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

From: Michael Haggerty <[email-masked]>
Date: Thu, 16 Jun 2016 06:03:26 +0200

On 06/14/2016 07:03 AM, Eric Sunshine wrote:
> On Fri, Jun 3, 2016 at 5:03 PM, Michael Haggerty <[email-masked]> 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 <[email-masked]>
>> ---
>> 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.

I agree both that xstrndup() (or, in this case, xmemdupz()) would have
been clearer, and also that it's not worth a re-roll. I'll keep it in
mind if I touch this code again.

Thanks for your comment.

Michael