]>
git.proxmox.com Git - libgit2.git/blob - include/git2/refs.h
2 * Copyright (C) 2009-2011 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #ifndef INCLUDE_git_refs_h__
8 #define INCLUDE_git_refs_h__
16 * @brief Git reference management routines
17 * @defgroup git_reference Git reference management routines
24 * Lookup a reference by its name in a repository.
26 * The generated reference is owned by the repository and
27 * should not be freed by the user.
29 * @param reference_out pointer to the looked-up reference
30 * @param repo the repository to look up the reference
31 * @param name the long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...)
32 * @return GIT_SUCCESS or an error code
34 GIT_EXTERN(int) git_reference_lookup(git_reference
**reference_out
, git_repository
*repo
, const char *name
);
37 * Create a new symbolic reference.
39 * The reference will be created in the repository and written
42 * This reference is owned by the repository and shall not
43 * be free'd by the user.
45 * If `force` is true and there already exists a reference
46 * with the same name, it will be overwritten.
48 * @param ref_out Pointer to the newly created reference
49 * @param repo Repository where that reference will live
50 * @param name The name of the reference
51 * @param target The target of the reference
52 * @param force Overwrite existing references
53 * @return GIT_SUCCESS or an error code
55 GIT_EXTERN(int) git_reference_create_symbolic(git_reference
**ref_out
, git_repository
*repo
, const char *name
, const char *target
, int force
);
58 * Create a new object id reference.
60 * The reference will be created in the repository and written
63 * This reference is owned by the repository and shall not
64 * be free'd by the user.
66 * If `force` is true and there already exists a reference
67 * with the same name, it will be overwritten.
69 * @param ref_out Pointer to the newly created reference
70 * @param repo Repository where that reference will live
71 * @param name The name of the reference
72 * @param id The object id pointed to by the reference.
73 * @param force Overwrite existing references
74 * @return GIT_SUCCESS or an error code
76 GIT_EXTERN(int) git_reference_create_oid(git_reference
**ref_out
, git_repository
*repo
, const char *name
, const git_oid
*id
, int force
);
79 * Get the OID pointed to by a reference.
81 * Only available if the reference is direct (i.e. not symbolic)
83 * @param ref The reference
84 * @return a pointer to the oid if available, NULL otherwise
86 GIT_EXTERN(const git_oid
*) git_reference_oid(git_reference
*ref
);
89 * Get full name to the reference pointed by this reference
91 * Only available if the reference is symbolic
93 * @param ref The reference
94 * @return a pointer to the name if available, NULL otherwise
96 GIT_EXTERN(const char *) git_reference_target(git_reference
*ref
);
99 * Get the type of a reference
101 * Either direct (GIT_REF_OID) or symbolic (GIT_REF_SYMBOLIC)
103 * @param ref The reference
106 GIT_EXTERN(git_rtype
) git_reference_type(git_reference
*ref
);
109 * Get the full name of a reference
111 * @param ref The reference
112 * @return the full name for the ref
114 GIT_EXTERN(const char *) git_reference_name(git_reference
*ref
);
117 * Resolve a symbolic reference
119 * Thie method iteratively peels a symbolic reference
120 * until it resolves to a direct reference to an OID.
122 * If a direct reference is passed as an argument,
123 * that reference is returned immediately
125 * @param resolved_ref Pointer to the peeled reference
126 * @param ref The reference
127 * @return GIT_SUCCESS or an error code
129 GIT_EXTERN(int) git_reference_resolve(git_reference
**resolved_ref
, git_reference
*ref
);
132 * Get the repository where a reference resides
134 * @param ref The reference
135 * @return a pointer to the repo
137 GIT_EXTERN(git_repository
*) git_reference_owner(git_reference
*ref
);
140 * Set the symbolic target of a reference.
142 * The reference must be a symbolic reference, otherwise
143 * this method will fail.
145 * The reference will be automatically updated in
146 * memory and on disk.
148 * @param ref The reference
149 * @param target The new target for the reference
150 * @return GIT_SUCCESS or an error code
152 GIT_EXTERN(int) git_reference_set_target(git_reference
*ref
, const char *target
);
155 * Set the OID target of a reference.
157 * The reference must be a direct reference, otherwise
158 * this method will fail.
160 * The reference will be automatically updated in
161 * memory and on disk.
163 * @param ref The reference
164 * @param id The new target OID for the reference
165 * @return GIT_SUCCESS or an error code
167 GIT_EXTERN(int) git_reference_set_oid(git_reference
*ref
, const git_oid
*id
);
170 * Rename an existing reference
172 * This method works for both direct and symbolic references.
173 * The new name will be checked for validity and may be
174 * modified into a normalized form.
176 * The refernece will be immediately renamed in-memory
180 GIT_EXTERN(int) git_reference_rename(git_reference
*ref
, const char *new_name
, int force
);
183 * Delete an existing reference
185 * This method works for both direct and symbolic references.
187 * The reference will be immediately removed on disk and from
188 * memory. The given reference pointer will no longer be valid.
191 GIT_EXTERN(int) git_reference_delete(git_reference
*ref
);
194 * Pack all the loose references in the repository
196 * This method will load into the cache all the loose
197 * references on the repository and update the
198 * `packed-refs` file with them.
200 * Once the `packed-refs` file has been written properly,
201 * the loose references will be removed from disk.
203 * WARNING: calling this method may invalidate any existing
204 * references previously loaded on the cache.
206 * @param repo Repository where the loose refs will be packed
207 * @return GIT_SUCCESS or an error code
209 GIT_EXTERN(int) git_reference_packall(git_repository
*repo
);
212 * Fill a list with all the references that can be found
215 * The listed references may be filtered by type, or using
216 * a bitwise OR of several types. Use the magic value
217 * `GIT_REF_LISTALL` to obtain all references, including
220 * The string array will be filled with the names of all
221 * references; these values are owned by the user and
222 * should be free'd manually when no longer needed, using
223 * `git_strarray_free`.
225 * @param array Pointer to a git_strarray structure where
226 * the reference names will be stored
227 * @param repo Repository where to find the refs
228 * @param list_flags Filtering flags for the reference
230 * @return GIT_SUCCESS or an error code
232 GIT_EXTERN(int) git_reference_listall(git_strarray
*array
, git_repository
*repo
, unsigned int list_flags
);
236 * Perform an operation on each reference in the repository
238 * The processed references may be filtered by type, or using
239 * a bitwise OR of several types. Use the magic value
240 * `GIT_REF_LISTALL` to obtain all references, including
243 * The `callback` function will be called for each of the references
244 * in the repository, and will receive the name of the reference and
245 * the `payload` value passed to this method.
247 * @param repo Repository where to find the refs
248 * @param list_flags Filtering flags for the reference
250 * @param callback Function which will be called for every listed ref
251 * @param payload Additional data to pass to the callback
252 * @return GIT_SUCCESS or an error code
254 GIT_EXTERN(int) git_reference_foreach(git_repository
*repo
, unsigned int list_flags
, int (*callback
)(const char *, void *), void *payload
);