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

Re: [PATCH v6 1/7] archive: optionally add "virtual" files

From
René Scharfe <l.s.r@web.de>
Date
May 26, 2022, 18:57 UTC
Message-ID
<ed95b26a-2fa3-d1f7-3142-05719a44a8f7@web.de>
In-Reply-To
<xmqqee0g1aoz.fsf@gitster.g>
Am 26.05.22 um 19:10 schrieb Junio C Hamano:
Show 19 quoted lines
> René Scharfe <l.s.r@web.de> writes:
>
>> If the prefix is applied then a prefix-less extra file can by had by
>> using --prefix= or --no-prefix for it and --prefix=... for the tree,
>> e.g.:
>>
>>    $ git archive --add-file=extra --prefix=dir/ v2.36.0
>>
>> puts "extra" at the root and the rest under "dir".  The order of
>> arguments matters here, and the default prefix is the empty string.
>
> This was the part of the design for the original "--add-file" that I
> was moderately unhappy with.  If "--add-file" were the only feature
> that used "--prefix", I wouldn't have been unhappy, but this rule:
>
>         The value of "--prefix" most recently seen at the point of
>         "--add-file" is prepended.  (By the way, it is not clearly
>         documented what happens when you give multiple prefix and
>         when you give prefix before or after add-file)
Regarding documentation: I wonder what's missing; a guess is below.
Show 22 quoted lines
>
> makes the original use of "--prefix":
>
> 	The value given to "--prefix" is prepended to each filename
> 	in the archive.  (IOW "git archive --prefix=git-2.36.0/
> 	v2.36.0" is a way to prefix each and every path in the
> 	tree-ish with the given prefix)
>
> confusing.  Does
>
> 	git archive --prefix=bonus-files/ --add-file=extra v2.36.0
>
> place the main part of the archive also in bonus-files/ or at the
> top level?  One reasonable interpretation is "yes", if we imagine
> that each invocation of --add-file will consume and reset the prefix.
> Another reasonable interpretation is "no", if we imagine that the
> prefix last specified will stay around and equally affect both extra
> ones and main part of the archive.
>
> Unfortunately what the implmentation does is the latter, and those
> who want to put the main part of the archive at the top-level must
> add "--prefix=''" at the end (before the tree-ish).

A one-shot --prefix would be surprising -- usually options keep their value until they are specified again with a different value or negated (--no-...). That surprise could be documented away by using a different name like --next-prefix or --single-use-prefix. But a sub-option to a single option like that would probably be better baked into that option, e.g. allow --add-file=<path_in_archive>:<path_in_fs>.

Show 13 quoted lines
>
> Because of this potential for confusion ...
>
>> So extra files can be put anywhere even if --prefix is honored.
>>
>> Keeping the whole path from --add-virtual-file makes sense to me; I
>> slightly prefer applying --prefix on top of that for consistency.
>
> ... I was hoping that we can releave users from having to worry
> about the interaction between "prefix" and contents coming from
> outside the tree-ish by ignoring the "prefix".
>
> But either is fine by me.

The unusual thing about the current --prefix implementation is that its current value is captured along the way instead of just using its right-most value. Not sure ignoring it for one of the three archive content sources helps. (Really, it's hard for me to put me in the shoes of someone who doesn't know how these options are supposed to be used.)

--- >8 ---
Subject: [PATCH] archive: improve documentation of --prefix

Document the interaction between --add-file and --prefix by giving an example.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 Documentation/git-archive.txt | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.txt
index bc4e76a783..10a48ab5f8 100644
--- a/Documentation/git-archive.txt
+++ b/Documentation/git-archive.txt
@@ -49,7 +49,9 @@ OPTIONS
 	Report progress to stderr.

 --prefix=<prefix>/::
-	Prepend <prefix>/ to each filename in the archive.
+	Prepend <prefix>/ to each filename in the archive.  Can be
+	specified multiple times; the last one seen when reading from
+	left to right is applied.

 -o <file>::
 --output=<file>::
@@ -58,8 +60,8 @@ OPTIONS
 --add-file=<file>::
 	Add a non-tracked file to the archive.  Can be repeated to add
 	multiple files.  The path of the file in the archive is built
-	by concatenating the value for `--prefix` (if any) and the
-	basename of <file>.
+	by concatenating the current value for `--prefix` (if any) and
+	the basename of <file>.

 --worktree-attributes::
 	Look for attributes in .gitattributes files in the working tree
@@ -194,6 +196,12 @@ EXAMPLES
 	commit on the current branch. Note that the output format is
 	inferred by the extension of the output file.

