From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Robin H. Johnson" <robbat2@gentoo.org>,
"SZEDER Gábor" <szeder.dev@gmail.com>,
"Git Mailing List" <git@vger.kernel.org>
Subject: Re: git-clone --config order & fetching extra refs during initial clone
Date: Mon, 27 Feb 2017 16:12:17 -0500 [thread overview]
Message-ID: <20170227211217.73gydlxb2qu2sp3m@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqd1e3xx4c.fsf@gitster.mtv.corp.google.com>
On Mon, Feb 27, 2017 at 11:16:35AM -0800, Junio C Hamano wrote:
> >> TL;DR: git-clone ignores any fetch specs passed via --config.
> >
> > I agree that this is a bug. There's some previous discussion and an RFC
> > patch from lat March (author cc'd):
> >
> > http://public-inbox.org/git/1457313062-10073-1-git-send-email-szeder@ira.uka.de/
> >
> > That discussion veered off into alternatives, but I think the v2 posted
> > in that thread is taking a sane approach.
>
> Let's see how well it fares by cooking it in 'next' ;-)
>
> I think it was <1459349623-16443-1-git-send-email-szeder@ira.uka.de>,
> which needs a bit of massaging to apply to the current codebase.
Yeah, that is the most recent one I found.
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.
> @@ -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;
...
Though if I'm bikeshedding, I'd probably have written the whole thing
with an argv_array and avoided counting at all.
> + 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.
> 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.
If we wanted to be thorough, we could also check that the feature works
correctly with "--origin" (I think it does).
-Peff
next prev parent reply other threads:[~2017-02-27 21:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-25 19:12 git-clone --config order & fetching extra refs during initial clone Robin H. Johnson
2017-02-25 20:21 ` Jeff King
2017-02-25 20:50 ` Jeff King
2017-02-27 19:16 ` Junio C Hamano
2017-02-27 21:12 ` Jeff King [this message]
2017-03-11 0:41 ` SZEDER Gábor
2017-03-15 17:08 ` Jeff King
2017-05-03 14:42 ` SZEDER Gábor
2017-05-03 20:22 ` Jeff King
2017-05-04 6:57 ` Sebastian Schuberth
2017-05-09 1:33 ` Junio C Hamano
2017-05-09 2:10 ` Jeff King
2017-05-09 2:26 ` Jeff King
2017-05-09 2:50 ` Junio C Hamano
2017-05-04 7:28 ` Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170227211217.73gydlxb2qu2sp3m@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=robbat2@gentoo.org \
--cc=szeder.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).