Re: [PATCH 10/22] mailmap tests: get rid of overly complex blame fuzzing
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 14, 2021, 20:21 UTC
- Message-ID
- <xmqqbldrxo9o.fsf@gitster.c.googlers.com>
- In-Reply-To
- <xmqqlfcx239z.fsf@gitster.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 23 quoted lines
> Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > >> + 6 6 1 >> + Santa Claus >> + 7 7 1 >> + CTO >> + EOF >> + >> + git blame --porcelain one >actual.blame && >> + grep -E \ >> + -e "[0-9]+ [0-9]+ [0-9]+$" \ >> + -e "^author .*$" \ >> + actual.blame >actual.grep && >> + cut -d " " -f2-4 <actual.grep >actual.fuzz && > > An approach along the lines of ... > > NUM="[0-9][0-9]*" > sed -n -e "s/^author //p" \ > -e "s/^$OID_REGEX \($NUM $NUM $NUM\)$/\1/p" > > ... would allow you to drop "cut" and also not assume that names do > not have more than 3 tokens.
Trying to lead by example..., here is the suggestion in a follow-up patch form that can be applied on top of the series.
----- >8 ----- ----- >8 ----- ----- >8 ----- ----- >8 ----- ----- >8 ----- Subject: [PATCH] t4203: make blame output massaging more robust
In the "git blame --porcelain" output, lines that ends with three integers may not be the line that shows a commit object with line numbers and block length (the contents from the blamed file or the summary field can have a line that happens to match). Also, the names of the author may have more than three SP separated tokens ("git blame -L242,+1 cf6de18aabf7 Documentation/SubmittingPatches" gives an example). The existing "grep -E | cut" pipeline is a bit too loose on these two points.
While they can be assumed on the test data, it is not so hard to use the right pattern from the documented format, so let's do so.
Signed-off-by: Junio C Hamano <gitster@pobox.com> --- t/t4203-mailmap.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git c/t/t4203-mailmap.sh i/t/t4203-mailmap.sh index 89cb300f28..d4a6e73736 100755 --- c/t/t4203-mailmap.sh +++ i/t/t4203-mailmap.sh @@ -739,11 +739,11 @@ test_expect_success 'Blame --porcelain output (complex mapping)' ' EOF git blame --porcelain one >actual.blame && - grep -E \ - -e "[0-9]+ [0-9]+ [0-9]+$" \ - -e "^author .*$" \ - actual.blame >actual.grep && - cut -d " " -f2-4 <actual.grep >actual.fuzz && + + NUM="[0-9][0-9]*" && + sed -n <actual.blame >actual.fuzz \ + -e "s/^author //p" \ + -e "s/^$OID_REGEX \\($NUM $NUM $NUM\\)$/\\1/p" && test_cmp expect actual.fuzz '