Re: [PATCH 16/38] resolve_gitlink_ref(): implement using resolve_ref_recursively()

From
Eric Sunshine <hidden>
Date
2016-06-16 06:55:52
Reply to
Michael Haggerty, 2016-06-16
On Fri, Jun 3, 2016 at 5:03 PM, Michael Haggerty [off-list ref] wrote:
quoted hunk ↗ jump to hunk
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 <redacted>
---
diff --git a/refs.c b/refs.c
@@ -1299,6 +1299,30 @@ const char *resolve_ref_unsafe(const char *refname, int resolve_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);
It took me a moment to figure out that you're using the strbuf only
for its side-effect of giving you a NUL-terminated string needed by
get_ref_store(), and not because you need any fancy functionality of
strbuf. I wonder if xstrndup() would have made this clearer.

Not worth a re-roll.
quoted hunk ↗ jump to hunk
+       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;
+}
Thread (47 messages) 47 messages, 4 authors, 2016-07-13
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help