Re: [PATCH 16/38] resolve_gitlink_ref(): implement using resolve_ref_recursively()
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Jun 14, 2016, 05:03 UTC
- Message-ID
- <CAPig+cQTDrUw63qWknZQxmuDBXkoYr6gLyp5Bu=JopeT394puw@mail.gmail.com>
- In-Reply-To
- <a9787723bcd990413661b8cb2e5542d618ab6321.1464983301.git.mhagger@alum.mit.edu>
On Fri, Jun 3, 2016 at 5:03 PM, Michael Haggerty <mhagger@alum.mit.edu> wrote:
Show 25 quoted lines
> 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>
> ---
> 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.
Show 10 quoted lines
> + 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; > +}