Re: [PATCH 16/38] resolve_gitlink_ref(): implement using resolve_ref_recursively()
- From
Michael Haggerty <mhagger@alum.mit.edu>
- Date
- Jun 16, 2016, 04:03 UTC
- Message-ID
- <5762250E.6020200@alum.mit.edu>
- In-Reply-To
- <CAPig+cQTDrUw63qWknZQxmuDBXkoYr6gLyp5Bu=JopeT394puw@mail.gmail.com>
On 06/14/2016 07:03 AM, Eric Sunshine wrote:
Show 33 quoted lines
> On Fri, Jun 3, 2016 at 5:03 PM, Michael Haggerty <mhagger@alum.mit.edu> 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@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.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