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

Re: [PATCH 2/2] pretty: add merge and exclude options to %(describe)

From
René Scharfe. <l.s.r@web.de>
Date
Mar 6, 2021, 16:18 UTC
Message-ID
<a28592c5-4a70-1ea8-fd73-959e28b4278d@web.de>
In-Reply-To
<30f78fce-fe1a-0a50-fa8c-e6fe14a03bf3@web.de>
Am 02.03.21 um 17:00 schrieb René Scharfe.:
Show 13 quoted lines
> Am 28.02.21 um 16:41 schrieb Ævar Arnfjörð Bjarmason:
>> Instead of taking the trouble of putting a limit in the
>> pretty_print_context so we don't call it N times for the same commit,
>> why not just put the strbuf with the result in that same struct?
>>
>> Then you can have it millions of times, and it won't be any more
>> expensive than the other existing %(format) specifiers (actually cheaper
>> than most).
>
> Each %(describe) placeholder can have a unique set of match or exclude
> arguments.  Caching them all would increase the strength of a DoS
> attack.  Caching a few of them would be OK, but is ineffective in
> reducing the strength of the attack.

The script at the bottom creates archives that illustrate the issue. On a repo generated with parameter 10 (10 files with 10 $Format:...$ with 10 %(describe) placeholders, so 1000 total), I get the following number with v2.30.1, which ignores %(describe):

Benchmark #1: git archive HEAD
  Time (mean ± σ):       2.2 ms ±   0.2 ms    [User: 0.9 ms, System: 1.0 ms]
  Range (min … max):     1.8 ms …   2.8 ms    705 runs
  Warning: Command took less than 5 ms to complete. Results might be inaccurate.

The version in next expands all placeholders and takes three orders of magnitude longer:

Benchmark #1: git archive HEAD
  Time (mean ± σ):      2.300 s ±  0.003 s    [User: 819.0 ms, System: 1200.0 ms]
  Range (min … max):    2.293 s …  2.305 s    10 runs

The proposed patch to expand only a single placeholder gets the runtime back under control:

Benchmark #1: git archive HEAD
  Time (mean ± σ):       4.7 ms ±   0.3 ms    [User: 1.8 ms, System: 2.2 ms]
  Range (min … max):     4.2 ms …   7.0 ms    451 runs
  Warning: Command took less than 5 ms to complete. Results might be inaccurate.

Using parameter 100 takes about a second to create the repo, but the git archive version in next already needs longer to tar it up than I'm willing to wait.

#!/bin/sh
n=$1
mkdir $n
cd $n
git init
for i in $(seq $n)
do
	awk -v i=$i -v n=$n 'END {
		for (j = 0; j < n; j++) {
			print "$Format:"
			for (k = 0; k < n; k++) {
				print "%(describe:exclude=x-" i "-" j "-" k ")"
			}
			print "$"
		}
	}' </dev/null >"file$i"
done
git add file*
echo "file* export-subst" >.gitattributes
git add .gitattributes
git commit -m initial
for tagno in $(seq $n)
do
	git tag -m "$tagno" "tag$tagno"
done
Previous: René Scharfe.Next: Eli Schwartz
Message 14 of 27 in “gitattributes export-subst and software versioning”
  1. Eli SchwartzJan 25, 2021
  2. René ScharfeFeb 8, 2021
  3. Junio C HamanoFeb 8, 2021
  4. Eli SchwartzFeb 9, 2021
  5. Junio C HamanoFeb 9, 2021
  6. René ScharfeFeb 14, 2021
  7. René ScharfeFeb 14, 2021
  8. 1/2 pretty: add %(describe)René Scharfe, Feb 14, 2021
  9. 2/2 pretty: add merge and exclude options to %(describe)René Scharfe., Feb 14, 2021
  10. Jeff KingFeb 17, 2021
  11. René Scharfe.Feb 28, 2021
  12. Ævar Arnfjörð BjarmasonFeb 28, 2021
  13. René Scharfe.Mar 2, 2021
  14. René Scharfe.Mar 6, 2021
  15. Eli SchwartzFeb 16, 2021
  16. Ævar Arnfjörð BjarmasonFeb 16, 2021
  17. René Scharfe.Feb 16, 2021
  18. Junio C HamanoFeb 16, 2021
  19. Ævar Arnfjörð BjarmasonFeb 17, 2021
  20. René Scharfe.Feb 28, 2021
  21. Ævar Arnfjörð BjarmasonFeb 17, 2021
  22. Junio C HamanoFeb 17, 2021
  23. René Scharfe.Feb 28, 2021
  24. René Scharfe.Feb 28, 2021
  25. René Scharfe.Mar 2, 2021
  26. René Scharfe.Mar 2, 2021
  27. René Scharfe.Mar 2, 2021

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.