diff options
Diffstat (limited to 'include/git2')
-rw-r--r-- | include/git2/errors.h | 1 | ||||
-rw-r--r-- | include/git2/refs.h | 109 | ||||
-rw-r--r-- | include/git2/sys/refdb_backend.h | 5 |
3 files changed, 106 insertions, 9 deletions
diff --git a/include/git2/errors.h b/include/git2/errors.h index 973d56003..bcf2f80ab 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -40,6 +40,7 @@ typedef enum { GIT_EINVALIDSPEC = -12, /*< Name/ref spec was not in a valid format */ GIT_EMERGECONFLICT = -13, /*< Merge conflicts prevented operation */ GIT_ELOCKED = -14, /*< Lock file prevented operation */ + GIT_EMODIFIED = -15, /*< Reference value does not match expected */ GIT_PASSTHROUGH = -30, /*< Internal only */ GIT_ITEROVER = -31, /*< Signals end of iteration with iterator */ diff --git a/include/git2/refs.h b/include/git2/refs.h index f9aaea827..970faf744 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -68,6 +68,46 @@ GIT_EXTERN(int) git_reference_name_to_id( GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, const char *shorthand); /** + * Conditionally create a new symbolic reference. + * + * A symbolic reference is a reference name that refers to another + * reference name. If the other name moves, the symbolic name will move, + * too. As a simple example, the "HEAD" reference might refer to + * "refs/heads/master" while on the "master" branch of a repository. + * + * The symbolic reference will be created in the repository and written to + * the disk. The generated reference object must be freed by the user. + * + * Valid reference names must follow one of two patterns: + * + * 1. Top-level names must contain only capital letters and underscores, + * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). + * 2. Names prefixed with "refs/" can be almost anything. You must avoid + * the characters '~', '^', ':', '\\', '?', '[', and '*', and the + * sequences ".." and "@{" which have special meaning to revparse. + * + * This function will return an error if a reference already exists with the + * given name unless `force` is true, in which case it will be overwritten. + * + * The signature and message for the reflog will be ignored if the + * reference does not belong in the standard set (HEAD, branches and + * remote-tracking branches) and it does not have a reflog. + * + * It will also return an error if the reference's value at the time + * of updating does not match the one passed. + * + * @param out Pointer to the newly created reference + * @param repo Repository where that reference will live + * @param name The name of the reference + * @param target The target of the reference + * @param force Overwrite existing references + * @param signature The identity that will used to populate the reflog entry + * @param log_message The one line long message to be appended to the reflog + * @return 0 on success, GIT_EEXISTS, GIT_EINVALIDSPEC, GIT_EMODIFIED or an error code + */ +GIT_EXTERN(int) git_reference_symbolic_create_matching(git_reference **out, git_repository *repo, const char *name, const char *target, int force, const git_signature *signature, const char *log_message, const char *old_value); + +/** * Create a new symbolic reference. * * A symbolic reference is a reference name that refers to another @@ -144,6 +184,50 @@ GIT_EXTERN(int) git_reference_symbolic_create(git_reference **out, git_repositor GIT_EXTERN(int) git_reference_create(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_signature *signature, const char *log_message); /** + * Conditionally create new direct reference + * + * A direct reference (also called an object id reference) refers directly + * to a specific object id (a.k.a. OID or SHA) in the repository. The id + * permanently refers to the object (although the reference itself can be + * moved). For example, in libgit2 the direct ref "refs/tags/v0.17.0" + * refers to OID 5b9fac39d8a76b9139667c26a63e6b3f204b3977. + * + * The direct reference will be created in the repository and written to + * the disk. The generated reference object must be freed by the user. + * + * Valid reference names must follow one of two patterns: + * + * 1. Top-level names must contain only capital letters and underscores, + * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD"). + * 2. Names prefixed with "refs/" can be almost anything. You must avoid + * the characters '~', '^', ':', '\\', '?', '[', and '*', and the + * sequences ".." and "@{" which have special meaning to revparse. + * + * This function will return an error if a reference already exists with the + * given name unless `force` is true, in which case it will be overwritten. + * + * The signature and message for the reflog will be ignored if the + * reference does not belong in the standard set (HEAD, branches and + * remote-tracking branches) and and it does not have a reflog. + * + * It will also return an error if the reference's value at the time + * of updating does not match the one passed. + * + * @param out Pointer to the newly created reference + * @param repo Repository where that reference will live + * @param name The name of the reference + * @param id The object id pointed to by the reference. + * @param force Overwrite existing references + * @param force Overwrite existing references + * @param signature The identity that will used to populate the reflog entry + * @param log_message The one line long message to be appended to the reflog + * @param old_id The old value which the reference should have + * @return 0 on success, GIT_EMODIFIED if the value of the reference + * has changed, GIT_EEXISTS, GIT_EINVALIDSPEC or an error code + */ +GIT_EXTERN(int) git_reference_create_matching(git_reference **out, git_repository *repo, const char *name, const git_oid *id, int force, const git_signature *signature, const char *log_message, const git_oid *old_id); + +/** * Get the OID pointed to by a direct reference. * * Only available if the reference is direct (i.e. an object id reference, @@ -254,22 +338,19 @@ GIT_EXTERN(int) git_reference_symbolic_set_target( const char *log_message); /** - * Create a new reference with the same name as the given reference but a + * Conditionally create a new reference with the same name as the given reference but a * different OID target. The reference must be a direct reference, otherwise * this will fail. * * The new reference will be written to disk, overwriting the given reference. * - * The signature and message for the reflog will be ignored if the - * reference does not belong in the standard set (HEAD, branches and - * remote-tracking branches) and and it does not have a reflog. - * * @param out Pointer to the newly created reference * @param ref The reference * @param id The new target OID for the reference * @param signature The identity that will used to populate the reflog entry * @param log_message The one line long message to be appended to the reflog - * @return 0 or an error code + * @return 0 on success, GIT_EMODIFIED if the value of the reference + * has changed, or an error code */ GIT_EXTERN(int) git_reference_set_target( git_reference **out, @@ -317,12 +398,26 @@ GIT_EXTERN(int) git_reference_rename( * will be immediately removed on disk but the memory will not be freed. * Callers must call `git_reference_free`. * + * This function will return an error if the reference has changed + * from the time it was looked up. + * * @param ref The reference to remove - * @return 0 or an error code + * @return 0, GIT_EMODIFIED or an error code */ GIT_EXTERN(int) git_reference_delete(git_reference *ref); /** + * Delete an existing reference by name + * + * This method removes the named reference from the repository without + * looking at its old value. + * + * @param ref The reference to remove + * @return 0, GIT_EMODIFIED or an error code + */ +GIT_EXTERN(int) git_reference_remove(git_repository *repo, const char *name); + +/** * Fill a list with all the references that can be found in a repository. * * The string array will be filled with the names of all references; these diff --git a/include/git2/sys/refdb_backend.h b/include/git2/sys/refdb_backend.h index 5bbd4ba4c..aa5ef9ecc 100644 --- a/include/git2/sys/refdb_backend.h +++ b/include/git2/sys/refdb_backend.h @@ -94,7 +94,8 @@ struct git_refdb_backend { */ int (*write)(git_refdb_backend *backend, const git_reference *ref, int force, - const git_signature *who, const char *message); + const git_signature *who, const char *message, + const git_oid *old, const char *old_target); int (*rename)( git_reference **out, git_refdb_backend *backend, @@ -105,7 +106,7 @@ struct git_refdb_backend { * Deletes the given reference from the refdb. A refdb implementation * must provide this function. */ - int (*del)(git_refdb_backend *backend, const char *ref_name); + int (*del)(git_refdb_backend *backend, const char *ref_name, const git_oid *old_id, const char *old_target); /** * Suggests that the given refdb compress or optimize its references. |