diff mbox series

[4/4] blame: test the -b option, use blank oid for boundary commits.

Message ID 20200525215751.1735-5-philipoakley@iee.email (mailing list archive)
State New, archived
Headers show
Series Selectively show only blamed limes | expand

Commit Message

Philip Oakley May 25, 2020, 9:57 p.m. UTC
4c10a5caa7 (blame: -b (blame.blankboundary) and --root (blame.showroot),
2006-12-18) introduced the -b option. Add a test.

The sed script removes the last hex digit from boundary commit oids
'^hexx msg' -> '^hex  msg' until all leading hex's are gone, finally
removing the boundary commit marker.

Signed-off-by: Philip Oakley <philipoakley@iee.email>
---
 t/t8002-blame.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Jeff King May 27, 2020, 7:30 a.m. UTC | #1
On Mon, May 25, 2020 at 10:57:51PM +0100, Philip Oakley wrote:

> The sed script removes the last hex digit from boundary commit oids
> '^hexx msg' -> '^hex  msg' until all leading hex's are gone, finally
> removing the boundary commit marker.

Thanks for documenting this, as the sed was rather hard to read:

> +test_expect_success 'test -b option, blank oid for boundary commits' '
> +	git blame -b branch1.. -- file >actual &&
> +	git blame branch1.. -- file >full &&
> +	sed -e "/^\^/{
> +		:loop;
> +		s/^\(\^[0-9a-f]*\)[0-9a-f] \(.*\)/\1  \2/g;
> +		tloop;
> +		s/^\^/ /;
> +	}" full >expected &&

I wonder if we can make it simpler.

In perl I'd probably just replace the whole string with the equivalent
number of spaces, like:

  perl -pe 's/^\^\S+/" " x length($&)/e'

but I suppose some would consider that pretty magical, too. It might be
simpler still to just avoid testing leading whitespace:

   sed 's/^\^[0-9a-f]* *//' <full >expected &&
   sed 's/^ *//' <actual >actual.stripped &&
   test_cmp expected actual.stripped

but perhaps the indentation is a useful part of what we're testing.

-Peff
Philip Oakley May 27, 2020, 10:52 a.m. UTC | #2
On 27/05/2020 08:30, Jeff King wrote:
> On Mon, May 25, 2020 at 10:57:51PM +0100, Philip Oakley wrote:
>
>> The sed script removes the last hex digit from boundary commit oids
>> '^hexx msg' -> '^hex  msg' until all leading hex's are gone, finally
>> removing the boundary commit marker.
> Thanks for documenting this, as the sed was rather hard to read:
It was hard to write as well;-) lots of dead ends in the sed language.
>
>> +test_expect_success 'test -b option, blank oid for boundary commits' '
>> +	git blame -b branch1.. -- file >actual &&
>> +	git blame branch1.. -- file >full &&
>> +	sed -e "/^\^/{
>> +		:loop;
>> +		s/^\(\^[0-9a-f]*\)[0-9a-f] \(.*\)/\1  \2/g;
>> +		tloop;
>> +		s/^\^/ /;
>> +	}" full >expected &&
> I wonder if we can make it simpler.
>
> In perl I'd probably just replace the whole string with the equivalent
> number of spaces, like:
>
>   perl -pe 's/^\^\S+/" " x length($&)/e'
I'm not a perl person, so I thought sed might be an easy target but ...
it wasn't.
>
> but I suppose some would consider that pretty magical, too. 
I'd need to look it up!

> It might be
> simpler still to just avoid testing leading whitespace:
>
>    sed 's/^\^[0-9a-f]* *//' <full >expected &&
>    sed 's/^ *//' <actual >actual.stripped &&
>    test_cmp expected actual.stripped
>
> but perhaps the indentation is a useful part of what we're testing.

The code does take care to exactly match indentation, so I felt that the
indentation should be tested.

Philip
diff mbox series

Patch

diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh
index d4877c7c54..de0f81abe9 100755
--- a/t/t8002-blame.sh
+++ b/t/t8002-blame.sh
@@ -129,4 +129,16 @@  test_expect_success 'test --blame-only, exclude boundary commits' '
 	test_cmp expected actual
 '
 
+test_expect_success 'test -b option, blank oid for boundary commits' '
+	git blame -b branch1.. -- file >actual &&
+	git blame branch1.. -- file >full &&
+	sed -e "/^\^/{
+		:loop;
+		s/^\(\^[0-9a-f]*\)[0-9a-f] \(.*\)/\1  \2/g;
+		tloop;
+		s/^\^/ /;
+	}" full >expected &&
+	test_cmp expected actual
+'
+
 test_done