summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2016-09-04 16:08:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-09-09 22:28:13 (GMT)
commit424dcc7683a37d1f14aa0dd485300001cb854f6c (patch)
tree5dce65332dd68a05e624d597bfb1bf2e3893ac5b /refs.c
parentbd40dcda27cc7d6b8b247caa5b650992c5e397fb (diff)
downloadgit-424dcc7683a37d1f14aa0dd485300001cb854f6c.zip
git-424dcc7683a37d1f14aa0dd485300001cb854f6c.tar.gz
git-424dcc7683a37d1f14aa0dd485300001cb854f6c.tar.bz2
resolve_gitlink_ref(): implement using resolve_ref_recursively()
resolve_ref_recursively() can handle references in arbitrary files reference stores, so use it to resolve "gitlink" (i.e., submodule) references. Aside from removing redundant code, this allows submodule lookups to benefit from the much more robust code that we use for reading non-submodule references. And, since the code is now agnostic about reference backends, it will work for any future references backend (so move its definition to refs.c). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/refs.c b/refs.c
index 464fe71..7b86b4e 100644
--- a/refs.c
+++ b/refs.c
@@ -1299,6 +1299,30 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
resolve_flags, sha1, flags);
}
+int resolve_gitlink_ref(const char *path, const char *refname, unsigned char *sha1)
+{
+ int len = strlen(path);
+ struct strbuf submodule = STRBUF_INIT;
+ struct ref_store *refs;
+ int flags;
+
+ while (len && path[len-1] == '/')
+ len--;
+ if (!len)
+ return -1;
+
+ strbuf_add(&submodule, path, len);
+ refs = get_ref_store(submodule.buf);
+ strbuf_release(&submodule);
+ if (!refs)
+ return -1;
+
+ if (!resolve_ref_recursively(refs, refname, 0, sha1, &flags) ||
+ is_null_sha1(sha1))
+ return -1;
+ return 0;
+}
+
/* A pointer to the ref_store for the main repository: */
static struct ref_store *main_ref_store;