[PATCH v2 35/43] refs-be-files.c: add method to rename refs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We also have to make rename_ref_available public, since alternate
backends for rename_ref will need it.

Signed-off-by: David Turner <dturner@xxxxxxxxxxxxxxxx>
---
 refs-be-files.c | 20 +++-----------------
 refs.c          | 21 +++++++++++++++++++++
 refs.h          |  7 ++++++-
 3 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/refs-be-files.c b/refs-be-files.c
index 3f2d194..3bcfab3 100644
--- a/refs-be-files.c
+++ b/refs-be-files.c
@@ -2491,29 +2491,14 @@ out:
 	return ret;
 }
 
-static int rename_ref_available(const char *oldname, const char *newname)
-{
-	struct string_list skip = STRING_LIST_INIT_NODUP;
-	struct strbuf err = STRBUF_INIT;
-	int ret;
-
-	string_list_insert(&skip, oldname);
-	ret = !verify_refname_available(newname, NULL, &skip, &err);
-	if (!ret)
-		error("%s", err.buf);
-
-	string_list_clear(&skip, 0);
-	strbuf_release(&err);
-	return ret;
-}
-
 static int write_ref_to_lockfile(struct ref_lock *lock,
 				 const unsigned char *sha1, struct strbuf *err);
 static int commit_ref_update(struct ref_lock *lock,
 			     const unsigned char *sha1, const char *logmsg,
 			     int flags, struct strbuf *err);
 
-int rename_ref(const char *oldrefname, const char *newrefname, const char *logmsg)
+static int files_rename_ref(const char *oldrefname, const char *newrefname,
+			    const char *logmsg)
 {
 	unsigned char sha1[20], orig_sha1[20];
 	int flag = 0, logmoved = 0;
@@ -3777,6 +3762,7 @@ struct ref_be refs_be_files = {
 	files_transaction_commit,
 	files_initial_transaction_commit,
 	files_transaction_free,
+	files_rename_ref,
 	files_for_each_reflog_ent,
 	files_for_each_reflog_ent_reverse,
 	files_for_each_reflog,
diff --git a/refs.c b/refs.c
index 930c85c..1c2dd79 100644
--- a/refs.c
+++ b/refs.c
@@ -1052,6 +1052,11 @@ void ref_transaction_free(struct ref_transaction *transaction)
 	return the_refs_backend->transaction_free(transaction);
 }
 
+int rename_ref(const char *oldref, const char *newref, const char *logmsg)
+{
+	return the_refs_backend->rename_ref(oldref, newref, logmsg);
+}
+
 const char *resolve_ref_unsafe(const char *ref, int resolve_flags,
 			       unsigned char *sha1, int *flags)
 {
@@ -1066,6 +1071,22 @@ int verify_refname_available(const char *refname, struct string_list *extra,
 							  err);
 }
 
+int rename_ref_available(const char *oldname, const char *newname)
+{
+	struct string_list skip = STRING_LIST_INIT_NODUP;
+	struct strbuf err = STRBUF_INIT;
+	int ret;
+
+	string_list_insert(&skip, oldname);
+	ret = !verify_refname_available(newname, NULL, &skip, &err);
+	if (!ret)
+		error("%s", err.buf);
+
+	string_list_clear(&skip, 0);
+	strbuf_release(&err);
+	return ret;
+}
+
 int pack_refs(unsigned int flags)
 {
 	return the_refs_backend->pack_refs(flags);
diff --git a/refs.h b/refs.h
index 02001ef..823983b 100644
--- a/refs.h
+++ b/refs.h
@@ -378,10 +378,13 @@ extern const char *prettify_refname(const char *refname);
 extern char *shorten_unambiguous_ref(const char *refname, int strict);
 
 /** rename ref, return 0 on success **/
-extern int rename_ref(const char *oldref, const char *newref, const char *logmsg);
+extern int rename_ref(const char *oldref, const char *newref,
+		      const char *logmsg);
 
 extern int create_symref(const char *ref, const char *refs_heads_master, const char *logmsg);
 
+int rename_ref_available(const char *oldname, const char *newname);
+
 enum action_on_err {
 	UPDATE_REFS_MSG_ON_ERR,
 	UPDATE_REFS_DIE_ON_ERR,
@@ -633,6 +636,7 @@ typedef int (*reflog_expire_fn)(const char *refname, const unsigned char *sha1,
 
 /* resolution functions */
 typedef void (*ref_transaction_free_fn)(struct ref_transaction *transaction);
+typedef int (*rename_ref_fn)(const char *oldref, const char *newref, const char *logmsg);
 typedef const char *(*resolve_ref_unsafe_fn)(const char *ref,
 					     int resolve_flags,
 					     unsigned char *sha1, int *flags);
@@ -682,6 +686,7 @@ struct ref_be {
 	ref_transaction_commit_fn transaction_commit;
 	ref_transaction_commit_fn initial_transaction_commit;
 	ref_transaction_free_fn transaction_free;
+	rename_ref_fn rename_ref;
 	for_each_reflog_ent_fn for_each_reflog_ent;
 	for_each_reflog_ent_reverse_fn for_each_reflog_ent_reverse;
 	for_each_reflog_fn for_each_reflog;
-- 
2.4.2.644.g97b850b-twtrsrc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]