]>
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 * If `force` is true and there already exists a reference
64 * with the same name, it will be overwritten.
66 * @param ref_out Pointer to the newly created reference
67 * @param repo Repository where that reference will live
68 * @param name The name of the reference
69 * @param target The target of the reference
70 * @param force Overwrite existing references
71 * @return 0 on success; error code otherwise
73 GIT_EXTERN(int) git_reference_create_symbolic(git_reference
**ref_out
, git_repository
*repo
, const char *name
, const char *target
, int force
);
76 * Create a new object id reference.
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 * If `force` is true and there already exists a reference
85 * with the same name, it will be overwritten.
87 * @param ref_out Pointer to the newly created reference
88 * @param repo Repository where that reference will live
89 * @param name The name of the reference
90 * @param id The object id pointed to by the reference.
91 * @param force Overwrite existing references
92 * @return 0 on success; error code otherwise
94 GIT_EXTERN(int) git_reference_create_oid(git_reference
**ref_out
, git_repository
*repo
, const char *name
, const git_oid
*id
, int force
);
97 * Get the OID pointed to by a reference.
99 * Only available if the reference is direct (i.e. not symbolic)
101 * @param ref The reference
102 * @return a pointer to the oid if available, NULL otherwise
104 GIT_EXTERN(const git_oid
*) git_reference_oid(git_reference
*ref
);
107 * Get full name to the reference pointed by this reference
109 * Only available if the reference is symbolic
111 * @param ref The reference
112 * @return a pointer to the name if available, NULL otherwise
114 GIT_EXTERN(const char *) git_reference_target(git_reference
*ref
);
117 * Get the type of a reference
119 * Either direct (GIT_REF_OID) or symbolic (GIT_REF_SYMBOLIC)
121 * @param ref The reference
124 GIT_EXTERN(git_rtype
) git_reference_type(git_reference
*ref
);
127 * Get the full name of a reference
129 * @param ref The reference
130 * @return the full name for the ref
132 GIT_EXTERN(const char *) git_reference_name(git_reference
*ref
);
135 * Resolve a symbolic reference
137 * Thie method iteratively peels a symbolic reference
138 * until it resolves to a direct reference to an OID.
140 * If a direct reference is passed as an argument,
141 * that reference is returned immediately
143 * @param resolved_ref Pointer to the peeled reference
144 * @param ref The reference
145 * @return 0 on success; error code otherwise
147 GIT_EXTERN(int) git_reference_resolve(git_reference
**resolved_ref
, git_reference
*ref
);
150 * Get the repository where a reference resides
152 * @param ref The reference
153 * @return a pointer to the repo
155 GIT_EXTERN(git_repository
*) git_reference_owner(git_reference
*ref
);
158 * Set the symbolic target of a reference.
160 * The reference must be a symbolic reference, otherwise
161 * this method will fail.
163 * The reference will be automatically updated in
164 * memory and on disk.
166 * @param ref The reference
167 * @param target The new target for the reference
168 * @return 0 on success; error code otherwise
170 GIT_EXTERN(int) git_reference_set_target(git_reference
*ref
, const char *target
);
173 * Set the OID target of a reference.
175 * The reference must be a direct reference, otherwise
176 * this method will fail.
178 * The reference will be automatically updated in
179 * memory and on disk.
181 * @param ref The reference
182 * @param id The new target OID for the reference
183 * @return 0 on success; error code otherwise
185 GIT_EXTERN(int) git_reference_set_oid(git_reference
*ref
, const git_oid
*id
);
188 * Rename an existing reference
190 * This method works for both direct and symbolic references.
191 * The new name will be checked for validity and may be
192 * modified into a normalized form.
194 * The refernece will be immediately renamed in-memory
198 GIT_EXTERN(int) git_reference_rename(git_reference
*ref
, const char *new_name
);
201 * Rename an existing reference, overwriting an existing one with the
202 * same name, if it exists.
204 * This method works for both direct and symbolic references.
205 * The new name will be checked for validity and may be
206 * modified into a normalized form.
208 * The refernece will be immediately renamed in-memory
212 GIT_EXTERN(int) git_reference_rename_f(git_reference
*ref
, const char *new_name
);
215 * Delete an existing reference
217 * This method works for both direct and symbolic references.
219 * The reference will be immediately removed on disk and from
220 * memory. The given reference pointer will no longer be valid.
223 GIT_EXTERN(int) git_reference_delete(git_reference
*ref
);
226 * Pack all the loose references in the repository
228 * This method will load into the cache all the loose
229 * references on the repository and update the
230 * `packed-refs` file with them.
232 * Once the `packed-refs` file has been written properly,
233 * the loose references will be removed from disk.
235 * WARNING: calling this method may invalidate any existing
236 * references previously loaded on the cache.
238 * @param repo Repository where the loose refs will be packed
239 * @return 0 on success; error code otherwise
241 GIT_EXTERN(int) git_reference_packall(git_repository
*repo
);
244 * Fill a list with all the references that can be found
247 * The listed references may be filtered by type, or using
248 * a bitwise OR of several types. Use the magic value
249 * `GIT_REF_LISTALL` to obtain all references, including
252 * The string array will be filled with the names of all
253 * references; these values are owned by the user and
254 * should be free'd manually when no longer needed, using
255 * `git_strarray_free`.
257 * @param array Pointer to a git_strarray structure where
258 * the reference names will be stored
259 * @param repo Repository where to find the refs
260 * @param list_flags Filtering flags for the reference
262 * @return 0 on success; error code otherwise
264 GIT_EXTERN(int) git_reference_listall(git_strarray
*array
, git_repository
*repo
, unsigned int list_flags
);
268 * Perform an operation on each reference in the repository
270 * The processed references may be filtered by type, or using
271 * a bitwise OR of several types. Use the magic value
272 * `GIT_REF_LISTALL` to obtain all references, including
275 * The `callback` function will be called for each of the references
276 * in the repository, and will receive the name of the reference and
277 * the `payload` value passed to this method.
279 * @param repo Repository where to find the refs
280 * @param list_flags Filtering flags for the reference
282 * @param callback Function which will be called for every listed ref
283 * @param payload Additional data to pass to the callback
284 * @return 0 on success; error code otherwise
286 GIT_EXTERN(int) git_reference_foreach(git_repository
*repo
, unsigned int list_flags
, int (*callback
)(const char *, void *), void *payload
);