From fa204962006541bd9c111bd7f3fa37ed2f8a2d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 28 Mar 2011 12:00:50 +0200 Subject: Allow forcing the creation or renaming of references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add internal reference create and rename functions which take a force parameter, telling them to overwrite an existing reference if it exists. These functions try to update the reference if it's of the same type as the one it's going to be replaced by. Otherwise the old reference becomes invalid. Signed-off-by: Carlos Martín Nieto --- include/git2/refs.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'include/git2/refs.h') diff --git a/include/git2/refs.h b/include/git2/refs.h index da55eaa3b..9ecf77295 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -68,6 +68,27 @@ GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_reposito */ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target); +/** + * Create a new symbolic reference, overwriting an existing one with + * the same name, if it exists. + * + * If the new reference isn't a symbolic one, any pointers to the old + * reference become invalid. + * + * The reference will be created in the repository and written + * to the disk. + * + * This reference is owned by the repository and shall not + * be free'd by the user. + * + * @param ref_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 + * @return 0 on success; error code otherwise + */ +GIT_EXTERN(int) git_reference_create_symbolic_force(git_reference **ref_out, git_repository *repo, const char *name, const char *target); + /** * Create a new object id reference. * @@ -85,6 +106,27 @@ GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repos */ GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id); +/** + * Create a new object id reference, overwriting an existing one with + * the same name, if it exists. + * + * If the new reference isn't a symbolic one, any pointers to the old + * reference become invalid. + * + * The reference will be created in the repository and written + * to the disk. + * + * This reference is owned by the repository and shall not + * be free'd by the user. + * + * @param ref_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. + * @return 0 on success; error code otherwise + */ +GIT_EXTERN(int) git_reference_create_oid_force(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id); + /** * Get the OID pointed to by a reference. * @@ -189,6 +231,20 @@ GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id); */ GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name); +/** + * Rename an existing reference, overwriting an existing one with the + * same name, if it exists. + * + * This method works for both direct and symbolic references. + * The new name will be checked for validity and may be + * modified into a normalized form. + * + * The refernece will be immediately renamed in-memory + * and on disk. + * + */ +GIT_EXTERN(int) git_reference_rename_force(git_reference *ref, const char *new_name); + /** * Delete an existing reference * -- cgit v1.2.1