Re: git-clone --config order & fetching extra refs during initial clone

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

 



On Mon, Feb 27, 2017 at 10:12 PM, Jeff King <peff@xxxxxxxx> wrote:

> I didn't actually review it very carefully before, but I'll do so now
> (spoiler: a few nits, but it looks fine).
>
>>  static struct ref *wanted_peer_refs(const struct ref *refs,
>> -             struct refspec *refspec)
>> +             struct refspec *refspec, unsigned int refspec_count)
>
> Most of the changes here and elsewhere are just about passing along
> multiple refspecs instead of a single, which makes sense.

The new parameter should perhaps be renamed to 'refspec_nr', though,
as '_nr' suffix seems to be more common in the codebase than '_count'.

>> @@ -856,7 +861,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>>       int submodule_progress;
>>
>>       struct refspec *refspec;
>> -     const char *fetch_pattern;
>> +     unsigned int refspec_count = 1;
>> +     const char **fetch_patterns;
>> +     const struct string_list *config_fetch_patterns;
>
> This "1" seems funny to up here by itself, as it must be kept in sync
> with the later logic that feeds exactly one non-configured refspec into
> our list. The current code isn't wrong, but it would be nice to have it
> all together. I.e., replacing:
>
>> +     if (config_fetch_patterns)
>> +             refspec_count = 1 + config_fetch_patterns->nr;
>> +     fetch_patterns = xcalloc(refspec_count, sizeof(*fetch_patterns));
>> +     fetch_patterns[0] = value.buf;
>
> with:
>
>   refspec_count = 1;
>   if (config_fetch_patterns)
>         refspec_count += config_fetch_patterns->nr;
>   ...

Agreed.

> Though if I'm bikeshedding, I'd probably have written the whole thing
> with an argv_array and avoided counting at all.

Yeah, I did notice that you love argv_array :)  I had to raise an
eyebrow recently while looking at send-pack and how it uses argv_array
to read refspecs from stdin into an array.  I think argv_array feels a
bit out of place in both cases.  Yes, it does exactly what's needed.
However, it's called *argv*_array, indicating that its contents is
destined to become the options of some command.  But that's not the
case in these two cases, we are not dealing with arguments to a
command, these are just arrays of strings.

However, leveraging get_remote() makes it moot anyway.

>> +     refspec = parse_fetch_refspec(refspec_count, fetch_patterns);
>>
>> +     strbuf_reset(&key);
>>       strbuf_reset(&value);
>>
>>       remote = remote_get(option_origin);
>
> I do also notice that right _after_ this parsing, we use remote_get(),
> which is supposed to give us this config anyway. Which makes me wonder
> if we could just reorder this to put remote_get() first, and then read
> the resulting refspecs from remote->fetch.

Though get_remote() does give us this config, at this point the
default fetch refspec has not been configured yet, therefore it's not
included in the resulting remote->fetch array.  The default refspec is
set in write_refspec_config(), but that's called only about two
screenfulls later.  So there is a bit of extra work to do in order to
leverage get_remote()'s parsing.

I think the simplest way is to keep parsing the default fetch refspec
manually, and then append it to the remote->fetch array.  Definitely
shorter and simpler than that parsing in the current patch.
Alternatively, we could set the default fetch refspec in the
configuration temporarily, only for the duration of the get_remote()
call, but it feels a bit too hackish...

>> diff --git a/t/t5611-clone-config.sh b/t/t5611-clone-config.sh
>> index e4850b778c..3bed17783b 100755
>> --- a/t/t5611-clone-config.sh
>> +++ b/t/t5611-clone-config.sh
>> @@ -37,6 +37,30 @@ test_expect_success 'clone -c config is available during clone' '
>>       test_cmp expect child/file
>>  '
>>
>> +test_expect_success 'clone -c remote.origin.fetch=<refspec> works' '
>> +     rm -rf child &&
>> +     git update-ref refs/grab/it refs/heads/master &&
>> +     git update-ref refs/keep/out refs/heads/master &&
>> +     git clone -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" . child &&
>> +     (
>> +             cd child &&
>> +             git for-each-ref --format="%(refname)" refs/grab/ >../actual
>> +     ) &&
>> +     echo refs/grab/it >expect &&
>> +     test_cmp expect actual
>> +'
>> +
>> +test_expect_success 'git -c remote.origin.fetch=<refspec> clone works' '
>> +     rm -rf child &&
>> +     git -c "remote.origin.fetch=+refs/grab/*:refs/grab/*" clone . child &&
>> +     (
>> +             cd child &&
>> +             git for-each-ref --format="%(refname)" refs/grab/ >../actual
>> +     ) &&
>> +     echo refs/grab/it >expect &&
>> +     test_cmp expect actual
>> +'
>
> These look reasonable. Using "git -C for-each-ref" would save a
> subshell, but that's minor.

Loosing a subshell is good, but I subjectively like how the
indentation highlights that that command operates on a different
repository.

However, the tests should also check that refs matching the default
fetch refspec are transferred, too, i.e. that the clone has something
under refs/remotes/origin/ as well.  Case in point is using the result
of get_remote(): at first I naively set out to use remote->fetch
as-is, which didn't include the default fetch refspec, hence didn't
fetch refs/heads/master, but the test succeeded nonetheless.

> If we wanted to be thorough, we could also check that the feature works
> correctly with "--origin" (I think it does).

I think it works, but I'm not quite sure what you mean with "works
correctly with --origin".

So just to be clear: the behaviour depends on whether the remote name
given in '-c remote.<name>.fetch=<refspec>' matches the name given to
the '--origin=<name>'.  If they match, then refs matching the
additional refspec are transferred, too.  That's good.  However, if
the two remote names don't match, then refs matching the additional
refspec are NOT transferred.  I think this is good, too, because only
the origin remote should be cloned, whatever it is called, and in this
case that additional refspec belongs to a different remote.

Gábor




[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]