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

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

 



On Fri, Jun 3, 2016 at 5:03 PM, Michael Haggerty <mhagger@xxxxxxxxxxxx> wrote:
> 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@xxxxxxxxxxxx>
> ---
> 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.

> +       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;
> +}
--
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]