]>
git.proxmox.com Git - libgit2.git/blob - include/git2/refs.h
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
25 #ifndef INCLUDE_git_refs_h__
26 #define INCLUDE_git_refs_h__
34 * @brief Git reference management routines
35 * @defgroup git_reference Git reference management routines
42 * Lookup a reference by its name in a repository.
44 * The generated reference is owned by the repository and
45 * should not be freed by the user.
47 * @param reference_out pointer to the looked-up reference
48 * @param repo the repository to look up the reference
49 * @param name the long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...)
50 * @return 0 on success; error code otherwise
52 GIT_EXTERN(int) git_reference_lookup(git_reference
**reference_out
, git_repository
*repo
, const char *name
);
55 * Create a new symbolic reference.
57 * The reference will be created in the repository and written
60 * This reference is owned by the repository and shall not
61 * be free'd by the user.
63 * @param ref_out Pointer to the newly created reference
64 * @param repo Repository where that reference will live
65 * @param name The name of the reference
66 * @param target The target of the reference
67 * @return 0 on success; error code otherwise
69 GIT_EXTERN(int) git_reference_create_symbolic(git_reference
**ref_out
, git_repository
*repo
, const char *name
, const char *target
);
72 * Create a new symbolic reference, overwriting an existing one with
73 * the same name, if it exists.
75 * If the new reference isn't a symbolic one, any pointers to the old
76 * reference become invalid.
78 * The reference will be created in the repository and written
81 * This reference is owned by the repository and shall not
82 * be free'd by the user.
84 * @param ref_out Pointer to the newly created reference
85 * @param repo Repository where that reference will live
86 * @param name The name of the reference
87 * @param target The target of the reference
88 * @return 0 on success; error code otherwise
90 GIT_EXTERN(int) git_reference_create_symbolic_f(git_reference
**ref_out
, git_repository
*repo
, const char *name
, const char *target
);
93 * Create a new object id reference.
95 * The reference will be created in the repository and written
98 * This reference is owned by the repository and shall not
99 * be free'd by the user.
101 * @param ref_out Pointer to the newly created reference
102 * @param repo Repository where that reference will live
103 * @param name The name of the reference
104 * @param id The object id pointed to by the reference.
105 * @return 0 on success; error code otherwise
107 GIT_EXTERN(int) git_reference_create_oid(git_reference
**ref_out
, git_repository
*repo
, const char *name
, const git_oid
*id
);
110 * Create a new object id reference, overwriting an existing one with
111 * the same name, if it exists.
113 * If the new reference isn't an object id one, any pointers to the
114 * old reference become invalid.
116 * The reference will be created in the repository and written
119 * This reference is owned by the repository and shall not
120 * be free'd by the user.
122 * @param ref_out Pointer to the newly created reference
123 * @param repo Repository where that reference will live
124 * @param name The name of the reference
125 * @param id The object id pointed to by the reference.
126 * @return 0 on success; error code otherwise
128 GIT_EXTERN(int) git_reference_create_oid_f(git_reference
**ref_out
, git_repository
*repo
, const char *name
, const git_oid
*id
);
131 * Get the OID pointed to by a reference.
133 * Only available if the reference is direct (i.e. not symbolic)
135 * @param ref The reference
136 * @return a pointer to the oid if available, NULL otherwise
138 GIT_EXTERN(const git_oid
*) git_reference_oid(git_reference
*ref
);
141 * Get full name to the reference pointed by this reference
143 * Only available if the reference is symbolic
145 * @param ref The reference
146 * @return a pointer to the name if available, NULL otherwise
148 GIT_EXTERN(const char *) git_reference_target(git_reference
*ref
);
151 * Get the type of a reference
153 * Either direct (GIT_REF_OID) or symbolic (GIT_REF_SYMBOLIC)
155 * @param ref The reference
158 GIT_EXTERN(git_rtype
) git_reference_type(git_reference
*ref
);
161 * Get the full name of a reference
163 * @param ref The reference
164 * @return the full name for the ref
166 GIT_EXTERN(const char *) git_reference_name(git_reference
*ref
);
169 * Resolve a symbolic reference
171 * Thie method iteratively peels a symbolic reference
172 * until it resolves to a direct reference to an OID.
174 * If a direct reference is passed as an argument,
175 * that reference is returned immediately
177 * @param resolved_ref Pointer to the peeled reference
178 * @param ref The reference
179 * @return 0 on success; error code otherwise
181 GIT_EXTERN(int) git_reference_resolve(git_reference
**resolved_ref
, git_reference
*ref
);
184 * Get the repository where a reference resides
186 * @param ref The reference
187 * @return a pointer to the repo
189 GIT_EXTERN(git_repository
*) git_reference_owner(git_reference
*ref
);
192 * Set the symbolic target of a reference.
194 * The reference must be a symbolic reference, otherwise
195 * this method will fail.
197 * The reference will be automatically updated in
198 * memory and on disk.
200 * @param ref The reference
201 * @param target The new target for the reference
202 * @return 0 on success; error code otherwise
204 GIT_EXTERN(int) git_reference_set_target(git_reference
*ref
, const char *target
);
207 * Set the OID target of a reference.
209 * The reference must be a direct reference, otherwise
210 * this method will fail.
212 * The reference will be automatically updated in
213 * memory and on disk.
215 * @param ref The reference
216 * @param target The new target OID for the reference
217 * @return 0 on success; error code otherwise
219 GIT_EXTERN(int) git_reference_set_oid(git_reference
*ref
, const git_oid
*id
);
222 * Rename an existing reference
224 * This method works for both direct and symbolic references.
225 * The new name will be checked for validity and may be
226 * modified into a normalized form.
228 * The refernece will be immediately renamed in-memory
232 GIT_EXTERN(int) git_reference_rename(git_reference
*ref
, const char *new_name
);
235 * Rename an existing reference, overwriting an existing one with the
236 * same name, if it exists.
238 * This method works for both direct and symbolic references.
239 * The new name will be checked for validity and may be
240 * modified into a normalized form.
242 * The refernece will be immediately renamed in-memory
246 GIT_EXTERN(int) git_reference_rename_f(git_reference
*ref
, const char *new_name
);
249 * Delete an existing reference
251 * This method works for both direct and symbolic references.
253 * The reference will be immediately removed on disk and from
254 * memory. The given reference pointer will no longer be valid.
257 GIT_EXTERN(int) git_reference_delete(git_reference
*ref
);
260 * Pack all the loose references in the repository
262 * This method will load into the cache all the loose
263 * references on the repository and update the
264 * `packed-refs` file with them.
266 * Once the `packed-refs` file has been written properly,
267 * the loose references will be removed from disk.
269 * WARNING: calling this method may invalidate any existing
270 * references previously loaded on the cache.
272 * @param repo Repository where the loose refs will be packed
273 * @return 0 on success; error code otherwise
275 GIT_EXTERN(int) git_reference_packall(git_repository
*repo
);
278 * Fill a list with all the references that can be found
281 * The listed references may be filtered by type, or using
282 * a bitwise OR of several types. Use the magic value
283 * `GIT_REF_LISTALL` to obtain all references, including
286 * The string array will be filled with the names of all
287 * references; these values are owned by the user and
288 * should be free'd manually when no longer needed, using
289 * `git_strarray_free`.
291 * @param array Pointer to a git_strarray structure where
292 * the reference names will be stored
293 * @param repo Repository where to find the refs
294 * @param list_flags Filtering flags for the reference
296 * @return 0 on success; error code otherwise
298 GIT_EXTERN(int) git_reference_listall(git_strarray
*array
, git_repository
*repo
, unsigned int list_flags
);
302 * Perform an operation on each reference in the repository
304 * The processed references may be filtered by type, or using
305 * a bitwise OR of several types. Use the magic value
306 * `GIT_REF_LISTALL` to obtain all references, including
309 * The `callback` function will be called for each of the references
310 * in the repository, and will receive the name of the reference and
311 * the `payload` value passed to this method.
313 * @param repo Repository where to find the refs
314 * @param list_flags Filtering flags for the reference
316 * @param callback Function which will be called for every listed ref
317 * @param payload Additional data to pass to the callback
318 * @return 0 on success; error code otherwise
320 GIT_EXTERN(int) git_reference_foreach(git_repository
*repo
, unsigned int list_flags
, int (*callback
)(const char *, void *), void *payload
);