git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v4 0/4] Filter alternate references

From
Taylor Blau <me@ttaylorr.com>
Date
Oct 2, 2018, 02:23 UTC
Message-ID
<cover.1538446826.git.me@ttaylorr.com>
In-Reply-To
<cover.1537466087.git.me@ttaylorr.com>
Hi,

Attached is the fourth re-roll of a series to teach 'core.alternateRefsCommand' and 'core.alternateRefsPrefixes' to filter refs from an alternate from being visible to the fork. This is done in order to optimize a case described in patch [3/4].

As always, a range-diff is included below, showing that not much has changed of significance since last round. I mostly focused my efforts on taking Peff's suggestion towards a more straightforward implementation of the test setup.

Some extra documentation was written and a couple of commit messages amended, but no C code has changed since the v2.

Thanks again for all of your review.

Thanks, Taylor

Jeff King (1):
  transport: drop refnames from for_each_alternate_ref
Taylor Blau (3):
  transport.c: extract 'fill_alternate_refs_command'
  transport.c: introduce core.alternateRefsCommand
  transport.c: introduce core.alternateRefsPrefixes
 Documentation/config.txt           | 23 +++++++++++++++++
 builtin/receive-pack.c             |  3 +--
 fetch-pack.c                       |  3 +--
 t/t5410-receive-pack-alternates.sh | 41 ++++++++++++++++++++++++++++++
 transport.c                        | 38 +++++++++++++++++++++------
 transport.h                        |  2 +-
 6 files changed, 97 insertions(+), 13 deletions(-)
 create mode 100755 t/t5410-receive-pack-alternates.sh
Range-diff against v3:
1:  037273dab0 ! 1:  491f258f50 transport: drop refnames from for_each_alternate_ref
    @@ -14,6 +14,7 @@
         bare minimum.
         Signed-off-by: Jeff King <peff@peff.net>
    +    Signed-off-by: Taylor Blau <me@ttaylorr.com>
      diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
      --- a/builtin/receive-pack.c
