1 /*
2  * Copyright (C) the libgit2 contributors. All rights reserved.
3  *
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.
6  */
7 module libgit2_d.refs;
8 
9 
10 private static import libgit2_d.oid;
11 private static import libgit2_d.strarray;
12 private static import libgit2_d.types;
13 
14 /**
15  * @file git2/refs.h
16  * @brief Git reference management routines
17  * @defgroup git_reference Git reference management routines
18  * @ingroup Git
19  * @{
20  */
21 extern (C):
22 nothrow @nogc:
23 public:
24 
25 /**
26  * Lookup a reference by name in a repository.
27  *
28  * The returned reference must be freed by the user.
29  *
30  * The name will be checked for validity.
31  * See `git_reference_symbolic_create()` for rules about valid names.
32  *
33  * @param out_ pointer to the looked-up reference
34  * @param repo the repository to look up the reference
35  * @param name the long name for the reference (e.g. HEAD, refs/heads/master,
36  * refs/tags/v0.1.0, ...)
37  * @return 0 on success, git_error_code.GIT_ENOTFOUND, git_error_code.GIT_EINVALIDSPEC or an error code.
38  */
39 //GIT_EXTERN
40 int git_reference_lookup(libgit2_d.types.git_reference** out_, libgit2_d.types.git_repository* repo, const (char)* name);
41 
42 /**
43  * Lookup a reference by name and resolve immediately to OID.
44  *
45  * This function provides a quick way to resolve a reference name straight
46  * through to the object id that it refers to.  This avoids having to
47  * allocate or free any `git_reference` objects for simple situations.
48  *
49  * The name will be checked for validity.
50  * See `git_reference_symbolic_create()` for rules about valid names.
51  *
52  * @param out_ Pointer to oid to be filled in
53  * @param repo The repository in which to look up the reference
54  * @param name The long name for the reference (e.g. HEAD, refs/heads/master,
55  * refs/tags/v0.1.0, ...)
56  * @return 0 on success, git_error_code.GIT_ENOTFOUND, git_error_code.GIT_EINVALIDSPEC or an error code.
57  */
58 //GIT_EXTERN
59 int git_reference_name_to_id(libgit2_d.oid.git_oid* out_, libgit2_d.types.git_repository* repo, const (char)* name);
60 
61 /**
62  * Lookup a reference by DWIMing its short name
63  *
64  * Apply the git precendence rules to the given shorthand to determine
65  * which reference the user is referring to.
66  *
67  * @param out_ pointer in which to store the reference
68  * @param repo the repository in which to look
69  * @param shorthand the short name for the reference
70  * @return 0 or an error code
71  */
72 //GIT_EXTERN
73 int git_reference_dwim(libgit2_d.types.git_reference** out_, libgit2_d.types.git_repository* repo, const (char)* shorthand);
74 
75 /**
76  * Conditionally create a new symbolic reference.
77  *
78  * A symbolic reference is a reference name that refers to another
79  * reference name.  If the other name moves, the symbolic name will move,
80  * too.  As a simple example, the "HEAD" reference might refer to
81  * "refs/heads/master" while on the "master" branch of a repository.
82  *
83  * The symbolic reference will be created in the repository and written to
84  * the disk.  The generated reference object must be freed by the user.
85  *
86  * Valid reference names must follow one of two patterns:
87  *
88  * 1. Top-level names must contain only capital letters and underscores,
89  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
90  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
91  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
92  *    sequences ".." and "@{" which have special meaning to revparse.
93  *
94  * This function will return an error if a reference already exists with the
95  * given name unless `force` is true, in which case it will be overwritten.
96  *
97  * The message for the reflog will be ignored if the reference does
98  * not belong in the standard set (HEAD, branches and remote-tracking
99  * branches) and it does not have a reflog.
100  *
101  * It will return git_error_code.GIT_EMODIFIED if the reference's value at the time
102  * of updating does not match the one passed through `current_value`
103  * (i.e. if the ref has changed since the user read it).
104  *
105  * @param out_ Pointer to the newly created reference
106  * @param repo Repository where that reference will live
107  * @param name The name of the reference
108  * @param target The target of the reference
109  * @param force Overwrite existing references
110  * @param current_value The expected value of the reference when updating
111  * @param log_message The one line long message to be appended to the reflog
112  * @return 0 on success, git_error_code.GIT_EEXISTS, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EMODIFIED or an
113  * error code
114  */
115 //GIT_EXTERN
116 int git_reference_symbolic_create_matching(libgit2_d.types.git_reference** out_, libgit2_d.types.git_repository* repo, const (char)* name, const (char)* target, int force, const (char)* current_value, const (char)* log_message);
117 
118 /**
119  * Create a new symbolic reference.
120  *
121  * A symbolic reference is a reference name that refers to another
122  * reference name.  If the other name moves, the symbolic name will move,
123  * too.  As a simple example, the "HEAD" reference might refer to
124  * "refs/heads/master" while on the "master" branch of a repository.
125  *
126  * The symbolic reference will be created in the repository and written to
127  * the disk.  The generated reference object must be freed by the user.
128  *
129  * Valid reference names must follow one of two patterns:
130  *
131  * 1. Top-level names must contain only capital letters and underscores,
132  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
133  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
134  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
135  *    sequences ".." and "@{" which have special meaning to revparse.
136  *
137  * This function will return an error if a reference already exists with the
138  * given name unless `force` is true, in which case it will be overwritten.
139  *
140  * The message for the reflog will be ignored if the reference does
141  * not belong in the standard set (HEAD, branches and remote-tracking
142  * branches) and it does not have a reflog.
143  *
144  * @param out_ Pointer to the newly created reference
145  * @param repo Repository where that reference will live
146  * @param name The name of the reference
147  * @param target The target of the reference
148  * @param force Overwrite existing references
149  * @param log_message The one line long message to be appended to the reflog
150  * @return 0 on success, git_error_code.GIT_EEXISTS, git_error_code.GIT_EINVALIDSPEC or an error code
151  */
152 //GIT_EXTERN
153 int git_reference_symbolic_create(libgit2_d.types.git_reference** out_, libgit2_d.types.git_repository* repo, const (char)* name, const (char)* target, int force, const (char)* log_message);
154 
155 /**
156  * Create a new direct reference.
157  *
158  * A direct reference (also called an object id reference) refers directly
159  * to a specific object id (a.k.a. OID or SHA) in the repository.  The id
160  * permanently refers to the object (although the reference itself can be
161  * moved).  For example, in libgit2 the direct ref "refs/tags/v0.17.0"
162  * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977.
163  *
164  * The direct reference will be created in the repository and written to
165  * the disk.  The generated reference object must be freed by the user.
166  *
167  * Valid reference names must follow one of two patterns:
168  *
169  * 1. Top-level names must contain only capital letters and underscores,
170  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
171  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
172  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
173  *    sequences ".." and "@{" which have special meaning to revparse.
174  *
175  * This function will return an error if a reference already exists with the
176  * given name unless `force` is true, in which case it will be overwritten.
177  *
178  * The message for the reflog will be ignored if the reference does
179  * not belong in the standard set (HEAD, branches and remote-tracking
180  * branches) and and it does not have a reflog.
181  *
182  * @param out_ Pointer to the newly created reference
183  * @param repo Repository where that reference will live
184  * @param name The name of the reference
185  * @param id The object id pointed to by the reference.
186  * @param force Overwrite existing references
187  * @param log_message The one line long message to be appended to the reflog
188  * @return 0 on success, git_error_code.GIT_EEXISTS, git_error_code.GIT_EINVALIDSPEC or an error code
189  */
190 //GIT_EXTERN
191 int git_reference_create(libgit2_d.types.git_reference** out_, libgit2_d.types.git_repository* repo, const (char)* name, const (libgit2_d.oid.git_oid)* id, int force, const (char)* log_message);
192 
193 /**
194  * Conditionally create new direct reference
195  *
196  * A direct reference (also called an object id reference) refers directly
197  * to a specific object id (a.k.a. OID or SHA) in the repository.  The id
198  * permanently refers to the object (although the reference itself can be
199  * moved).  For example, in libgit2 the direct ref "refs/tags/v0.17.0"
200  * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977.
201  *
202  * The direct reference will be created in the repository and written to
203  * the disk.  The generated reference object must be freed by the user.
204  *
205  * Valid reference names must follow one of two patterns:
206  *
207  * 1. Top-level names must contain only capital letters and underscores,
208  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
209  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
210  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
211  *    sequences ".." and "@{" which have special meaning to revparse.
212  *
213  * This function will return an error if a reference already exists with the
214  * given name unless `force` is true, in which case it will be overwritten.
215  *
216  * The message for the reflog will be ignored if the reference does
217  * not belong in the standard set (HEAD, branches and remote-tracking
218  * branches) and and it does not have a reflog.
219  *
220  * It will return git_error_code.GIT_EMODIFIED if the reference's value at the time
221  * of updating does not match the one passed through `current_id`
222  * (i.e. if the ref has changed since the user read it).
223  *
224  * @param out_ Pointer to the newly created reference
225  * @param repo Repository where that reference will live
226  * @param name The name of the reference
227  * @param id The object id pointed to by the reference.
228  * @param force Overwrite existing references
229  * @param current_id The expected value of the reference at the time of update
230  * @param log_message The one line long message to be appended to the reflog
231  * @return 0 on success, git_error_code.GIT_EMODIFIED if the value of the reference
232  * has changed, git_error_code.GIT_EEXISTS, git_error_code.GIT_EINVALIDSPEC or an error code
233  */
234 //GIT_EXTERN
235 int git_reference_create_matching(libgit2_d.types.git_reference** out_, libgit2_d.types.git_repository* repo, const (char)* name, const (libgit2_d.oid.git_oid)* id, int force, const (libgit2_d.oid.git_oid)* current_id, const (char)* log_message);
236 
237 /**
238  * Get the OID pointed to by a direct reference.
239  *
240  * Only available if the reference is direct (i.e. an object id reference,
241  * not a symbolic one).
242  *
243  * To find the OID of a symbolic ref, call `git_reference_resolve()` and
244  * then this function (or maybe use `git_reference_name_to_id()` to
245  * directly resolve a reference name all the way through to an OID).
246  *
247  * @param ref_ The reference
248  * @return a pointer to the oid if available, null otherwise
249  */
250 //GIT_EXTERN
251 const (libgit2_d.oid.git_oid)* git_reference_target(const (libgit2_d.types.git_reference)* ref_);
252 
253 /**
254  * Return the peeled OID target of this reference.
255  *
256  * This peeled OID only applies to direct references that point to
257  * a hard Tag object: it is the result of peeling such Tag.
258  *
259  * @param ref_ The reference
260  * @return a pointer to the oid if available, null otherwise
261  */
262 //GIT_EXTERN
263 const (libgit2_d.oid.git_oid)* git_reference_target_peel(const (libgit2_d.types.git_reference)* ref_);
264 
265 /**
266  * Get full name to the reference pointed to by a symbolic reference.
267  *
268  * Only available if the reference is symbolic.
269  *
270  * @param ref_ The reference
271  * @return a pointer to the name if available, null otherwise
272  */
273 //GIT_EXTERN
274 const (char)* git_reference_symbolic_target(const (libgit2_d.types.git_reference)* ref_);
275 
276 /**
277  * Get the type of a reference.
278  *
279  * Either direct (git_reference_t.GIT_REFERENCE_DIRECT) or symbolic (git_reference_t.GIT_REFERENCE_SYMBOLIC)
280  *
281  * @param ref_ The reference
282  * @return the type
283  */
284 //GIT_EXTERN
285 libgit2_d.types.git_reference_t git_reference_type(const (libgit2_d.types.git_reference)* ref_);
286 
287 /**
288  * Get the full name of a reference.
289  *
290  * See `git_reference_symbolic_create()` for rules about valid names.
291  *
292  * @param ref_ The reference
293  * @return the full name for the ref_
294  */
295 //GIT_EXTERN
296 const (char)* git_reference_name(const (libgit2_d.types.git_reference)* ref_);
297 
298 /**
299  * Resolve a symbolic reference to a direct reference.
300  *
301  * This method iteratively peels a symbolic reference until it resolves to
302  * a direct reference to an OID.
303  *
304  * The peeled reference is returned in the `resolved_ref` argument, and
305  * must be freed manually once it's no longer needed.
306  *
307  * If a direct reference is passed as an argument, a copy of that
308  * reference is returned. This copy must be manually freed too.
309  *
310  * @param out_ Pointer to the peeled reference
311  * @param ref_ The reference
312  * @return 0 or an error code
313  */
314 //GIT_EXTERN
315 int git_reference_resolve(libgit2_d.types.git_reference** out_, const (libgit2_d.types.git_reference)* ref_);
316 
317 /**
318  * Get the repository where a reference resides.
319  *
320  * @param ref_ The reference
321  * @return a pointer to the repo
322  */
323 //GIT_EXTERN
324 libgit2_d.types.git_repository* git_reference_owner(const (libgit2_d.types.git_reference)* ref_);
325 
326 /**
327  * Create a new reference with the same name as the given reference but a
328  * different symbolic target. The reference must be a symbolic reference,
329  * otherwise this will fail.
330  *
331  * The new reference will be written to disk, overwriting the given reference.
332  *
333  * The target name will be checked for validity.
334  * See `git_reference_symbolic_create()` for rules about valid names.
335  *
336  * The message for the reflog will be ignored if the reference does
337  * not belong in the standard set (HEAD, branches and remote-tracking
338  * branches) and and it does not have a reflog.
339  *
340  * @param out_ Pointer to the newly created reference
341  * @param ref_ The reference
342  * @param target The new target for the reference
343  * @param log_message The one line long message to be appended to the reflog
344  * @return 0 on success, git_error_code.GIT_EINVALIDSPEC or an error code
345  */
346 //GIT_EXTERN
347 int git_reference_symbolic_set_target(libgit2_d.types.git_reference** out_, libgit2_d.types.git_reference* ref_, const (char)* target, const (char)* log_message);
348 
349 /**
350  * Conditionally create a new reference with the same name as the given
351  * reference but a different OID target. The reference must be a direct
352  * reference, otherwise this will fail.
353  *
354  * The new reference will be written to disk, overwriting the given reference.
355  *
356  * @param out_ Pointer to the newly created reference
357  * @param ref_ The reference
358  * @param id The new target OID for the reference
359  * @param log_message The one line long message to be appended to the reflog
360  * @return 0 on success, git_error_code.GIT_EMODIFIED if the value of the reference
361  * has changed since it was read, or an error code
362  */
363 //GIT_EXTERN
364 int git_reference_set_target(libgit2_d.types.git_reference** out_, libgit2_d.types.git_reference* ref_, const (libgit2_d.oid.git_oid)* id, const (char)* log_message);
365 
366 /**
367  * Rename an existing reference.
368  *
369  * This method works for both direct and symbolic references.
370  *
371  * The new name will be checked for validity.
372  * See `git_reference_symbolic_create()` for rules about valid names.
373  *
374  * If the `force` flag is not enabled, and there's already
375  * a reference with the given name, the renaming will fail.
376  *
377  * IMPORTANT:
378  * The user needs to write a proper reflog entry if the
379  * reflog is enabled for the repository. We only rename
380  * the reflog if it exists.
381  *
382  * @param ref_ The reference to rename
383  * @param new_name The new name for the reference
384  * @param force Overwrite an existing reference
385  * @param log_message The one line long message to be appended to the reflog
386  * @return 0 on success, git_error_code.GIT_EINVALIDSPEC, git_error_code.GIT_EEXISTS or an error code
387  *
388  */
389 //GIT_EXTERN
390 int git_reference_rename(libgit2_d.types.git_reference** new_ref, libgit2_d.types.git_reference* ref_, const (char)* new_name, int force, const (char)* log_message);
391 
392 /**
393  * Delete an existing reference.
394  *
395  * This method works for both direct and symbolic references.  The reference
396  * will be immediately removed on disk but the memory will not be freed.
397  * Callers must call `git_reference_free`.
398  *
399  * This function will return an error if the reference has changed
400  * from the time it was looked up.
401  *
402  * @param ref_ The reference to remove
403  * @return 0, git_error_code.GIT_EMODIFIED or an error code
404  */
405 //GIT_EXTERN
406 int git_reference_delete(libgit2_d.types.git_reference* ref_);
407 
408 /**
409  * Delete an existing reference by name
410  *
411  * This method removes the named reference from the repository without
412  * looking at its old value.
413  *
414  * @param name The reference to remove
415  * @return 0 or an error code
416  */
417 //GIT_EXTERN
418 int git_reference_remove(libgit2_d.types.git_repository* repo, const (char)* name);
419 
420 /**
421  * Fill a list with all the references that can be found in a repository.
422  *
423  * The string array will be filled with the names of all references; these
424  * values are owned by the user and should be free'd manually when no
425  * longer needed, using `git_strarray_free()`.
426  *
427  * @param array Pointer to a git_strarray structure where
428  *		the reference names will be stored
429  * @param repo Repository where to find the refs
430  * @return 0 or an error code
431  */
432 //GIT_EXTERN
433 int git_reference_list(libgit2_d.strarray.git_strarray* array, libgit2_d.types.git_repository* repo);
434 
435 /**
436  * Callback used to iterate over references
437  *
438  * @see git_reference_foreach
439  *
440  * @param reference The reference object
441  * @param payload Payload passed to git_reference_foreach
442  * @return non-zero to terminate the iteration
443  */
444 alias git_reference_foreach_cb = int function(libgit2_d.types.git_reference* reference, void* payload);
445 
446 /**
447  * Callback used to iterate over reference names
448  *
449  * @see git_reference_foreach_name
450  *
451  * @param name The reference name
452  * @param payload Payload passed to git_reference_foreach_name
453  * @return non-zero to terminate the iteration
454  */
455 alias git_reference_foreach_name_cb = int function(const (char)* name, void* payload);
456 
457 /**
458  * Perform a callback on each reference in the repository.
459  *
460  * The `callback` function will be called for each reference in the
461  * repository, receiving the reference object and the `payload` value
462  * passed to this method.  Returning a non-zero value from the callback
463  * will terminate the iteration.
464  *
465  * Note that the callback function is responsible to call `git_reference_free`
466  * on each reference passed to it.
467  *
468  * @param repo Repository where to find the refs
469  * @param callback Function which will be called for every listed ref
470  * @param payload Additional data to pass to the callback
471  * @return 0 on success, non-zero callback return value, or error code
472  */
473 //GIT_EXTERN
474 int git_reference_foreach(libgit2_d.types.git_repository* repo, .git_reference_foreach_cb callback, void* payload);
475 
476 /**
477  * Perform a callback on the fully-qualified name of each reference.
478  *
479  * The `callback` function will be called for each reference in the
480  * repository, receiving the name of the reference and the `payload` value
481  * passed to this method.  Returning a non-zero value from the callback
482  * will terminate the iteration.
483  *
484  * @param repo Repository where to find the refs
485  * @param callback Function which will be called for every listed ref name
486  * @param payload Additional data to pass to the callback
487  * @return 0 on success, non-zero callback return value, or error code
488  */
489 //GIT_EXTERN
490 int git_reference_foreach_name(libgit2_d.types.git_repository* repo, git_reference_foreach_name_cb callback, void* payload);
491 
492 /**
493  * Create a copy of an existing reference.
494  *
495  * Call `git_reference_free` to free the data.
496  *
497  * @param dest pointer where to store the copy
498  * @param source object to copy
499  * @return 0 or an error code
500  */
501 //GIT_EXTERN
502 int git_reference_dup(libgit2_d.types.git_reference** dest, libgit2_d.types.git_reference* source);
503 
504 /**
505  * Free the given reference.
506  *
507  * @param ref_ git_reference
508  */
509 //GIT_EXTERN
510 void git_reference_free(libgit2_d.types.git_reference* ref_);
511 
512 /**
513  * Compare two references.
514  *
515  * @param ref1 The first git_reference
516  * @param ref2 The second git_reference
517  * @return 0 if the same, else a stable but meaningless ordering.
518  */
519 //GIT_EXTERN
520 int git_reference_cmp(const (libgit2_d.types.git_reference)* ref1, const (libgit2_d.types.git_reference)* ref2);
521 
522 /**
523  * Create an iterator for the repo's references
524  *
525  * @param out_ pointer in which to store the iterator
526  * @param repo the repository
527  * @return 0 or an error code
528  */
529 //GIT_EXTERN
530 int git_reference_iterator_new(libgit2_d.types.git_reference_iterator** out_, libgit2_d.types.git_repository* repo);
531 
532 /**
533  * Create an iterator for the repo's references that match the
534  * specified glob
535  *
536  * @param out_ pointer in which to store the iterator
537  * @param repo the repository
538  * @param glob the glob to match against the reference names
539  * @return 0 or an error code
540  */
541 //GIT_EXTERN
542 int git_reference_iterator_glob_new(libgit2_d.types.git_reference_iterator** out_, libgit2_d.types.git_repository* repo, const (char)* glob);
543 
544 /**
545  * Get the next reference
546  *
547  * @param out_ pointer in which to store the reference
548  * @param iter the iterator
549  * @return 0, git_error_code.GIT_ITEROVER if there are no more; or an error code
550  */
551 //GIT_EXTERN
552 int git_reference_next(libgit2_d.types.git_reference** out_, libgit2_d.types.git_reference_iterator* iter);
553 
554 /**
555  * Get the next reference's name
556  *
557  * This function is provided for convenience in case only the names
558  * are interesting as it avoids the allocation of the `git_reference`
559  * object which `git_reference_next()` needs.
560  *
561  * @param out_ pointer in which to store the string
562  * @param iter the iterator
563  * @return 0, git_error_code.GIT_ITEROVER if there are no more; or an error code
564  */
565 //GIT_EXTERN
566 int git_reference_next_name(const (char)** out_, libgit2_d.types.git_reference_iterator* iter);
567 
568 /**
569  * Free the iterator and its associated resources
570  *
571  * @param iter the iterator to free
572  */
573 //GIT_EXTERN
574 void git_reference_iterator_free(libgit2_d.types.git_reference_iterator* iter);
575 
576 /**
577  * Perform a callback on each reference in the repository whose name
578  * matches the given pattern.
579  *
580  * This function acts like `git_reference_foreach()` with an additional
581  * pattern match being applied to the reference name before issuing the
582  * callback function.  See that function for more information.
583  *
584  * The pattern is matched using fnmatch or "glob" style where a '*' matches
585  * any sequence of letters, a '?' matches any letter, and square brackets
586  * can be used to define character ranges (such as "[0-9]" for digits).
587  *
588  * @param repo Repository where to find the refs
589  * @param glob Pattern to match (fnmatch-style) against reference name.
590  * @param callback Function which will be called for every listed ref
591  * @param payload Additional data to pass to the callback
592  * @return 0 on success, git_error_code.GIT_EUSER on non-zero callback, or error code
593  */
594 //GIT_EXTERN
595 int git_reference_foreach_glob(libgit2_d.types.git_repository* repo, const (char)* glob, git_reference_foreach_name_cb callback, void* payload);
596 
597 /**
598  * Check if a reflog exists for the specified reference.
599  *
600  * @param repo the repository
601  * @param refname the reference's name
602  * @return 0 when no reflog can be found, 1 when it exists;
603  * otherwise an error code.
604  */
605 //GIT_EXTERN
606 int git_reference_has_log(libgit2_d.types.git_repository* repo, const (char)* refname);
607 
608 /**
609  * Ensure there is a reflog for a particular reference.
610  *
611  * Make sure that successive updates to the reference will append to
612  * its log.
613  *
614  * @param repo the repository
615  * @param refname the reference's name
616  * @return 0 or an error code.
617  */
618 //GIT_EXTERN
619 int git_reference_ensure_log(libgit2_d.types.git_repository* repo, const (char)* refname);
620 
621 /**
622  * Check if a reference is a local branch.
623  *
624  * @param ref_ A git reference
625  *
626  * @return 1 when the reference lives in the refs/heads
627  * namespace; 0 otherwise.
628  */
629 //GIT_EXTERN
630 int git_reference_is_branch(const (libgit2_d.types.git_reference)* ref_);
631 
632 /**
633  * Check if a reference is a remote tracking branch
634  *
635  * @param ref_ A git reference
636  *
637  * @return 1 when the reference lives in the refs/remotes
638  * namespace; 0 otherwise.
639  */
640 //GIT_EXTERN
641 int git_reference_is_remote(const (libgit2_d.types.git_reference)* ref_);
642 
643 /**
644  * Check if a reference is a tag
645  *
646  * @param ref_ A git reference
647  *
648  * @return 1 when the reference lives in the refs/tags
649  * namespace; 0 otherwise.
650  */
651 //GIT_EXTERN
652 int git_reference_is_tag(const (libgit2_d.types.git_reference)* ref_);
653 
654 /**
655  * Check if a reference is a note
656  *
657  * @param ref_ A git reference
658  *
659  * @return 1 when the reference lives in the refs/notes
660  * namespace; 0 otherwise.
661  */
662 //GIT_EXTERN
663 int git_reference_is_note(const (libgit2_d.types.git_reference)* ref_);
664 
665 /**
666  * Normalization options for reference lookup
667  */
668 enum git_reference_format_t
669 {
670 	/**
671 	 * No particular normalization.
672 	 */
673 	GIT_REFERENCE_FORMAT_NORMAL = 0u,
674 
675 	/**
676 	 * Control whether one-level refnames are accepted
677 	 * (i.e., refnames that do not contain multiple /-separated
678 	 * components). Those are expected to be written only using
679 	 * uppercase letters and underscore (FETCH_HEAD, ...)
680 	 */
681 	GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL = 1u << 0,
682 
683 	/**
684 	 * Interpret the provided name as a reference pattern for a
685 	 * refspec (as used with remote repositories). If this option
686 	 * is enabled, the name is allowed to contain a single * (<star>)
687 	 * in place of a one full pathname component
688 	 * (e.g., foo/<star>/bar but not foo/bar<star>).
689 	 */
690 	GIT_REFERENCE_FORMAT_REFSPEC_PATTERN = 1u << 1,
691 
692 	/**
693 	 * Interpret the name as part of a refspec in shorthand form
694 	 * so the `ONELEVEL` naming rules aren't enforced and 'master'
695 	 * becomes a valid name.
696 	 */
697 	GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = 1u << 2,
698 }
699 
700 /**
701  * Normalize reference name and check validity.
702  *
703  * This will normalize the reference name by removing any leading slash
704  * '/' characters and collapsing runs of adjacent slashes between name
705  * components into a single slash.
706  *
707  * Once normalized, if the reference name is valid, it will be returned in
708  * the user allocated buffer.
709  *
710  * See `git_reference_symbolic_create()` for rules about valid names.
711  *
712  * @param buffer_out User allocated buffer to store normalized name
713  * @param buffer_size Size of buffer_out
714  * @param name Reference name to be checked.
715  * @param flags Flags to constrain name validation rules - see the
716  *              GIT_REFERENCE_FORMAT constants above.
717  * @return 0 on success, git_error_code.GIT_EBUFS if buffer is too small, git_error_code.GIT_EINVALIDSPEC
718  * or an error code.
719  */
720 //GIT_EXTERN
721 int git_reference_normalize_name(char* buffer_out, size_t buffer_size, const (char)* name, uint flags);
722 
723 /**
724  * Recursively peel reference until object of the specified type is found.
725  *
726  * The retrieved `peeled` object is owned by the repository
727  * and should be closed with the `git_object_free` method.
728  *
729  * If you pass `git_object_t.GIT_OBJECT_ANY` as the target type, then the object
730  * will be peeled until a non-tag object is met.
731  *
732  * @param out_ Pointer to the peeled git_object
733  * @param ref_ The reference to be processed
734  * @param type The type of the requested object (git_object_t.GIT_OBJECT_COMMIT,
735  * git_object_t.GIT_OBJECT_TAG, git_object_t.GIT_OBJECT_TREE, git_object_t.GIT_OBJECT_BLOB or git_object_t.GIT_OBJECT_ANY).
736  * @return 0 on success, git_error_code.GIT_EAMBIGUOUS, git_error_code.GIT_ENOTFOUND or an error code
737  */
738 //GIT_EXTERN
739 int git_reference_peel(libgit2_d.types.git_object** out_, const (libgit2_d.types.git_reference)* ref_, libgit2_d.types.git_object_t type);
740 
741 /**
742  * Ensure the reference name is well-formed.
743  *
744  * Valid reference names must follow one of two patterns:
745  *
746  * 1. Top-level names must contain only capital letters and underscores,
747  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
748  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
749  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
750  *    sequences ".." and "@{" which have special meaning to revparse.
751  *
752  * @param refname name to be checked.
753  * @return 1 if the reference name is acceptable; 0 if it isn't
754  */
755 //GIT_EXTERN
756 int git_reference_is_valid_name(const (char)* refname);
757 
758 /**
759  * Get the reference's short name
760  *
761  * This will transform the reference name into a name "human-readable"
762  * version. If no shortname is appropriate, it will return the full
763  * name.
764  *
765  * The memory is owned by the reference and must not be freed.
766  *
767  * @param ref_ a reference
768  * @return the human-readable version of the name
769  */
770 //GIT_EXTERN
771 const (char)* git_reference_shorthand(const (libgit2_d.types.git_reference)* ref_);
772 
773 /** @} */