]> git.ipfire.org Git - thirdparty/git.git/commitdiff
transport.c: introduce core.alternateRefsPrefixes
authorTaylor Blau <me@ttaylorr.com>
Mon, 8 Oct 2018 18:09:30 +0000 (11:09 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 9 Oct 2018 05:30:03 +0000 (14:30 +0900)
The recently-introduced "core.alternateRefsCommand" allows callers to
specify with high flexibility the tips that they wish to advertise from
alternates. This flexibility comes at the cost of some inconvenience
when the caller only wishes to limit the advertisement to one or more
prefixes.

For example, to advertise only tags, a caller using
'core.alternateRefsCommand' would have to do:

  $ git config core.alternateRefsCommand ' \
      f() { git -C "$1" for-each-ref \
              refs/tags --format="%(objectname)" }; f "$@"'

The above is cumbersome to write, so let's introduce a
"core.alternateRefsPrefixes" to address this common case. Instead, the
caller can run:

  $ git config core.alternateRefsPrefixes 'refs/tags'

Which will behave identically to the longer example using
"core.alternateRefsCommand".

Since the value of "core.alternateRefsPrefixes" is appended to 'git
for-each-ref' and then executed, include a "--" before taking the
configured value to avoid misinterpreting arguments as flags to 'git
for-each-ref'.

In the case that the caller wishes to specify multiple prefixes, they
may separate them by whitespace. If "core.alternateRefsCommand" is set,
it will take precedence over "core.alternateRefsPrefixes".

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
t/t5410-receive-pack-alternates.sh
transport.c

index 00224dea61b5c83248e5a5785f8e0a80f6b80031..3486f9f74979848caa5ea17ce90f0daaf32aa54d 100644 (file)
@@ -627,6 +627,13 @@ Note that you cannot generally put `git for-each-ref` directly into the config
 value, as it does not take a repository path as an argument (but you can wrap
 the command above in a shell script).
 
+core.alternateRefsPrefixes::
+       When listing references from an alternate, list only references that begin
+       with the given prefix. Prefixes match as if they were given as arguments to
+       linkgit:git-for-each-ref[1]. To list multiple prefixes, separate them with
+       whitespace. If `core.alternateRefsCommand` is set, setting
+       `core.alternateRefsPrefixes` has no effect.
+
 core.bare::
        If true this repository is assumed to be 'bare' and has no
        working directory associated with it.  If this is the case a
index 49d0fe44fbce0a1d21b773ec8b565763de5a8206..457c20c2a579d48a36a20a4742de4f7cab235f26 100755 (executable)
@@ -30,4 +30,12 @@ test_expect_success 'with core.alternateRefsCommand' '
        test_cmp expect actual.haves
 '
 
+test_expect_success 'with core.alternateRefsPrefixes' '
+       test_config -C fork core.alternateRefsPrefixes "refs/heads/private" &&
+       git rev-parse private/branch >expect &&
+       printf "0000" | git receive-pack fork >actual &&
+       extract_haves <actual >actual.haves &&
+       test_cmp expect actual.haves
+'
+
 test_done
index 19baec7942d2c865adb30fcf06c0d08ddb2dc63e..90a3350936adf51ebf3efaba4ebbafadf7789253 100644 (file)
@@ -1341,6 +1341,11 @@ static void fill_alternate_refs_command(struct child_process *cmd,
                argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path);
                argv_array_push(&cmd->args, "for-each-ref");
                argv_array_push(&cmd->args, "--format=%(objectname)");
+
+               if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
+                       argv_array_push(&cmd->args, "--");
+                       argv_array_split(&cmd->args, value);
+               }
        }
 
        cmd->env = local_repo_env;