[PATCH v7 30/33] refs: break out resolve_ref_unsafe_submodule

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

 



It will soon be useful for resolve_ref_unsafe to support submodules.
But since it is called from so many places, changing it would have
been painful.  Fortunately, it's just a thin wrapper around (the
former) resolve_ref_1.  So now resolve_ref_1 becomes
resolve_ref_unsafe_submodule, and it passes its submodule argument
through to read_raw_ref.

The files backend doesn't need this functionality, but it doesn't
hurt.

Signed-off-by: David Turner <dturner@xxxxxxxxxxxxxxxx>
Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 refs.c               | 41 +++++++++++++++++++++++++----------------
 refs/files-backend.c |  8 ++++++--
 refs/refs-internal.h | 19 ++++++++++++++++---
 3 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/refs.c b/refs.c
index 5fe0bac..d1cf707 100644
--- a/refs.c
+++ b/refs.c
@@ -60,6 +60,9 @@ void register_ref_storage_backends(void)
 	 * entries below when you add a new backend.
 	 */
 	register_ref_storage_backend(&refs_be_files);
+#ifdef USE_LIBLMDB
+	register_ref_storage_backend(&refs_be_lmdb);
+#endif
 }
 
 /*
@@ -320,8 +323,10 @@ static int submodule_backend(const char *key, const char *value, void *data)
 	const char **path = data;
 	char **old_path = data;
 	if (!strcmp(key, "extensions.refstorage") &&
-	    !git_config_string(path, key, "extensions.refstorage"))
-			free(*old_path);
+	    !git_config_string(path, key, "extensions.refstorage")) {
+		free(*old_path);
+		*path = xstrdup(value);
+	}
 
 	return 0;
 }
@@ -1313,21 +1318,22 @@ int for_each_rawref(each_ref_fn fn, void *cb_data)
 			       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);
 }
 
-static int read_raw_ref(const char *refname, unsigned char *sha1,
-			struct strbuf *symref, struct strbuf *sb_path,
-			unsigned int *flags)
+static int read_raw_ref(const char *submodule, const char *refname,
+			unsigned char *sha1, struct strbuf *symref,
+			struct strbuf *sb_path, unsigned int *flags)
 {
-	return the_refs_backend->read_raw_ref(refname, sha1, symref, sb_path,
-					      flags);
+	return the_refs_backend->read_raw_ref(submodule, refname, sha1,
+					      symref, sb_path, flags);
 }
 
 /* This function needs to return a meaningful errno on failure */
-static const char *resolve_ref_1(const char *refname,
-				 int resolve_flags,
-				 unsigned char *sha1,
-				 int *flags,
-				 struct strbuf *sb_refname,
-				 struct strbuf *sb_path)
+const char *resolve_ref_unsafe_submodule(const char *submodule,
+					 const char *refname,
+					 int resolve_flags,
+					 unsigned char *sha1,
+					 int *flags,
+					 struct strbuf *sb_refname,
+					 struct strbuf *sb_path)
 {
 	int bad_name = 0;
 	int symref_count;
@@ -1358,7 +1364,8 @@ static const char *resolve_ref_1(const char *refname,
 	for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
 		unsigned int read_flags = 0;
 
-		if (read_raw_ref(refname, sha1, sb_refname, sb_path, &read_flags)) {
+		if (read_raw_ref(submodule, refname, sha1, sb_refname, sb_path,
+				 &read_flags)) {
 			int saved_errno = errno;
 			if (flags)
 				*flags |= read_flags;
@@ -1419,8 +1426,8 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
 	struct strbuf sb_path = STRBUF_INIT;
 	const char *ret;
 
-	ret = resolve_ref_1(refname, resolve_flags, sha1, flags,
-			    &sb_refname, &sb_path);
+	ret = resolve_ref_unsafe_submodule(NULL, refname, resolve_flags, sha1,
+					   flags, &sb_refname, &sb_path);
 
 	strbuf_release(&sb_path);
 	return ret;
@@ -1663,6 +1670,8 @@ int safe_create_reflog(const char *refname, int force_create,
 
 int delete_reflog(const char *refname)
 {
+	if (ref_type(refname) != REF_TYPE_NORMAL)
+		return refs_be_files.delete_reflog(refname);
 	return the_refs_backend->delete_reflog(refname);
 }
 
diff --git a/refs/files-backend.c b/refs/files-backend.c
index a13d419..87c02f8 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -1413,7 +1413,8 @@ static int resolve_missing_loose_ref(const char *refname,
  *
  * sb_path is workspace: the caller should allocate and free it.
  */
-static int files_read_raw_ref(const char *refname, unsigned char *sha1,
+static int files_read_raw_ref(const char *submodule,
+			      const char *refname, unsigned char *sha1,
 			      struct strbuf *symref, struct strbuf *sb_path,
 			      unsigned int *flags)
 {
@@ -1423,7 +1424,10 @@ static int files_read_raw_ref(const char *refname, unsigned char *sha1,
 	const char *buf;
 
 	strbuf_reset(sb_path);
-	strbuf_git_path(sb_path, "%s", refname);
+	if (submodule)
+		strbuf_git_path_submodule(sb_path, submodule, "%s", refname);
+	else
+		strbuf_git_path(sb_path, "%s", refname);
 	path = sb_path->buf;
 
 	for (;;) {
diff --git a/refs/refs-internal.h b/refs/refs-internal.h
index 0d3f9e7..9736959 100644
--- a/refs/refs-internal.h
+++ b/refs/refs-internal.h
@@ -230,6 +230,15 @@ int do_for_each_per_worktree_ref(const char *submodule, const char *base,
 				 each_ref_fn fn, int trim, int flags,
 				 void *cb_data);
 
+
+const char *resolve_ref_unsafe_submodule(const char *submodule,
+					 const char *refname,
+					 int resolve_flags,
+					 unsigned char *sha1,
+					 int *flags,
+					 struct strbuf *sb_refname,
+					 struct strbuf *sb_path);
+
 /* refs backends */
 typedef int ref_init_db_fn(int shared, struct strbuf *err);
 typedef int ref_transaction_commit_fn(struct ref_transaction *transaction,
@@ -266,9 +275,9 @@ typedef int rename_ref_fn(const char *oldref, const char *newref,
 			  const char *logmsg);
 
 /* resolution methods */
-typedef int read_raw_ref_fn(const char *refname, unsigned char *sha1,
-			    struct strbuf *symref, struct strbuf *sb_path,
-			    unsigned int *flags);
+typedef int read_raw_ref_fn(const char *submodule, const char *refname,
+			    unsigned char *sha1, struct strbuf *symref,
+			    struct strbuf *sb_path, unsigned int *flags);
 typedef int verify_refname_available_fn(const char *refname, struct string_list *extra, struct string_list *skip, struct strbuf *err);
 typedef int resolve_gitlink_ref_fn(const char *path, const char *refname,
 				   unsigned char *sha1);
@@ -305,4 +314,8 @@ struct ref_storage_be {
 };
 
 extern struct ref_storage_be refs_be_files;
+
+#ifdef USE_LIBLMDB
+extern struct ref_storage_be refs_be_lmdb;
+#endif
 #endif /* REFS_REFS_INTERNAL_H */
-- 
2.4.2.767.g62658d5-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]