+`git archive -o latest.tar --prefix=build/ --add-file=configure --prefix= HEAD`::
+
+	Creates a tar archive that contains the contents of the latest
+	commit on the current branch with no prefix and the untracked
+	file 'configure' with the prefix 'build/'.
+
 `git config tar.tar.xz.command "xz -c"`::

 	Configure a "tar.xz" format for making LZMA-compressed tarfiles.
--
2.35.3
Previous: Junio C HamanoNext: Junio C Hamano
Message 108 of 140 in “scalar: implement the subcommand "diagnose"”
  1. 0/5 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, Jan 26, 2022
  2. 1/5 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, Jan 26, 2022
  3. René ScharfeJan 26, 2022
  4. Taylor BlauJan 26, 2022
  5. Johannes SchindelinFeb 6, 2022
  6. Elijah NewrenJan 27, 2022
  7. 2/5 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, Jan 26, 2022
  8. 3/5 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, Jan 26, 2022
  9. Taylor BlauJan 26, 2022
  10. Derrick StoleeJan 27, 2022
  11. Johannes SchindelinFeb 6, 2022
  12. 4/5 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, Jan 26, 2022
  13. Taylor BlauJan 26, 2022
  14. Derrick StoleeJan 27, 2022
  15. Elijah NewrenJan 27, 2022
  16. Johannes SchindelinFeb 6, 2022
  17. 5/5 scalar diagnose: show a spinner while staging contentJohannes Schindelin via GitGitGadget, Jan 26, 2022
  18. Derrick StoleeJan 27, 2022
  19. Johannes SchindelinFeb 6, 2022
  20. 0/6 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, Feb 6, 2022
  21. 2/6 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, Feb 6, 2022
  22. 1/6 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, Feb 6, 2022
  23. René ScharfeFeb 7, 2022
  24. Junio C HamanoFeb 7, 2022
  25. Johannes SchindelinFeb 8, 2022
  26. Junio C HamanoFeb 8, 2022
  27. René ScharfeFeb 8, 2022
  28. Junio C HamanoFeb 9, 2022
  29. René ScharfeFeb 10, 2022
  30. Junio C HamanoFeb 10, 2022
  31. René ScharfeFeb 11, 2022
  32. Junio C HamanoFeb 11, 2022
  33. René ScharfeFeb 12, 2022
  34. Junio C HamanoFeb 13, 2022
  35. René ScharfeFeb 13, 2022
  36. Junio C HamanoFeb 14, 2022
  37. Johannes SchindelinFeb 8, 2022
  38. 3/6 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, Feb 6, 2022
  39. René ScharfeFeb 7, 2022
  40. Johannes SchindelinFeb 8, 2022
  41. 4/6 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, Feb 6, 2022
  42. 5/6 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, Feb 6, 2022
  43. 6/6 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, Feb 6, 2022
  44. 0/7 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, May 4, 2022
  45. 2/7 archive --add-file-with-contents: allow paths containing colonsJohannes Schindelin via GitGitGadget, May 4, 2022
  46. Elijah NewrenMay 7, 2022
  47. Johannes SchindelinMay 9, 2022
  48. 1/7 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, May 4, 2022
  49. 3/7 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, May 4, 2022
  50. 5/7 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, May 4, 2022
  51. 7/7 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, May 4, 2022
  52. 6/7 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, May 4, 2022
  53. 4/7 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, May 4, 2022
  54. Elijah NewrenMay 7, 2022
  55. 0/7 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, May 10, 2022
  56. 2/7 archive --add-file-with-contents: allow paths containing colonsJohannes Schindelin via GitGitGadget, May 10, 2022
  57. Junio C HamanoMay 10, 2022
  58. rsbecker@nexbridge.comMay 10, 2022
  59. Johannes SchindelinMay 19, 2022
  60. Johannes SchindelinMay 19, 2022
  61. Junio C HamanoMay 19, 2022
  62. 3/7 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, May 10, 2022
  63. Ævar Arnfjörð BjarmasonMay 17, 2022
  64. Junio C HamanoMay 18, 2022
  65. Ævar Arnfjörð BjarmasonMay 20, 2022
  66. Johannes SchindelinMay 20, 2022
  67. Ævar Arnfjörð BjarmasonMay 21, 2022
  68. Junio C HamanoMay 22, 2022
  69. Johannes SchindelinMay 24, 2022
  70. Ævar Arnfjörð BjarmasonMay 24, 2022
  71. Junio C HamanoMay 24, 2022
  72. Johannes SchindelinMay 25, 2022
  73. 4/7 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, May 10, 2022
  74. Ævar Arnfjörð BjarmasonMay 17, 2022
  75. 6/7 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, May 10, 2022
  76. 5/7 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, May 10, 2022
  77. 1/7 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, May 10, 2022
  78. Junio C HamanoMay 10, 2022
  79. rsbecker@nexbridge.comMay 10, 2022
  80. Junio C HamanoMay 10, 2022
  81. René ScharfeMay 11, 2022
  82. Junio C HamanoMay 11, 2022
  83. René ScharfeMay 12, 2022
  84. Junio C HamanoMay 12, 2022
  85. Junio C HamanoMay 12, 2022
  86. René ScharfeMay 14, 2022
  87. fixup! archive: optionally add "virtual" filesJunio C Hamano, May 12, 2022
  88. 7/7 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, May 10, 2022
  89. Ævar Arnfjörð BjarmasonMay 17, 2022
  90. rsbecker@nexbridge.comMay 17, 2022
  91. Johannes SchindelinMay 19, 2022
  92. 0/7 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, May 19, 2022
  93. 1/7 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, May 19, 2022
  94. René ScharfeMay 20, 2022
  95. Junio C HamanoMay 20, 2022
  96. 2/7 archive --add-file-with-contents: allow paths containing colonsJohannes Schindelin via GitGitGadget, May 19, 2022
  97. 5/7 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, May 19, 2022
  98. 4/7 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, May 19, 2022
  99. 3/7 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, May 19, 2022
  100. 6/7 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, May 19, 2022
  101. 7/7 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, May 19, 2022
  102. Junio C HamanoMay 19, 2022
  103. 0/7 scalar: implement the subcommand "diagnose"Johannes Schindelin via GitGitGadget, May 21, 2022
  104. 1/7 archive: optionally add "virtual" filesJohannes Schindelin via GitGitGadget, May 21, 2022
  105. Junio C HamanoMay 25, 2022
  106. René ScharfeMay 26, 2022
  107. Junio C HamanoMay 26, 2022
  108. René ScharfeMay 26, 2022
  109. Junio C HamanoMay 26, 2022
  110. René ScharfeMay 27, 2022
  111. Junio C HamanoMay 27, 2022
  112. René ScharfeMay 28, 2022
  113. 3/7 scalar: validate the optional enlistment argumentJohannes Schindelin via GitGitGadget, May 21, 2022
  114. 2/7 archive --add-virtual-file: allow paths containing colonsJohannes Schindelin via GitGitGadget, May 21, 2022
  115. Junio C HamanoMay 25, 2022
  116. Junio C HamanoMay 25, 2022
  117. Junio C HamanoMay 25, 2022
  118. 6/7 scalar: teach `diagnose` to gather packfile infoMatthew John Cheetham via GitGitGadget, May 21, 2022
  119. 4/7 Implement `scalar diagnose`Johannes Schindelin via GitGitGadget, May 21, 2022
  120. 5/7 scalar diagnose: include disk space informationJohannes Schindelin via GitGitGadget, May 21, 2022
  121. 7/7 scalar: teach `diagnose` to gather loose objects informationMatthew John Cheetham via GitGitGadget, May 21, 2022
  122. 0/7 js/scalar-diagnose rebasedJunio C Hamano, May 28, 2022
  123. 1/7 archive: optionally add "virtual" filesJunio C Hamano, May 28, 2022
  124. 3/7 scalar: validate the optional enlistment argumentJunio C Hamano, May 28, 2022
  125. 2/7 archive --add-virtual-file: allow paths containing colonsJunio C Hamano, May 28, 2022
  126. Adam DinwoodieJun 15, 2022
  127. Junio C HamanoJun 15, 2022
  128. Adam DinwoodieJun 15, 2022
  129. Johannes SchindelinJun 18, 2022
  130. Junio C HamanoJun 18, 2022
  131. Adam DinwoodieJun 20, 2022
  132. 4/7 scalar: implement `scalar diagnose`Junio C Hamano, May 28, 2022
  133. Ævar Arnfjörð BjarmasonJun 10, 2022
  134. Junio C HamanoJun 10, 2022
  135. Ævar Arnfjörð BjarmasonJun 10, 2022
  136. 6/7 scalar: teach `diagnose` to gather packfile infoJunio C Hamano, May 28, 2022
  137. 7/7 scalar: teach `diagnose` to gather loose objects informationJunio C Hamano, May 28, 2022
  138. 5/7 scalar diagnose: include disk space informationJunio C Hamano, May 28, 2022
  139. Johannes SchindelinMay 30, 2022
  140. Junio C HamanoMay 30, 2022

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.