Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:38

0001 /*
0002  * Copyright (C) the libgit2 contributors. All rights reserved.
0003  *
0004  * This file is part of libgit2, distributed under the GNU GPL v2 with
0005  * a Linking Exception. For full terms see the included COPYING file.
0006  */
0007 #ifndef INCLUDE_git_refs_h__
0008 #define INCLUDE_git_refs_h__
0009 
0010 #include "common.h"
0011 #include "types.h"
0012 #include "oid.h"
0013 #include "strarray.h"
0014 
0015 /**
0016  * @file git2/refs.h
0017  * @brief Git reference management routines
0018  * @defgroup git_reference Git reference management routines
0019  * @ingroup Git
0020  * @{
0021  */
0022 GIT_BEGIN_DECL
0023 
0024 /**
0025  * Lookup a reference by name in a repository.
0026  *
0027  * The returned reference must be freed by the user.
0028  *
0029  * The name will be checked for validity.
0030  * See `git_reference_symbolic_create()` for rules about valid names.
0031  *
0032  * @param out pointer to the looked-up reference
0033  * @param repo the repository to look up the reference
0034  * @param name the long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...)
0035  * @return 0 on success, GIT_ENOTFOUND, GIT_EINVALIDSPEC or an error code.
0036  */
0037 GIT_EXTERN(int) git_reference_lookup(git_reference **out, git_repository *repo, const char *name);
0038 
0039 /**
0040  * Lookup a reference by name and resolve immediately to OID.
0041  *
0042  * This function provides a quick way to resolve a reference name straight
0043  * through to the object id that it refers to.  This avoids having to
0044  * allocate or free any `git_reference` objects for simple situations.
0045  *
0046  * The name will be checked for validity.
0047  * See `git_reference_symbolic_create()` for rules about valid names.
0048  *
0049  * @param out Pointer to oid to be filled in
0050  * @param repo The repository in which to look up the reference
0051  * @param name The long name for the reference (e.g. HEAD, refs/heads/master, refs/tags/v0.1.0, ...)
0052  * @return 0 on success, GIT_ENOTFOUND, GIT_EINVALIDSPEC or an error code.
0053  */
0054 GIT_EXTERN(int) git_reference_name_to_id(
0055     git_oid *out, git_repository *repo, const char *name);
0056 
0057 /**
0058  * Lookup a reference by DWIMing its short name
0059  *
0060  * Apply the git precedence rules to the given shorthand to determine
0061  * which reference the user is referring to.
0062  *
0063  * @param out pointer in which to store the reference
0064  * @param repo the repository in which to look
0065  * @param shorthand the short name for the reference
0066  * @return 0 or an error code
0067  */
0068 GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, const char *shorthand);
0069 
0070 /**
0071  * Conditionally create a new symbolic reference.
0072  *
0073  * A symbolic reference is a reference name that refers to another
0074  * reference name.  If the other name moves, the symbolic name will move,
0075  * too.  As a simple example, the "HEAD" reference might refer to
0076  * "refs/heads/master" while on the "master" branch of a repository.
0077  *
0078  * The symbolic reference will be created in the repository and written to
0079  * the disk.  The generated reference object must be freed by the user.
0080  *
0081  * Valid reference names must follow one of two patterns:
0082  *
0083  * 1. Top-level names must contain only capital letters and underscores,
0084  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
0085  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
0086  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
0087  *    sequences ".." and "@{" which have special meaning to revparse.
0088  *
0089  * This function will return an error if a reference already exists with the
0090  * given name unless `force` is true, in which case it will be overwritten.
0091  *
0092  * The message for the reflog will be ignored if the reference does
0093  * not belong in the standard set (HEAD, branches and remote-tracking
0094  * branches) and it does not have a reflog.
0095  *
0096  * It will return GIT_EMODIFIED if the reference's value at the time
0097  * of updating does not match the one passed through `current_value`
0098  * (i.e. if the ref has changed since the user read it).
0099  *
0100  * If `current_value` is all zeros, this function will return GIT_EMODIFIED
0101  * if the ref already exists.
0102  *
0103  * @param out Pointer to the newly created reference
0104  * @param repo Repository where that reference will live
0105  * @param name The name of the reference
0106  * @param target The target of the reference
0107  * @param force Overwrite existing references
0108  * @param current_value The expected value of the reference when updating
0109  * @param log_message The one line long message to be appended to the reflog
0110  * @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC, GIT_EMODIFIED or an error code
0111  */
0112 GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *current_value, const char *log_message);
0113 
0114 /**
0115  * Create a new symbolic reference.
0116  *
0117  * A symbolic reference is a reference name that refers to another
0118  * reference name.  If the other name moves, the symbolic name will move,
0119  * too.  As a simple example, the "HEAD" reference might refer to
0120  * "refs/heads/master" while on the "master" branch of a repository.
0121  *
0122  * The symbolic reference will be created in the repository and written to
0123  * the disk.  The generated reference object must be freed by the user.
0124  *
0125  * Valid reference names must follow one of two patterns:
0126  *
0127  * 1. Top-level names must contain only capital letters and underscores,
0128  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
0129  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
0130  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
0131  *    sequences ".." and "@{" which have special meaning to revparse.
0132  *
0133  * This function will return an error if a reference already exists with the
0134  * given name unless `force` is true, in which case it will be overwritten.
0135  *
0136  * The message for the reflog will be ignored if the reference does
0137  * not belong in the standard set (HEAD, branches and remote-tracking
0138  * branches) and it does not have a reflog.
0139  *
0140  * @param out Pointer to the newly created reference
0141  * @param repo Repository where that reference will live
0142  * @param name The name of the reference
0143  * @param target The target of the reference
0144  * @param force Overwrite existing references
0145  * @param log_message The one line long message to be appended to the reflog
0146  * @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
0147  */
0148 GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const char *log_message);
0149 
0150 /**
0151  * Create a new direct reference.
0152  *
0153  * A direct reference (also called an object id reference) refers directly
0154  * to a specific object id (a.k.a. OID or SHA) in the repository.  The id
0155  * permanently refers to the object (although the reference itself can be
0156  * moved).  For example, in libgit2 the direct ref "refs/tags/v0.17.0"
0157  * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977.
0158  *
0159  * The direct reference will be created in the repository and written to
0160  * the disk.  The generated reference object must be freed by the user.
0161  *
0162  * Valid reference names must follow one of two patterns:
0163  *
0164  * 1. Top-level names must contain only capital letters and underscores,
0165  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
0166  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
0167  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
0168  *    sequences ".." and "@{" which have special meaning to revparse.
0169  *
0170  * This function will return an error if a reference already exists with the
0171  * given name unless `force` is true, in which case it will be overwritten.
0172  *
0173  * The message for the reflog will be ignored if the reference does
0174  * not belong in the standard set (HEAD, branches and remote-tracking
0175  * branches) and it does not have a reflog.
0176  *
0177  * @param out Pointer to the newly created reference
0178  * @param repo Repository where that reference will live
0179  * @param name The name of the reference
0180  * @param id The object id pointed to by the reference.
0181  * @param force Overwrite existing references
0182  * @param log_message The one line long message to be appended to the reflog
0183  * @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
0184  */
0185 GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const char *log_message);
0186 
0187 /**
0188  * Conditionally create new direct reference
0189  *
0190  * A direct reference (also called an object id reference) refers directly
0191  * to a specific object id (a.k.a. OID or SHA) in the repository.  The id
0192  * permanently refers to the object (although the reference itself can be
0193  * moved).  For example, in libgit2 the direct ref "refs/tags/v0.17.0"
0194  * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977.
0195  *
0196  * The direct reference will be created in the repository and written to
0197  * the disk.  The generated reference object must be freed by the user.
0198  *
0199  * Valid reference names must follow one of two patterns:
0200  *
0201  * 1. Top-level names must contain only capital letters and underscores,
0202  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
0203  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
0204  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
0205  *    sequences ".." and "@{" which have special meaning to revparse.
0206  *
0207  * This function will return an error if a reference already exists with the
0208  * given name unless `force` is true, in which case it will be overwritten.
0209  *
0210  * The message for the reflog will be ignored if the reference does
0211  * not belong in the standard set (HEAD, branches and remote-tracking
0212  * branches) and it does not have a reflog.
0213  *
0214  * It will return GIT_EMODIFIED if the reference's value at the time
0215  * of updating does not match the one passed through `current_id`
0216  * (i.e. if the ref has changed since the user read it).
0217  *
0218  * @param out Pointer to the newly created reference
0219  * @param repo Repository where that reference will live
0220  * @param name The name of the reference
0221  * @param id The object id pointed to by the reference.
0222  * @param force Overwrite existing references
0223  * @param current_id The expected value of the reference at the time of update
0224  * @param log_message The one line long message to be appended to the reflog
0225  * @return 0 on success, GIT_EMODIFIED if the value of the reference
0226  * has changed, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code
0227  */
0228 GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_oid *current_id, const char *log_message);
0229 
0230 /**
0231  * Get the OID pointed to by a direct reference.
0232  *
0233  * Only available if the reference is direct (i.e. an object id reference,
0234  * not a symbolic one).
0235  *
0236  * To find the OID of a symbolic ref, call `git_reference_resolve()` and
0237  * then this function (or maybe use `git_reference_name_to_id()` to
0238  * directly resolve a reference name all the way through to an OID).
0239  *
0240  * @param ref The reference
0241  * @return a pointer to the oid if available, NULL otherwise
0242  */
0243 GIT_EXTERN(const git_oid *) git_reference_target(const git_reference *ref);
0244 
0245 /**
0246  * Return the peeled OID target of this reference.
0247  *
0248  * This peeled OID only applies to direct references that point to
0249  * a hard Tag object: it is the result of peeling such Tag.
0250  *
0251  * @param ref The reference
0252  * @return a pointer to the oid if available, NULL otherwise
0253  */
0254 GIT_EXTERN(const git_oid *) git_reference_target_peel(const git_reference *ref);
0255 
0256 /**
0257  * Get full name to the reference pointed to by a symbolic reference.
0258  *
0259  * Only available if the reference is symbolic.
0260  *
0261  * @param ref The reference
0262  * @return a pointer to the name if available, NULL otherwise
0263  */
0264 GIT_EXTERN(const char *) git_reference_symbolic_target(const git_reference *ref);
0265 
0266 /**
0267  * Get the type of a reference.
0268  *
0269  * Either direct (GIT_REFERENCE_DIRECT) or symbolic (GIT_REFERENCE_SYMBOLIC)
0270  *
0271  * @param ref The reference
0272  * @return the type
0273  */
0274 GIT_EXTERN(git_reference_t) git_reference_type(const git_reference *ref);
0275 
0276 /**
0277  * Get the full name of a reference.
0278  *
0279  * See `git_reference_symbolic_create()` for rules about valid names.
0280  *
0281  * @param ref The reference
0282  * @return the full name for the ref
0283  */
0284 GIT_EXTERN(const char *) git_reference_name(const git_reference *ref);
0285 
0286 /**
0287  * Resolve a symbolic reference to a direct reference.
0288  *
0289  * This method iteratively peels a symbolic reference until it resolves to
0290  * a direct reference to an OID.
0291  *
0292  * The peeled reference is returned in the `resolved_ref` argument, and
0293  * must be freed manually once it's no longer needed.
0294  *
0295  * If a direct reference is passed as an argument, a copy of that
0296  * reference is returned. This copy must be manually freed too.
0297  *
0298  * @param out Pointer to the peeled reference
0299  * @param ref The reference
0300  * @return 0 or an error code
0301  */
0302 GIT_EXTERN(int) git_reference_resolve(git_reference **out, const git_reference *ref);
0303 
0304 /**
0305  * Get the repository where a reference resides.
0306  *
0307  * @param ref The reference
0308  * @return a pointer to the repo
0309  */
0310 GIT_EXTERN(git_repository *) git_reference_owner(const git_reference *ref);
0311 
0312 /**
0313  * Create a new reference with the same name as the given reference but a
0314  * different symbolic target. The reference must be a symbolic reference,
0315  * otherwise this will fail.
0316  *
0317  * The new reference will be written to disk, overwriting the given reference.
0318  *
0319  * The target name will be checked for validity.
0320  * See `git_reference_symbolic_create()` for rules about valid names.
0321  *
0322  * The message for the reflog will be ignored if the reference does
0323  * not belong in the standard set (HEAD, branches and remote-tracking
0324  * branches) and it does not have a reflog.
0325  *
0326  * @param out Pointer to the newly created reference
0327  * @param ref The reference
0328  * @param target The new target for the reference
0329  * @param log_message The one line long message to be appended to the reflog
0330  * @return 0 on success, GIT_EINVALIDSPEC or an error code
0331  */
0332 GIT_EXTERN(int) git_reference_symbolic_set_target(
0333     git_reference **out,
0334     git_reference *ref,
0335     const char *target,
0336     const char *log_message);
0337 
0338 /**
0339  * Conditionally create a new reference with the same name as the given reference but a
0340  * different OID target. The reference must be a direct reference, otherwise
0341  * this will fail.
0342  *
0343  * The new reference will be written to disk, overwriting the given reference.
0344  *
0345  * @param out Pointer to the newly created reference
0346  * @param ref The reference
0347  * @param id The new target OID for the reference
0348  * @param log_message The one line long message to be appended to the reflog
0349  * @return 0 on success, GIT_EMODIFIED if the value of the reference
0350  * has changed since it was read, or an error code
0351  */
0352 GIT_EXTERN(int) git_reference_set_target(
0353     git_reference **out,
0354     git_reference *ref,
0355     const git_oid *id,
0356     const char *log_message);
0357 
0358 /**
0359  * Rename an existing reference.
0360  *
0361  * This method works for both direct and symbolic references.
0362  *
0363  * The new name will be checked for validity.
0364  * See `git_reference_symbolic_create()` for rules about valid names.
0365  *
0366  * If the `force` flag is not enabled, and there's already
0367  * a reference with the given name, the renaming will fail.
0368  *
0369  * IMPORTANT:
0370  * The user needs to write a proper reflog entry if the
0371  * reflog is enabled for the repository. We only rename
0372  * the reflog if it exists.
0373  *
0374  * @param ref The reference to rename
0375  * @param new_name The new name for the reference
0376  * @param force Overwrite an existing reference
0377  * @param log_message The one line long message to be appended to the reflog
0378  * @return 0 on success, GIT_EINVALIDSPEC, GIT_EEXISTS or an error code
0379  *
0380  */
0381 GIT_EXTERN(int) git_reference_rename(
0382     git_reference **new_ref,
0383     git_reference *ref,
0384     const char *new_name,
0385     int force,
0386     const char *log_message);
0387 
0388 /**
0389  * Delete an existing reference.
0390  *
0391  * This method works for both direct and symbolic references.  The reference
0392  * will be immediately removed on disk but the memory will not be freed.
0393  * Callers must call `git_reference_free`.
0394  *
0395  * This function will return an error if the reference has changed
0396  * from the time it was looked up.
0397  *
0398  * @param ref The reference to remove
0399  * @return 0, GIT_EMODIFIED or an error code
0400  */
0401 GIT_EXTERN(int) git_reference_delete(git_reference *ref);
0402 
0403 /**
0404  * Delete an existing reference by name
0405  *
0406  * This method removes the named reference from the repository without
0407  * looking at its old value.
0408  *
0409  * @param name The reference to remove
0410  * @return 0 or an error code
0411  */
0412 GIT_EXTERN(int) git_reference_remove(git_repository *repo, const char *name);
0413 
0414 /**
0415  * Fill a list with all the references that can be found in a repository.
0416  *
0417  * The string array will be filled with the names of all references; these
0418  * values are owned by the user and should be free'd manually when no
0419  * longer needed, using `git_strarray_free()`.
0420  *
0421  * @param array Pointer to a git_strarray structure where
0422  *      the reference names will be stored
0423  * @param repo Repository where to find the refs
0424  * @return 0 or an error code
0425  */
0426 GIT_EXTERN(int) git_reference_list(git_strarray *array, git_repository *repo);
0427 
0428 /**
0429  * Callback used to iterate over references
0430  *
0431  * @see git_reference_foreach
0432  *
0433  * @param reference The reference object
0434  * @param payload Payload passed to git_reference_foreach
0435  * @return non-zero to terminate the iteration
0436  */
0437 typedef int GIT_CALLBACK(git_reference_foreach_cb)(git_reference *reference, void *payload);
0438 
0439 /**
0440  * Callback used to iterate over reference names
0441  *
0442  * @see git_reference_foreach_name
0443  *
0444  * @param name The reference name
0445  * @param payload Payload passed to git_reference_foreach_name
0446  * @return non-zero to terminate the iteration
0447  */
0448 typedef int GIT_CALLBACK(git_reference_foreach_name_cb)(const char *name, void *payload);
0449 
0450 /**
0451  * Perform a callback on each reference in the repository.
0452  *
0453  * The `callback` function will be called for each reference in the
0454  * repository, receiving the reference object and the `payload` value
0455  * passed to this method.  Returning a non-zero value from the callback
0456  * will terminate the iteration.
0457  *
0458  * Note that the callback function is responsible to call `git_reference_free`
0459  * on each reference passed to it.
0460  *
0461  * @param repo Repository where to find the refs
0462  * @param callback Function which will be called for every listed ref
0463  * @param payload Additional data to pass to the callback
0464  * @return 0 on success, non-zero callback return value, or error code
0465  */
0466 GIT_EXTERN(int) git_reference_foreach(
0467     git_repository *repo,
0468     git_reference_foreach_cb callback,
0469     void *payload);
0470 
0471 /**
0472  * Perform a callback on the fully-qualified name of each reference.
0473  *
0474  * The `callback` function will be called for each reference in the
0475  * repository, receiving the name of the reference and the `payload` value
0476  * passed to this method.  Returning a non-zero value from the callback
0477  * will terminate the iteration.
0478  *
0479  * @param repo Repository where to find the refs
0480  * @param callback Function which will be called for every listed ref name
0481  * @param payload Additional data to pass to the callback
0482  * @return 0 on success, non-zero callback return value, or error code
0483  */
0484 GIT_EXTERN(int) git_reference_foreach_name(
0485     git_repository *repo,
0486     git_reference_foreach_name_cb callback,
0487     void *payload);
0488 
0489 /**
0490  * Create a copy of an existing reference.
0491  *
0492  * Call `git_reference_free` to free the data.
0493  *
0494  * @param dest pointer where to store the copy
0495  * @param source object to copy
0496  * @return 0 or an error code
0497  */
0498 GIT_EXTERN(int) git_reference_dup(git_reference **dest, git_reference *source);
0499 
0500 /**
0501  * Free the given reference.
0502  *
0503  * @param ref git_reference
0504  */
0505 GIT_EXTERN(void) git_reference_free(git_reference *ref);
0506 
0507 /**
0508  * Compare two references.
0509  *
0510  * @param ref1 The first git_reference
0511  * @param ref2 The second git_reference
0512  * @return 0 if the same, else a stable but meaningless ordering.
0513  */
0514 GIT_EXTERN(int) git_reference_cmp(
0515     const git_reference *ref1,
0516     const git_reference *ref2);
0517 
0518 /**
0519  * Create an iterator for the repo's references
0520  *
0521  * @param out pointer in which to store the iterator
0522  * @param repo the repository
0523  * @return 0 or an error code
0524  */
0525 GIT_EXTERN(int) git_reference_iterator_new(
0526     git_reference_iterator **out,
0527     git_repository *repo);
0528 
0529 /**
0530  * Create an iterator for the repo's references that match the
0531  * specified glob
0532  *
0533  * @param out pointer in which to store the iterator
0534  * @param repo the repository
0535  * @param glob the glob to match against the reference names
0536  * @return 0 or an error code
0537  */
0538 GIT_EXTERN(int) git_reference_iterator_glob_new(
0539     git_reference_iterator **out,
0540     git_repository *repo,
0541     const char *glob);
0542 
0543 /**
0544  * Get the next reference
0545  *
0546  * @param out pointer in which to store the reference
0547  * @param iter the iterator
0548  * @return 0, GIT_ITEROVER if there are no more; or an error code
0549  */
0550 GIT_EXTERN(int) git_reference_next(git_reference **out, git_reference_iterator *iter);
0551 
0552 /**
0553  * Get the next reference's name
0554  *
0555  * This function is provided for convenience in case only the names
0556  * are interesting as it avoids the allocation of the `git_reference`
0557  * object which `git_reference_next()` needs.
0558  *
0559  * @param out pointer in which to store the string
0560  * @param iter the iterator
0561  * @return 0, GIT_ITEROVER if there are no more; or an error code
0562  */
0563 GIT_EXTERN(int) git_reference_next_name(const char **out, git_reference_iterator *iter);
0564 
0565 /**
0566  * Free the iterator and its associated resources
0567  *
0568  * @param iter the iterator to free
0569  */
0570 GIT_EXTERN(void) git_reference_iterator_free(git_reference_iterator *iter);
0571 
0572 /**
0573  * Perform a callback on each reference in the repository whose name
0574  * matches the given pattern.
0575  *
0576  * This function acts like `git_reference_foreach()` with an additional
0577  * pattern match being applied to the reference name before issuing the
0578  * callback function.  See that function for more information.
0579  *
0580  * The pattern is matched using fnmatch or "glob" style where a '*' matches
0581  * any sequence of letters, a '?' matches any letter, and square brackets
0582  * can be used to define character ranges (such as "[0-9]" for digits).
0583  *
0584  * @param repo Repository where to find the refs
0585  * @param glob Pattern to match (fnmatch-style) against reference name.
0586  * @param callback Function which will be called for every listed ref
0587  * @param payload Additional data to pass to the callback
0588  * @return 0 on success, GIT_EUSER on non-zero callback, or error code
0589  */
0590 GIT_EXTERN(int) git_reference_foreach_glob(
0591     git_repository *repo,
0592     const char *glob,
0593     git_reference_foreach_name_cb callback,
0594     void *payload);
0595 
0596 /**
0597  * Check if a reflog exists for the specified reference.
0598  *
0599  * @param repo the repository
0600  * @param refname the reference's name
0601  * @return 0 when no reflog can be found, 1 when it exists;
0602  * otherwise an error code.
0603  */
0604 GIT_EXTERN(int) git_reference_has_log(git_repository *repo, const char *refname);
0605 
0606 /**
0607  * Ensure there is a reflog for a particular reference.
0608  *
0609  * Make sure that successive updates to the reference will append to
0610  * its log.
0611  *
0612  * @param repo the repository
0613  * @param refname the reference's name
0614  * @return 0 or an error code.
0615  */
0616 GIT_EXTERN(int) git_reference_ensure_log(git_repository *repo, const char *refname);
0617 
0618 /**
0619  * Check if a reference is a local branch.
0620  *
0621  * @param ref A git reference
0622  *
0623  * @return 1 when the reference lives in the refs/heads
0624  * namespace; 0 otherwise.
0625  */
0626 GIT_EXTERN(int) git_reference_is_branch(const git_reference *ref);
0627 
0628 /**
0629  * Check if a reference is a remote tracking branch
0630  *
0631  * @param ref A git reference
0632  *
0633  * @return 1 when the reference lives in the refs/remotes
0634  * namespace; 0 otherwise.
0635  */
0636 GIT_EXTERN(int) git_reference_is_remote(const git_reference *ref);
0637 
0638 /**
0639  * Check if a reference is a tag
0640  *
0641  * @param ref A git reference
0642  *
0643  * @return 1 when the reference lives in the refs/tags
0644  * namespace; 0 otherwise.
0645  */
0646 GIT_EXTERN(int) git_reference_is_tag(const git_reference *ref);
0647 
0648 /**
0649  * Check if a reference is a note
0650  *
0651  * @param ref A git reference
0652  *
0653  * @return 1 when the reference lives in the refs/notes
0654  * namespace; 0 otherwise.
0655  */
0656 GIT_EXTERN(int) git_reference_is_note(const git_reference *ref);
0657 
0658 /**
0659  * Normalization options for reference lookup
0660  */
0661 typedef enum {
0662     /**
0663      * No particular normalization.
0664      */
0665     GIT_REFERENCE_FORMAT_NORMAL = 0u,
0666 
0667     /**
0668      * Control whether one-level refnames are accepted
0669      * (i.e., refnames that do not contain multiple /-separated
0670      * components). Those are expected to be written only using
0671      * uppercase letters and underscore (FETCH_HEAD, ...)
0672      */
0673     GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL = (1u << 0),
0674 
0675     /**
0676      * Interpret the provided name as a reference pattern for a
0677      * refspec (as used with remote repositories). If this option
0678      * is enabled, the name is allowed to contain a single * (<star>)
0679      * in place of a one full pathname component
0680      * (e.g., foo/<star>/bar but not foo/bar<star>).
0681      */
0682     GIT_REFERENCE_FORMAT_REFSPEC_PATTERN = (1u << 1),
0683 
0684     /**
0685      * Interpret the name as part of a refspec in shorthand form
0686      * so the `ONELEVEL` naming rules aren't enforced and 'master'
0687      * becomes a valid name.
0688      */
0689     GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2)
0690 } git_reference_format_t;
0691 
0692 /**
0693  * Normalize reference name and check validity.
0694  *
0695  * This will normalize the reference name by removing any leading slash
0696  * '/' characters and collapsing runs of adjacent slashes between name
0697  * components into a single slash.
0698  *
0699  * Once normalized, if the reference name is valid, it will be returned in
0700  * the user allocated buffer.
0701  *
0702  * See `git_reference_symbolic_create()` for rules about valid names.
0703  *
0704  * @param buffer_out User allocated buffer to store normalized name
0705  * @param buffer_size Size of buffer_out
0706  * @param name Reference name to be checked.
0707  * @param flags Flags to constrain name validation rules - see the
0708  *              GIT_REFERENCE_FORMAT constants above.
0709  * @return 0 on success, GIT_EBUFS if buffer is too small, GIT_EINVALIDSPEC
0710  * or an error code.
0711  */
0712 GIT_EXTERN(int) git_reference_normalize_name(
0713     char *buffer_out,
0714     size_t buffer_size,
0715     const char *name,
0716     unsigned int flags);
0717 
0718 /**
0719  * Recursively peel reference until object of the specified type is found.
0720  *
0721  * The retrieved `peeled` object is owned by the repository
0722  * and should be closed with the `git_object_free` method.
0723  *
0724  * If you pass `GIT_OBJECT_ANY` as the target type, then the object
0725  * will be peeled until a non-tag object is met.
0726  *
0727  * @param out Pointer to the peeled git_object
0728  * @param ref The reference to be processed
0729  * @param type The type of the requested object (GIT_OBJECT_COMMIT,
0730  * GIT_OBJECT_TAG, GIT_OBJECT_TREE, GIT_OBJECT_BLOB or GIT_OBJECT_ANY).
0731  * @return 0 on success, GIT_EAMBIGUOUS, GIT_ENOTFOUND or an error code
0732  */
0733 GIT_EXTERN(int) git_reference_peel(
0734     git_object **out,
0735     const git_reference *ref,
0736     git_object_t type);
0737 
0738 /**
0739  * Ensure the reference name is well-formed.
0740  *
0741  * Valid reference names must follow one of two patterns:
0742  *
0743  * 1. Top-level names must contain only capital letters and underscores,
0744  *    and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
0745  * 2. Names prefixed with "refs/" can be almost anything.  You must avoid
0746  *    the characters '~', '^', ':', '\\', '?', '[', and '*', and the
0747  *    sequences ".." and "@{" which have special meaning to revparse.
0748  *
0749  * @param valid output pointer to set with validity of given reference name
0750  * @param refname name to be checked.
0751  * @return 0 on success or an error code
0752  */
0753 GIT_EXTERN(int) git_reference_name_is_valid(int *valid, const char *refname);
0754 
0755 /**
0756  * Get the reference's short name
0757  *
0758  * This will transform the reference name into a name "human-readable"
0759  * version. If no shortname is appropriate, it will return the full
0760  * name.
0761  *
0762  * The memory is owned by the reference and must not be freed.
0763  *
0764  * @param ref a reference
0765  * @return the human-readable version of the name
0766  */
0767 GIT_EXTERN(const char *) git_reference_shorthand(const git_reference *ref);
0768 
0769 /** @} */
0770 GIT_END_DECL
0771 #endif