2:  9479470cb1 = 2:  6119de15f2 transport.c: extract 'fill_alternate_refs_command'
3:  2dbcd54190 ! 3:  aadb27c010 transport.c: introduce core.alternateRefsCommand
    @@ -24,9 +24,7 @@
         Let the repository that has alternates configure this command to avoid
         trusting the alternate to provide us a safe command to run in the shell.
    -    To behave differently on each alternate (e.g., only list tags from
    -    alternate A, only heads from B) provide the path of the alternate as the
    -    first argument.
    +    To find the alternate, pass its absolute path as the first argument.
         Signed-off-by: Taylor Blau <me@ttaylorr.com>
    @@ -40,51 +38,41 @@
     +core.alternateRefsCommand::
     +	When advertising tips of available history from an alternate, use the shell to
     +	execute the specified command instead of linkgit:git-for-each-ref[1]. The
    -+	first argument is the absolute path of the alternate. Output must be of the
    -+	form: `%(objectname)`, where multiple tips are separated by newlines.
    ++	first argument is the absolute path of the alternate. Output must contain one
    ++	hex object id per line (i.e., the same as produce by `git for-each-ref
    ++	--format='%(objectname)'`).
     ++
     +This is useful when a repository only wishes to advertise some of its
    -+alternate's references as ".have"'s. For example, to only advertise branch
    ++alternate's references as `.have`'s. For example, to only advertise branch
     +heads, configure `core.alternateRefsCommand` to the path of a script which runs
     +`git --git-dir="$1" for-each-ref --format='%(objectname)' refs/heads`.
    +++
    ++Note that the configured value is executed in a shell, and thus
    ++linkgit:git-for-each-ref[1] by itself does not work, as scripts have to handle
    ++the path argument specially.
     +
      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
    - diff --git a/t/t5410-receive-pack.sh b/t/t5410-receive-pack.sh
    + diff --git a/t/t5410-receive-pack-alternates.sh b/t/t5410-receive-pack-alternates.sh
      new file mode 100755
      --- /dev/null
    - +++ b/t/t5410-receive-pack.sh
    + +++ b/t/t5410-receive-pack-alternates.sh
     @@
     +#!/bin/sh
     +
    -+test_description='git receive-pack test'
    ++test_description='git receive-pack with alternate ref filtering'
     +
     +. ./test-lib.sh
     +
     +test_expect_success 'setup' '
    -+	test_commit one &&
    -+	git update-ref refs/heads/a HEAD &&
    -+	test_commit two &&
    -+	git update-ref refs/heads/b HEAD &&
    -+	test_commit three &&
    -+	git update-ref refs/heads/c HEAD &&
    -+	git clone --bare . fork &&
    -+	git clone fork pusher &&
    -+	(
    -+		cd fork &&
    -+		git update-ref --stdin <<-\EOF &&
    -+		delete refs/heads/a
    -+		delete refs/heads/b
    -+		delete refs/heads/c
    -+		delete refs/heads/master
    -+		delete refs/tags/one
    -+		delete refs/tags/two
    -+		delete refs/tags/three
    -+		EOF
    -+		echo "../../.git/objects" >objects/info/alternates
    -+	)
    ++	test_commit base &&
    ++	git clone -s --bare . fork &&
    ++	git checkout -b public/branch master &&
    ++	test_commit public &&
    ++	git checkout -b private/branch master &&
    ++	test_commit private
     +'
     +
     +extract_haves () {
    @@ -95,11 +83,10 @@
     +	write_script fork/alternate-refs <<-\EOF &&
     +		git --git-dir="$1" for-each-ref \
     +			--format="%(objectname)" \
    -+			refs/heads/a \
    -+			refs/heads/c
    ++			refs/heads/public/
     +	EOF
     +	test_config -C fork core.alternateRefsCommand alternate-refs &&
    -+	git rev-parse a c >expect &&
    ++	git rev-parse public/branch >expect &&
     +	printf "0000" | git receive-pack fork >actual &&
     +	extract_haves <actual >actual.haves &&
     +	test_cmp expect actual.haves
4:  48eb774c9e ! 4:  0d3521e92a transport.c: introduce core.alternateRefsPrefixes
    @@ -12,7 +12,8 @@
         'core.alternateRefsCommand' would have to do:
           $ git config core.alternateRefsCommand ' \
    -          git -C "$1" for-each-ref refs/tags --format="%(objectname)"'
    +          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
    @@ -38,8 +39,8 @@
      --- a/Documentation/config.txt
      +++ b/Documentation/config.txt
     @@
    - heads, configure `core.alternateRefsCommand` to the path of a script which runs
    - `git --git-dir="$1" for-each-ref --format='%(objectname)' refs/heads`.
    + linkgit:git-for-each-ref[1] by itself does not work, as scripts have to handle
    + the path argument specially.
     +core.alternateRefsPrefixes::
     +	When listing references from an alternate, list only references that begin
    @@ -52,16 +53,16 @@
      	If true this repository is assumed to be 'bare' and has no
      	working directory associated with it.  If this is the case a
    - diff --git a/t/t5410-receive-pack.sh b/t/t5410-receive-pack.sh
    - --- a/t/t5410-receive-pack.sh
    - +++ b/t/t5410-receive-pack.sh
    + diff --git a/t/t5410-receive-pack-alternates.sh b/t/t5410-receive-pack-alternates.sh
    + --- a/t/t5410-receive-pack-alternates.sh
    + +++ b/t/t5410-receive-pack-alternates.sh
     @@
      	test_cmp expect actual.haves
      '
     +test_expect_success 'with core.alternateRefsPrefixes' '
    -+	test_config -C fork core.alternateRefsPrefixes "refs/tags" &&
    -+	git rev-parse one three two >expect &&
    ++	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
--
2.19.0.221.g150f307af
Previous: Taylor BlauNext: Taylor Blau
Message 79 of 94 in “Filter alternate references”
  1. 0/3 Filter alternate referencesTaylor Blau, Sep 20, 2018
  2. 1/3 transport.c: extract 'fill_alternate_refs_command'Taylor Blau, Sep 20, 2018
  3. 2/3 transport.c: introduce core.alternateRefsCommandTaylor Blau, Sep 20, 2018
  4. Jeff KingSep 20, 2018
  5. Taylor BlauSep 20, 2018
  6. Jeff KingSep 20, 2018
  7. Junio C HamanoSep 21, 2018
  8. Taylor BlauSep 21, 2018
  9. Taylor BlauSep 21, 2018
  10. Junio C HamanoSep 21, 2018
  11. Taylor BlauSep 26, 2018
  12. 3/3 transport.c: introduce core.alternateRefsPrefixesTaylor Blau, Sep 20, 2018
  13. Jeff KingSep 20, 2018
  14. Taylor BlauSep 20, 2018
  15. Eric SunshineSep 21, 2018
  16. Taylor BlauSep 21, 2018
  17. Junio C HamanoSep 21, 2018
  18. Taylor BlauSep 21, 2018
  19. Junio C HamanoSep 21, 2018
  20. Stefan BellerSep 20, 2018
  21. Taylor BlauSep 20, 2018
  22. Jeff KingSep 20, 2018
  23. Jeff KingSep 20, 2018
  24. 0/3 Filter alternate referencesTaylor Blau, Sep 21, 2018
  25. 1/3 transport.c: extract 'fill_alternate_refs_command'Taylor Blau, Sep 21, 2018
  26. 2/3 transport.c: introduce core.alternateRefsCommandTaylor Blau, Sep 21, 2018
  27. Eric SunshineSep 21, 2018
  28. Taylor BlauSep 26, 2018
  29. Junio C HamanoSep 21, 2018
  30. Jeff KingSep 21, 2018
  31. Junio C HamanoSep 21, 2018
  32. Jeff KingSep 21, 2018
  33. Taylor BlauSep 26, 2018
  34. Jeff KingSep 26, 2018
  35. Eric SunshineSep 21, 2018
  36. brian m. carlsonSep 22, 2018
  37. Jeff KingSep 22, 2018
  38. brian m. carlsonSep 23, 2018
  39. Taylor BlauSep 26, 2018
  40. Jeff KingSep 26, 2018
  41. Taylor BlauSep 26, 2018
  42. Jeff KingSep 26, 2018
  43. Taylor BlauSep 28, 2018
  44. 3/3 transport.c: introduce core.alternateRefsPrefixesTaylor Blau, Sep 21, 2018
  45. Junio C HamanoSep 21, 2018
  46. Jeff KingSep 21, 2018
  47. Junio C HamanoSep 21, 2018
  48. Jeff KingSep 21, 2018
  49. Stefan BellerSep 21, 2018
  50. Junio C HamanoSep 24, 2018
  51. Jeff KingSep 24, 2018
  52. Junio C HamanoSep 24, 2018
  53. Jeff KingSep 24, 2018
  54. Jeff KingSep 24, 2018
  55. Junio C HamanoSep 24, 2018
  56. Jeff KingSep 24, 2018
  57. Junio C HamanoSep 25, 2018
  58. Taylor BlauSep 25, 2018
  59. Junio C HamanoSep 25, 2018
  60. Taylor BlauSep 26, 2018
  61. Jeff KingSep 26, 2018
  62. 0/4 Filter alternate referencesTaylor Blau, Sep 28, 2018
  63. 1/4 transport: drop refnames from for_each_alternate_refJeff King, Sep 28, 2018
  64. Jeff KingSep 28, 2018
  65. Taylor BlauSep 28, 2018
  66. 2/4 transport.c: extract 'fill_alternate_refs_command'Taylor Blau, Sep 28, 2018
  67. Jeff KingSep 28, 2018
  68. 3/4 transport.c: introduce core.alternateRefsCommandTaylor Blau, Sep 28, 2018
  69. Jeff KingSep 28, 2018
  70. Taylor BlauSep 28, 2018
  71. Jeff KingSep 29, 2018
  72. Taylor BlauOct 2, 2018
  73. 4/4 transport.c: introduce core.alternateRefsPrefixesTaylor Blau, Sep 28, 2018
  74. Jeff KingSep 28, 2018
  75. Taylor BlauSep 28, 2018
  76. Jeff KingSep 29, 2018
  77. Taylor BlauOct 2, 2018
  78. Taylor BlauOct 2, 2018
  79. 0/4 Filter alternate referencesTaylor Blau, Oct 2, 2018
  80. 1/4 transport: drop refnames from for_each_alternate_refTaylor Blau, Oct 2, 2018
  81. 3/4 transport.c: introduce core.alternateRefsCommandTaylor Blau, Oct 2, 2018
  82. Jeff KingOct 2, 2018
  83. Taylor BlauOct 4, 2018
  84. 2/4 transport.c: extract 'fill_alternate_refs_command'Taylor Blau, Oct 2, 2018
  85. 4/4 transport.c: introduce core.alternateRefsPrefixesTaylor Blau, Oct 2, 2018
  86. Ramsay JonesOct 2, 2018
  87. 4/4 transport.c: introduce core.alternateRefsPrefixesTaylor Blau, Oct 2, 2018
  88. 0/4 Filter alternate referencesTaylor Blau, Oct 8, 2018
  89. 1/4 transport: drop refnames from for_each_alternate_refTaylor Blau, Oct 8, 2018
  90. 2/4 transport.c: extract 'fill_alternate_refs_command'Taylor Blau, Oct 8, 2018
  91. 3/4 transport.c: introduce core.alternateRefsCommandTaylor Blau, Oct 8, 2018
  92. 4/4 transport.c: introduce core.alternateRefsPrefixesTaylor Blau, Oct 8, 2018
  93. Jeff KingOct 9, 2018
  94. Taylor BlauOct 9, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.