threads / patch / 42971

patch, 3 partsdiff-highlight: add support for git log --graph output.

Subject: [PATCH 0/3] diff-highlight: add support for git log --graph output.

## tl;dr

24 messages between Jul 30, 2016 and Aug 24, 2016. Diffs are folded; open one to read it.

replies: 23people: 5as markdown or json

Brian Henderson· Jul 30, 2016, 15:11 UTC · lore

(resending as thread instead of attachments take 3 I realized that I was adding the To field only to the cover letter and I wasn't catching that git-send-email wasn't adding it to the other patches. Apologies.)

Hi, I've been working with Jeff King on this patch, but he encouraged me to email the list.

I recently learned about the diff-highlight tool, and find it very helpful, however, I frequently use the --graph option to git log which breaks the tool. This patch looks to fix this.

I wanted to try and add some tests as well, but I was unsure what number to pick for the second digit. As there were limited tests in the contrib directory (only t93xx and one t7900) I just chose the next number in the 9xxx range. Please let me know if I need to change it.

I'm also not super happy about my test case for the graph option. If anyone has any better ideas, please let me know!

Brian Henderson (3):
  diff-highlight: add some tests.
  diff-highlight: add failing test for handling --graph output.
  diff-highlight: add support for --graph output.
 contrib/diff-highlight/Makefile                  |   5 +
 contrib/diff-highlight/diff-highlight            |  13 +--
 contrib/diff-highlight/t/Makefile                |  19 ++++
 contrib/diff-highlight/t/t9400-diff-highlight.sh |  76 ++++++++++++++++
 contrib/diff-highlight/t/test-diff-highlight.sh  | 111 +++++++++++++++++++++++
 5 files changed, 218 insertions(+), 6 deletions(-)
 create mode 100644 contrib/diff-highlight/Makefile
 create mode 100644 contrib/diff-highlight/t/Makefile
 create mode 100644 contrib/diff-highlight/t/t9400-diff-highlight.sh
 create mode 100644 contrib/diff-highlight/t/test-diff-highlight.sh
-- 
2.9.0
Brian Henderson· Jul 30, 2016, 15:11 UTC · re: Brian Henderson · lore

[PATCH 3/3] diff-highlight: add support for --graph output.

---
 contrib/diff-highlight/diff-highlight | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
Show changes to contrib/diff-highlight/diff-highlight +7 −6
diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight
index ffefc31..ec31356 100755
--- a/contrib/diff-highlight/diff-highlight
+++ b/contrib/diff-highlight/diff-highlight
@@ -20,6 +20,7 @@ my @NEW_HIGHLIGHT = (
 my $RESET = "\x1b[m";
 my $COLOR = qr/\x1b\[[0-9;]*m/;
 my $BORING = qr/$COLOR|\s/;
+my $GRAPH = qr/$COLOR?\|$COLOR?\s+/;
 
 my @removed;
 my @added;
@@ -32,12 +33,12 @@ $SIG{PIPE} = 'DEFAULT';
 while (<>) {
 	if (!$in_hunk) {
 		print;
-		$in_hunk = /^$COLOR*\@/;
+		$in_hunk = /^$GRAPH*$COLOR*\@/;
 	}
-	elsif (/^$COLOR*-/) {
+	elsif (/^$GRAPH*$COLOR*-/) {
 		push @removed, $_;
 	}
-	elsif (/^$COLOR*\+/) {
+	elsif (/^$GRAPH*$COLOR*\+/) {
 		push @added, $_;
 	}
 	else {
@@ -46,7 +47,7 @@ while (<>) {
 		@added = ();
 
 		print;
-		$in_hunk = /^$COLOR*[\@ ]/;
+		$in_hunk = /^$GRAPH*$COLOR*[\@ ]/;
 	}
 
 	# Most of the time there is enough output to keep things streaming,
@@ -211,8 +212,8 @@ sub is_pair_interesting {
 	my $suffix_a = join('', @$a[($sa+1)..$#$a]);
 	my $suffix_b = join('', @$b[($sb+1)..$#$b]);
 
-	return $prefix_a !~ /^$COLOR*-$BORING*$/ ||
-	       $prefix_b !~ /^$COLOR*\+$BORING*$/ ||
+	return $prefix_a !~ /^$GRAPH*$COLOR*-$BORING*$/ ||
+	       $prefix_b !~ /^$GRAPH*$COLOR*\+$BORING*$/ ||
 	       $suffix_a !~ /^$BORING*$/ ||
 	       $suffix_b !~ /^$BORING*$/;
 }
-- 
2.9.0
Junio C Hamano· Aug 1, 2016, 17:16 UTC · re: Brian Henderson · lore

Re: [PATCH 3/3] diff-highlight: add support for --graph output.

Brian Henderson <henderson.bj@gmail.com> writes:
Show 13 quoted lines
> ---
>  contrib/diff-highlight/diff-highlight | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight
> index ffefc31..ec31356 100755
> --- a/contrib/diff-highlight/diff-highlight
> +++ b/contrib/diff-highlight/diff-highlight
> @@ -20,6 +20,7 @@ my @NEW_HIGHLIGHT = (
>  my $RESET = "\x1b[m";
>  my $COLOR = qr/\x1b\[[0-9;]*m/;
>  my $BORING = qr/$COLOR|\s/;
> +my $GRAPH = qr/$COLOR?\|$COLOR?\s+/;

I didn't read the other parts (or existing code this patch changes, for that matter) of the series, but this looks like an attempt to catch the leading "|" bar showing direct ancestry. It makes a reader wonder what happens in a mergy histroy, though.

I _think_ that the patch portion of "log -p" output would only have "|" and never "\" or "/" that are used to adjust the number of tracks to deal with forks and merges, but perhaps the fact that this code relies on that assumption deserves to be written down here as an in-code comment?

Show 38 quoted lines
>  my @removed;
>  my @added;
> @@ -32,12 +33,12 @@ $SIG{PIPE} = 'DEFAULT';
>  while (<>) {
>  	if (!$in_hunk) {
>  		print;
> -		$in_hunk = /^$COLOR*\@/;
> +		$in_hunk = /^$GRAPH*$COLOR*\@/;
>  	}
> -	elsif (/^$COLOR*-/) {
> +	elsif (/^$GRAPH*$COLOR*-/) {
>  		push @removed, $_;
>  	}
> -	elsif (/^$COLOR*\+/) {
> +	elsif (/^$GRAPH*$COLOR*\+/) {
>  		push @added, $_;
>  	}
>  	else {
> @@ -46,7 +47,7 @@ while (<>) {
>  		@added = ();
>  
>  		print;
> -		$in_hunk = /^$COLOR*[\@ ]/;
> +		$in_hunk = /^$GRAPH*$COLOR*[\@ ]/;
>  	}
>  
>  	# Most of the time there is enough output to keep things streaming,
> @@ -211,8 +212,8 @@ sub is_pair_interesting {
>  	my $suffix_a = join('', @$a[($sa+1)..$#$a]);
>  	my $suffix_b = join('', @$b[($sb+1)..$#$b]);
>  
> -	return $prefix_a !~ /^$COLOR*-$BORING*$/ ||
> -	       $prefix_b !~ /^$COLOR*\+$BORING*$/ ||
> +	return $prefix_a !~ /^$GRAPH*$COLOR*-$BORING*$/ ||
> +	       $prefix_b !~ /^$GRAPH*$COLOR*\+$BORING*$/ ||
>  	       $suffix_a !~ /^$BORING*$/ ||
>  	       $suffix_b !~ /^$BORING*$/;
>  }
Brian Henderson· Aug 4, 2016, 15:02 UTC · re: Junio C Hamano · lore

[PATCH] diff-highlight: Add comment for our assumption about --graph output.

---
 contrib/diff-highlight/diff-highlight | 3 +++
 1 file changed, 3 insertions(+)
Show changes to contrib/diff-highlight/diff-highlight +3 −0
diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight
index ec31356..9364423 100755
--- a/contrib/diff-highlight/diff-highlight
+++ b/contrib/diff-highlight/diff-highlight
@@ -20,6 +20,9 @@ my @NEW_HIGHLIGHT = (
 my $RESET = "\x1b[m";
 my $COLOR = qr/\x1b\[[0-9;]*m/;
 my $BORING = qr/$COLOR|\s/;
+
+# The patch portion of git log -p --graph should only ever have preceding | and
+# not / or \ as merge history only shows up on the commit line.
 my $GRAPH = qr/$COLOR?\|$COLOR?\s+/;
 
 my @removed;
-- 
2.9.0
Brian Henderson· Jul 30, 2016, 15:11 UTC · re: Brian Henderson · lore

[PATCH 2/3] diff-highlight: add failing test for handling --graph output.

---
 contrib/diff-highlight/t/t9400-diff-highlight.sh | 13 ++++++++
 contrib/diff-highlight/t/test-diff-highlight.sh  | 42 ++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
Show changes to 2 files +55 −0

contrib/diff-highlight/t/t9400-diff-highlight.sh, contrib/diff-highlight/t/test-diff-highlight.sh

diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
index ca7605f..2fb4869 100644
--- a/contrib/diff-highlight/t/t9400-diff-highlight.sh
+++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
@@ -60,4 +60,17 @@ test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
 
 # TODO add multi-byte test
 
+test_expect_success 'diff-highlight highlightes the beginning of a line' '
+  dh_graph_test \
+    "aaa\nbbb\nccc\n" \
+    "aaa\n0bb\nccc\n" \
+    "aaa\nb0b\nccc\n" \
+"
+ aaa
+-${CW}b${CR}bb
++${CW}0${CR}bb
+ ccc
+"
+'
+
 test_done
diff --git a/contrib/diff-highlight/t/test-diff-highlight.sh b/contrib/diff-highlight/t/test-diff-highlight.sh
index 9b26271..162a694 100644
--- a/contrib/diff-highlight/t/test-diff-highlight.sh
+++ b/contrib/diff-highlight/t/test-diff-highlight.sh
@@ -67,3 +67,45 @@ dh_commit_test() {
 
   diff commit.exp commit.act
 }
+
+dh_graph_test() {
+  local a="$1" b="$2" c="$3"
+
+  {
+    printf "$a" > file
+    git add file
+    git commit -m"Add a file"
+
+    printf "$b" > file
+    git commit -am"Update a file"
+
+    git checkout -b branch
+    printf "$c" > file
+    git commit -am"Update a file on branch"
+
+    git checkout master
+    printf "$a" > file
+    git commit -am"Update a file again"
+
+    git checkout branch
+    printf "$b" > file
+    git commit -am"Update a file similar to master"
+
+    git merge master
+    git checkout master
+    git merge branch --no-ff
+  } >/dev/null 2>&1
+
+  git log -p --graph --no-merges > graph.raw
+
+  # git log --graph orders the commits different than git log so we hack it by
+  # using sed to remove the graph part. We know from other tests, that CMD
+  # works without the graph, so there should be no diff when running it with
+  # and without.
+  < graph.raw sed -e 's"^\(*\|| \||/\)\+""' -e 's"^  ""' | $CMD > graph.exp
+  < graph.raw $CMD | sed -e 's"^\(*\|| \||/\)\+""' -e 's"^  ""' > graph.act
+
+  # ignore whitespace since we're using a hacky sed command to remove the graph
+  # parts.
+  diff -b graph.exp graph.act
+}
-- 
2.9.0
Brian Henderson· Jul 30, 2016, 15:11 UTC · re: Brian Henderson · lore

[PATCH 1/3] diff-highlight: add some tests.

---
 contrib/diff-highlight/Makefile                  |  5 ++
 contrib/diff-highlight/t/Makefile                | 19 +++++++
 contrib/diff-highlight/t/t9400-diff-highlight.sh | 63 ++++++++++++++++++++++
 contrib/diff-highlight/t/test-diff-highlight.sh  | 69 ++++++++++++++++++++++++
 4 files changed, 156 insertions(+)
 create mode 100644 contrib/diff-highlight/Makefile
 create mode 100644 contrib/diff-highlight/t/Makefile
 create mode 100644 contrib/diff-highlight/t/t9400-diff-highlight.sh
 create mode 100644 contrib/diff-highlight/t/test-diff-highlight.sh
Show changes to 4 files +156 −0

contrib/diff-highlight/Makefile, contrib/diff-highlight/t/Makefile, contrib/diff-highlight/t/t9400-diff-highlight.sh, contrib/diff-highlight/t/test-diff-highlight.sh

diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile
new file mode 100644
index 0000000..b866259
--- /dev/null
+++ b/contrib/diff-highlight/Makefile
@@ -0,0 +1,5 @@
+# nothing to build
+all:;
+
+test:
+	$(MAKE) -C t
diff --git a/contrib/diff-highlight/t/Makefile b/contrib/diff-highlight/t/Makefile
new file mode 100644
index 0000000..ac81fc0
--- /dev/null
+++ b/contrib/diff-highlight/t/Makefile
@@ -0,0 +1,19 @@
+-include ../../../config.mak.autogen
+-include ../../../config.mak
+
+T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
+
+all: test
+test: $(T)
+
+.PHONY: help clean all test $(T)
+
+help:
+	@echo 'Run "$(MAKE) test" to launch test scripts'
+	@echo 'Run "$(MAKE) clean" to remove trash folders'
+
+$(T):
+	@echo "*** $@ ***"; sh $@ $(GIT_TEST_OPTS)
+
+clean:
+	$(RM) -r 'trash directory'.*
diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
new file mode 100644
index 0000000..ca7605f
--- /dev/null
+++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+#
+# Copyright (C) 2016
+
+test_description='Test diff-highlight'
+
+. ./test-diff-highlight.sh
+. $TEST_DIRECTORY/test-lib.sh
+
+# PERL is required, but assumed to be present, although not necessarily modern
+# some tests require 5.8
+
+test_expect_success 'diff-highlight highlightes the beginning of a line' '
+  dh_test \
+    "aaa\nbbb\nccc\n" \
+    "aaa\n0bb\nccc\n" \
+"
+ aaa
+-${CW}b${CR}bb
++${CW}0${CR}bb
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight highlightes the end of a line' '
+  dh_test \
+    "aaa\nbbb\nccc\n" \
+    "aaa\nbb0\nccc\n" \
+"
+ aaa
+-bb${CW}b${CR}
++bb${CW}0${CR}
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight highlightes the middle of a line' '
+  dh_test \
+    "aaa\nbbb\nccc\n" \
+    "aaa\nb0b\nccc\n" \
+"
+ aaa
+-b${CW}b${CR}b
++b${CW}0${CR}b
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight does not highlight whole line' '
+  dh_test \
+    "aaa\nbbb\nccc\n" \
+    "aaa\n000\nccc\n"
+'
+
+test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
+  dh_test \
+    "aaa\nbbb\n" \
+    "aaa\nb0b\nccc\n"
+'
+
+# TODO add multi-byte test
+
+test_done
diff --git a/contrib/diff-highlight/t/test-diff-highlight.sh b/contrib/diff-highlight/t/test-diff-highlight.sh
new file mode 100644
index 0000000..9b26271
--- /dev/null
+++ b/contrib/diff-highlight/t/test-diff-highlight.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+#
+# Copyright (C) 2016
+
+CURR_DIR=$(pwd)
+TEST_OUTPUT_DIRECTORY=$(pwd)
+TEST_DIRECTORY="$CURR_DIR"/../../../t
+cmd=diff-highlight
+CMD="$CURR_DIR"/../$cmd
+
+CW="\033[7m"
+CR="\033[27m"
+
+export TEST_OUTPUT_DIRECTORY TEST_DIRECTORY CW CR
+
+dh_test() {
+  dh_diff_test "$@"
+  dh_commit_test "$@"
+}
+
+dh_diff_test() {
+  local a="$1" b="$2"
+
+  printf "$a" > file
+  git add file
+
+  printf "$b" > file
+
+  git diff file > diff.raw
+
+  if test "$#" = 3
+  then
+    # remove last newline
+    head -n5 diff.raw | head -c -1 > diff.act
+    printf "$3" >> diff.act
+  else
+    cat diff.raw > diff.act
+  fi
+
+  < diff.raw $CMD > diff.exp
+
+  diff diff.exp diff.act
+}
+
+dh_commit_test() {
+  local a="$1" b="$2"
+
+  printf "$a" > file
+  git add file
+  git commit -m"Add a file" >/dev/null
+
+  printf "$b" > file
+  git commit -am"Update a file" >/dev/null
+
+  git show > commit.raw
+
+  if test "$#" = 3
+  then
+    # remove last newline
+    head -n11 commit.raw | head -c -1 > commit.act
+    printf "$3" >> commit.act
+  else
+    cat commit.raw > commit.act
+  fi
+
+  < commit.raw $CMD > commit.exp
+
+  diff commit.exp commit.act
+}
-- 
2.9.0
Eric Wong· Aug 10, 2016, 08:56 UTC · re: Brian Henderson · lore

Re: [PATCH 1/3] diff-highlight: add some tests.

Brian Henderson <henderson.bj@gmail.com> wrote:
Hi Brian,

A few minor portability/style nits below, but contrib/ probably (still?) has laxer rules than the rest of git...

I think we still require Signed-off-by lines in contrib, though...

Show 18 quoted lines
> +++ b/contrib/diff-highlight/t/Makefile
> @@ -0,0 +1,19 @@
> +-include ../../../config.mak.autogen
> +-include ../../../config.mak
> +
> +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
> +
> +all: test
> +test: $(T)
> +
> +.PHONY: help clean all test $(T)
> +
> +help:
> +	@echo 'Run "$(MAKE) test" to launch test scripts'
> +	@echo 'Run "$(MAKE) clean" to remove trash folders'
> +
> +$(T):
> +	@echo "*** $@ ***"; sh $@ $(GIT_TEST_OPTS)
Probably:
	@echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
like we do in t/Makefile in case we need to override 'sh'.
Show 12 quoted lines
> +
> +clean:
> +	$(RM) -r 'trash directory'.*
> diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> new file mode 100644
> index 0000000..ca7605f
> --- /dev/null
> +++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> @@ -0,0 +1,63 @@
> +#!/bin/sh
> +#
> +# Copyright (C) 2016

IANAL, but I think your name (or who you represent) needs to be in the copyright.

Show 5 quoted lines
> +
> +test_description='Test diff-highlight'
> +
> +. ./test-diff-highlight.sh
> +. $TEST_DIRECTORY/test-lib.sh

TEST_DIRECTORY ought to be quoted since it could contain shell-unfriendly chars (we intentionally name 'trash directory' this way to trigger errors).

Show 5 quoted lines
> +
> +# PERL is required, but assumed to be present, although not necessarily modern
> +# some tests require 5.8
> +
> +test_expect_success 'diff-highlight highlightes the beginning of a line' '
You can declare a prereq for PERL::
	test_expect_success PERL 'name' 'true'
And spelling: "highlights" (there's other instances of this, too)
> +  dh_test \
> +    "aaa\nbbb\nccc\n" \
> +    "aaa\n0bb\nccc\n" \
> +"
We use tabs for shell indentation.
<snip>
Show 15 quoted lines
> diff --git a/contrib/diff-highlight/t/test-diff-highlight.sh b/contrib/diff-highlight/t/test-diff-highlight.sh
> new file mode 100644
> index 0000000..9b26271
> --- /dev/null
> +++ b/contrib/diff-highlight/t/test-diff-highlight.sh
> @@ -0,0 +1,69 @@
> +#!/bin/sh
> +#
> +# Copyright (C) 2016
> +
> +CURR_DIR=$(pwd)
> +TEST_OUTPUT_DIRECTORY=$(pwd)
> +TEST_DIRECTORY="$CURR_DIR"/../../../t
> +cmd=diff-highlight
> +CMD="$CURR_DIR"/../$cmd
Same comments as above on quoting pathnames and empty copyright.
Show 13 quoted lines
> +
> +CW="\033[7m"
> +CR="\033[27m"
> +
> +export TEST_OUTPUT_DIRECTORY TEST_DIRECTORY CW CR
> +
> +dh_test() {
> +  dh_diff_test "$@"
> +  dh_commit_test "$@"
> +}
> +
> +dh_diff_test() {
> +  local a="$1" b="$2"

"local" is not a portable construct. It's common for Debian/Ubuntu systems to use dash as /bin/sh instead of bash; (dash is faster, and mostly sticks to POSIX)

The "devscripts" package in Debian/Ubuntu-based systems has a handy "checkbashisms" tool for checking portability of shell scripts.

Show 7 quoted lines
> +
> +  printf "$a" > file
> +  git add file
> +
> +  printf "$b" > file
> +
> +  git diff file > diff.raw

Commands should be '&&'-chained here since any of them could fail ("git add"/printf/etc could run out of space or fail on disk errors)

Also, our redirect style is: command >file without a space between '>' and destination.

See Documentation/CodingGuidelines for more details. Unfortunately, the reasoning is not explained for '>NOSPACE' and I'm not sure exactly why, either...

> +  if test "$#" = 3

Better to use -eq for numeric comparisons: test $# -eq 3 Quoting $# doesn't seem necessary unless your shell is hopelessly buggy :)

> +  then
> +    # remove last newline
> +    head -n5 diff.raw | head -c -1 > diff.act

"head -c" isn't portable, fortunately Jeff hoisted it out for use as test_copy_bytes in commit 48860819e8026 https://public-inbox.org/git/20160630090753.GA17463@sigill.intra.peff.net/

Show 6 quoted lines
> +    printf "$3" >> diff.act
> +  else
> +    cat diff.raw > diff.act
> +  fi
> +
> +  < diff.raw $CMD > diff.exp
$CMD probably needs to be quoted.  However, by the time I got
here I had to ask myself:  What is $CMD again?
A: Oh, look up at the top!
*shrug*  My attention span is tiny and my fonts are gigantic.
Perhaps using:
	DIFF_HIGHLIGHT="$CURR_DIR"/../diff-highlight
Would be more-readable?
> +
> +  diff diff.exp diff.act

Maybe use test_cmp to avoid depending external diff. (or "git diff -b --no-index" in your later test)

Same comments for the rest of the series, I think.

Typically, we expect a reroll in a few days, and I guess there's no rush (so you can squash your comment patch in addressing Junio's concern into 3/3).

Thanks.
Brian Henderson· Aug 15, 2016, 16:20 UTC · re: Eric Wong · lore

Re: [PATCH 1/3] diff-highlight: add some tests.

On Wed, Aug 10, 2016 at 08:56:35AM +0000, Eric Wong wrote:
<snip>
Show 5 quoted lines
> Typically, we expect a reroll in a few days, and I guess there's
> no rush (so you can squash your comment patch in addressing
> Junio's concern into 3/3).
> 
> Thanks.
thanks, (slowly) working on an update.
Junio C Hamano· Aug 15, 2016, 16:25 UTC · re: Brian Henderson · lore

Re: [PATCH 1/3] diff-highlight: add some tests.

Brian Henderson <henderson.bj@gmail.com> writes:
Show 11 quoted lines
> On Wed, Aug 10, 2016 at 08:56:35AM +0000, Eric Wong wrote:
>
> <snip>
>
>> Typically, we expect a reroll in a few days, and I guess there's
>> no rush (so you can squash your comment patch in addressing
>> Junio's concern into 3/3).
>> 
>> Thanks.
>
> thanks, (slowly) working on an update.
Thanks, both, for keeping the ball rolling ;-)
Brian Henderson· Aug 17, 2016, 15:31 UTC · re: Eric Wong · lore

[PATCH v2 0/3] diff-highlight: add support for git log --graph output.

Changes made per Eric.
On Wed, Aug 10, 2016 at 08:56:35AM +0000, Eric Wong wrote:
Show 9 quoted lines
> Brian Henderson <henderson.bj@gmail.com> wrote:
> 
> Hi Brian,
> 
> A few minor portability/style nits below, but contrib/ probably
> (still?) has laxer rules than the rest of git...
> 
> I think we still require Signed-off-by lines in contrib,
> though...
added
Show 26 quoted lines
> 
> > +++ b/contrib/diff-highlight/t/Makefile
> > @@ -0,0 +1,19 @@
> > +-include ../../../config.mak.autogen
> > +-include ../../../config.mak
> > +
> > +T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
> > +
> > +all: test
> > +test: $(T)
> > +
> > +.PHONY: help clean all test $(T)
> > +
> > +help:
> > +	@echo 'Run "$(MAKE) test" to launch test scripts'
> > +	@echo 'Run "$(MAKE) clean" to remove trash folders'
> > +
> > +$(T):
> > +	@echo "*** $@ ***"; sh $@ $(GIT_TEST_OPTS)
> 
> Probably:
> 
> 	@echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
> 
> like we do in t/Makefile in case we need to override 'sh'.
> 
done, although I basically had to copy the SHELL_PATH_SQ logic from t/Makefile
Show 15 quoted lines
> > +
> > +clean:
> > +	$(RM) -r 'trash directory'.*
> > diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> > new file mode 100644
> > index 0000000..ca7605f
> > --- /dev/null
> > +++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> > @@ -0,0 +1,63 @@
> > +#!/bin/sh
> > +#
> > +# Copyright (C) 2016
> 
> IANAL, but I think your name (or who you represent) needs to be
> in the copyright.
diff-highlight doesn't have a copyright, so I just removed it. ok?
Show 10 quoted lines
> 
> > +
> > +test_description='Test diff-highlight'
> > +
> > +. ./test-diff-highlight.sh
> > +. $TEST_DIRECTORY/test-lib.sh
> 
> TEST_DIRECTORY ought to be quoted since it could contain
> shell-unfriendly chars (we intentionally name 'trash directory'
> this way to trigger errors).
done
Show 10 quoted lines
> 
> > +
> > +# PERL is required, but assumed to be present, although not necessarily modern
> > +# some tests require 5.8
> > +
> > +test_expect_success 'diff-highlight highlightes the beginning of a line' '
> 
> You can declare a prereq for PERL::
> 
> 	test_expect_success PERL 'name' 'true'
done
> 
> And spelling: "highlights" (there's other instances of this, too)
oops, thanks
Show 7 quoted lines
> 
> > +  dh_test \
> > +    "aaa\nbbb\nccc\n" \
> > +    "aaa\n0bb\nccc\n" \
> > +"
> 
> We use tabs for shell indentation.
done
<snip>
Show 11 quoted lines
> > +
> > +dh_diff_test() {
> > +  local a="$1" b="$2"
> 
> "local" is not a portable construct.  It's common for
> Debian/Ubuntu systems to use dash as /bin/sh instead of bash;
> (dash is faster, and mostly sticks to POSIX)
> 
> The "devscripts" package in Debian/Ubuntu-based systems has a
> handy "checkbashisms" tool for checking portability of shell
> scripts.
checkbashisms didn't output anything, and I found other instances of local in some tests. but I removed anyway.
Show 11 quoted lines
> 
> > +
> > +  printf "$a" > file
> > +  git add file
> > +
> > +  printf "$b" > file
> > +
> > +  git diff file > diff.raw
> 
> Commands should be '&&'-chained here since any of them could fail
> ("git add"/printf/etc could run out of space or fail on disk errors)

I wasn't totally sure what to do here. I added some checks for empty files and && chained them with the last command to verify I wasn't diffing 2 empty files. Hope that is sufficient.

> 
> Also, our redirect style is:	command >file
> without a space between '>' and destination.
done
Show 6 quoted lines
> 
> See Documentation/CodingGuidelines for more details.
> Unfortunately, the reasoning is not explained for '>NOSPACE'
> and I'm not sure exactly why, either...
> 
> > +  if test "$#" = 3
done
Show 12 quoted lines
> 
> Better to use -eq for numeric comparisons: test $# -eq 3
> Quoting $# doesn't seem necessary unless your shell is
> hopelessly buggy :)
> 
> > +  then
> > +    # remove last newline
> > +    head -n5 diff.raw | head -c -1 > diff.act
> 
> "head -c" isn't portable, fortunately Jeff hoisted it out for
> use as test_copy_bytes in commit 48860819e8026
> https://public-inbox.org/git/20160630090753.GA17463@sigill.intra.peff.net/
It didn't look like his version supported a negative number, so I rolled my own.
Show 19 quoted lines
> 
> > +    printf "$3" >> diff.act
> > +  else
> > +    cat diff.raw > diff.act
> > +  fi
> > +
> > +  < diff.raw $CMD > diff.exp
> 
> $CMD probably needs to be quoted.  However, by the time I got
> here I had to ask myself:  What is $CMD again?
> A: Oh, look up at the top!
> 
> *shrug*  My attention span is tiny and my fonts are gigantic.
> 
> Perhaps using:
> 
> 	DIFF_HIGHLIGHT="$CURR_DIR"/../diff-highlight
> 
> Would be more-readable?
good, done.
Show 14 quoted lines
> 
> > +
> > +  diff diff.exp diff.act
> 
> Maybe use test_cmp to avoid depending external diff.
> (or "git diff -b --no-index" in your later test)
> 
> Same comments for the rest of the series, I think.
> 
> Typically, we expect a reroll in a few days, and I guess there's
> no rush (so you can squash your comment patch in addressing
> Junio's concern into 3/3).
> 
> Thanks.
thanks for the feedback.

I've rebased my changes. Unfortunately, having 3 commits made this somewhat tedious. I also find it weird that my new patch set makes it difficult to see what changes I've made from my first set. What's the standard workflow here?

Brian Henderson (3):
  diff-highlight: add some tests.
  diff-highlight: add failing test for handling --graph output.
  diff-highlight: add support for --graph output.
 contrib/diff-highlight/Makefile                  |   5 +
 contrib/diff-highlight/diff-highlight            |  16 ++--
 contrib/diff-highlight/t/Makefile                |  22 +++++
 contrib/diff-highlight/t/t9400-diff-highlight.sh |  75 +++++++++++++++
 contrib/diff-highlight/t/test-diff-highlight.sh  | 112 +++++++++++++++++++++++
 5 files changed, 224 insertions(+), 6 deletions(-)
 create mode 100644 contrib/diff-highlight/Makefile
 create mode 100644 contrib/diff-highlight/t/Makefile
 create mode 100755 contrib/diff-highlight/t/t9400-diff-highlight.sh
 create mode 100644 contrib/diff-highlight/t/test-diff-highlight.sh
-- 
2.9.0
Brian Henderson· Aug 17, 2016, 15:31 UTC · re: Brian Henderson · lore

[PATCH v2 2/3] diff-highlight: add failing test for handling --graph output.

Signed-off-by: Brian Henderson <henderson.bj@gmail.com>
---
 contrib/diff-highlight/t/t9400-diff-highlight.sh | 13 +++++++
 contrib/diff-highlight/t/test-diff-highlight.sh  | 43 ++++++++++++++++++++++++
 2 files changed, 56 insertions(+)
Show changes to 2 files +56 −0

contrib/diff-highlight/t/t9400-diff-highlight.sh, contrib/diff-highlight/t/test-diff-highlight.sh

diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
index 8eff178..39707c6 100755
--- a/contrib/diff-highlight/t/t9400-diff-highlight.sh
+++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
@@ -59,4 +59,17 @@ test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
 
 # TODO add multi-byte test
 
+test_expect_success 'diff-highlight highlights the beginning of a line' '
+	dh_graph_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\n0bb\nccc\n" \
+		"aaa\nb0b\nccc\n" \
+"
+ aaa
+-${CW}b${CR}bb
++${CW}0${CR}bb
+ ccc
+"
+'
+
 test_done
diff --git a/contrib/diff-highlight/t/test-diff-highlight.sh b/contrib/diff-highlight/t/test-diff-highlight.sh
index 38323e8..67f742c 100644
--- a/contrib/diff-highlight/t/test-diff-highlight.sh
+++ b/contrib/diff-highlight/t/test-diff-highlight.sh
@@ -64,6 +64,49 @@ dh_commit_test() {
 	test_cmp commit.exp commit.act
 }
 
+dh_graph_test() {
+	a="$1" b="$2" c="$3"
+
+	{
+		printf "$a" >file
+		git add file
+		git commit -m"Add a file"
+
+		printf "$b" >file
+		git commit -am"Update a file"
+
+		git checkout -b branch
+		printf "$c" >file
+		git commit -am"Update a file on branch"
+
+		git checkout master
+		printf "$a" >file
+		git commit -am"Update a file again"
+
+		git checkout branch
+		printf "$b" >file
+		git commit -am"Update a file similar to master"
+
+		git merge master
+		git checkout master
+		git merge branch --no-ff
+	} >/dev/null 2>&1
+
+	git log -p --graph --no-merges >graph.raw
+
+	# git log --graph orders the commits different than git log so we hack it by
+	# using sed to remove the graph part. We know from other tests, that DIFF_HIGHLIGHT
+	# works without the graph, so there should be no diff when running it with
+	# and without.
+	<graph.raw sed -e 's"^\(*\|| \||/\)\+""' -e 's"^  ""' | "$DIFF_HIGHLIGHT" >graph.exp
+	<graph.raw "$DIFF_HIGHLIGHT" | sed -e 's"^\(*\|| \||/\)\+""' -e 's"^  ""' >graph.act &&
+
+	test -s graph.act &&
+	# ignore whitespace since we're using a hacky sed command to remove the graph
+	# parts.
+	git diff -b --no-index graph.exp graph.act
+}
+
 test_chomp_eof() {
 	perl -pe 'chomp if eof'
 }
-- 
2.9.0
Junio C Hamano· Aug 17, 2016, 19:18 UTC · re: Brian Henderson · lore

Re: [PATCH v2 2/3] diff-highlight: add failing test for handling --graph output.

Brian Henderson <henderson.bj@gmail.com> writes:
Show 26 quoted lines
> Signed-off-by: Brian Henderson <henderson.bj@gmail.com>
> ---
>  contrib/diff-highlight/t/t9400-diff-highlight.sh | 13 +++++++
>  contrib/diff-highlight/t/test-diff-highlight.sh  | 43 ++++++++++++++++++++++++
>  2 files changed, 56 insertions(+)
>
> diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> index 8eff178..39707c6 100755
> --- a/contrib/diff-highlight/t/t9400-diff-highlight.sh
> +++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> @@ -59,4 +59,17 @@ test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
>  
>  # TODO add multi-byte test
>  
> +test_expect_success 'diff-highlight highlights the beginning of a line' '
> +	dh_graph_test \
> +		"aaa\nbbb\nccc\n" \
> +		"aaa\n0bb\nccc\n" \
> +		"aaa\nb0b\nccc\n" \
> +"
> + aaa
> +-${CW}b${CR}bb
> ++${CW}0${CR}bb
> + ccc
> +"
> +'

Is this expected to pass after applying 1/3 and 2/3? The title says "add faililng test", so I am assuming this is expected to fail, in which case the test should start out as "test_expect_failure". A later patch that makes it pass should turn "test_expect_failure" into "test_expect_success".

Show 21 quoted lines
>  test_done
> diff --git a/contrib/diff-highlight/t/test-diff-highlight.sh b/contrib/diff-highlight/t/test-diff-highlight.sh
> index 38323e8..67f742c 100644
> --- a/contrib/diff-highlight/t/test-diff-highlight.sh
> +++ b/contrib/diff-highlight/t/test-diff-highlight.sh
> @@ -64,6 +64,49 @@ dh_commit_test() {
>  	test_cmp commit.exp commit.act
>  }
>  
> +dh_graph_test() {
> +	a="$1" b="$2" c="$3"
> +
> +	{
> +		printf "$a" >file
> + ...
> +		git merge master
> +		git checkout master
> +		git merge branch --no-ff
> +	} >/dev/null 2>&1
> +
> +	git log -p --graph --no-merges >graph.raw

Hmph, when does it make sense to have "--no-merges" together with "--graph". Doesn't it result in a disconnected mess? Is that an interesting and most often used case?

> +
> +	# git log --graph orders the commits different than git log so we hack it by
> +	# using sed to remove the graph part.
Would it help if you knew "log --topo-order" to remove the "hack"?
Brian Henderson· Aug 17, 2016, 15:31 UTC · re: Brian Henderson · lore

[PATCH v2 1/3] diff-highlight: add some tests.

Signed-off-by: Brian Henderson <henderson.bj@gmail.com>
---
 contrib/diff-highlight/Makefile                  |  5 ++
 contrib/diff-highlight/t/Makefile                | 22 ++++++++
 contrib/diff-highlight/t/t9400-diff-highlight.sh | 62 +++++++++++++++++++++
 contrib/diff-highlight/t/test-diff-highlight.sh  | 69 ++++++++++++++++++++++++
 4 files changed, 158 insertions(+)
 create mode 100644 contrib/diff-highlight/Makefile
 create mode 100644 contrib/diff-highlight/t/Makefile
 create mode 100755 contrib/diff-highlight/t/t9400-diff-highlight.sh
 create mode 100644 contrib/diff-highlight/t/test-diff-highlight.sh
Show changes to 4 files +158 −0

contrib/diff-highlight/Makefile, contrib/diff-highlight/t/Makefile, contrib/diff-highlight/t/t9400-diff-highlight.sh, contrib/diff-highlight/t/test-diff-highlight.sh

diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile
new file mode 100644
index 0000000..b866259
--- /dev/null
+++ b/contrib/diff-highlight/Makefile
@@ -0,0 +1,5 @@
+# nothing to build
+all:;
+
+test:
+	$(MAKE) -C t
diff --git a/contrib/diff-highlight/t/Makefile b/contrib/diff-highlight/t/Makefile
new file mode 100644
index 0000000..5ff5275
--- /dev/null
+++ b/contrib/diff-highlight/t/Makefile
@@ -0,0 +1,22 @@
+-include ../../../config.mak.autogen
+-include ../../../config.mak
+
+# copied from ../../t/Makefile
+SHELL_PATH ?= $(SHELL)
+SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
+T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
+
+all: test
+test: $(T)
+
+.PHONY: help clean all test $(T)
+
+help:
+	@echo 'Run "$(MAKE) test" to launch test scripts'
+	@echo 'Run "$(MAKE) clean" to remove trash folders'
+
+$(T):
+	@echo "*** $@ ***"; '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS)
+
+clean:
+	$(RM) -r 'trash directory'.*
diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
new file mode 100755
index 0000000..8eff178
--- /dev/null
+++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+test_description='Test diff-highlight'
+
+. ./test-diff-highlight.sh
+. "$TEST_DIRECTORY"/test-lib.sh
+
+# PERL is required, but assumed to be present, although not necessarily modern
+# some tests require 5.8
+test_expect_success PERL 'name' 'true'
+
+test_expect_success 'diff-highlight highlights the beginning of a line' '
+	dh_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\n0bb\nccc\n" \
+"
+ aaa
+-${CW}b${CR}bb
++${CW}0${CR}bb
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight highlights the end of a line' '
+	dh_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\nbb0\nccc\n" \
+"
+ aaa
+-bb${CW}b${CR}
++bb${CW}0${CR}
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight highlights the middle of a line' '
+	dh_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\nb0b\nccc\n" \
+"
+ aaa
+-b${CW}b${CR}b
++b${CW}0${CR}b
+ ccc
+"
+'
+
+test_expect_success 'diff-highlight does not highlight whole line' '
+	dh_test \
+		"aaa\nbbb\nccc\n" \
+		"aaa\n000\nccc\n"
+'
+
+test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
+	dh_test \
+		"aaa\nbbb\n" \
+		"aaa\nb0b\nccc\n"
+'
+
+# TODO add multi-byte test
+
+test_done
diff --git a/contrib/diff-highlight/t/test-diff-highlight.sh b/contrib/diff-highlight/t/test-diff-highlight.sh
new file mode 100644
index 0000000..38323e8
--- /dev/null
+++ b/contrib/diff-highlight/t/test-diff-highlight.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+CURR_DIR=$(pwd)
+TEST_OUTPUT_DIRECTORY=$(pwd)
+TEST_DIRECTORY="$CURR_DIR"/../../../t
+DIFF_HIGHLIGHT="$CURR_DIR"/../diff-highlight
+
+CW="\033[7m"
+CR="\033[27m"
+
+export TEST_OUTPUT_DIRECTORY TEST_DIRECTORY CW CR
+
+dh_test() {
+	dh_diff_test "$@" &&
+	dh_commit_test "$@"
+}
+
+dh_diff_test() {
+	a="$1" b="$2"
+
+	printf "$a" >file
+	git add file
+
+	printf "$b" >file
+	git diff file >diff.raw
+
+	if test $# -eq 3
+	then
+		# remove last newline
+		head -n5 diff.raw | test_chomp_eof >diff.exp
+		printf "$3" >>diff.exp
+	else
+		cat diff.raw >diff.exp
+	fi
+
+	<diff.raw "$DIFF_HIGHLIGHT" >diff.act &&
+	test -s diff.act &&
+	diff diff.exp diff.act
+}
+
+dh_commit_test() {
+	a="$1" b="$2"
+
+	printf "$a" >file
+	git add file
+	git commit -m"Add a file" >/dev/null
+
+	printf "$b" >file
+	git commit -am"Update a file" >/dev/null
+
+	git show >commit.raw
+
+	if test "$#" = 3
+	then
+		# remove last newline
+		head -n11 commit.raw | test_chomp_eof >commit.exp
+		printf "$3" >>commit.exp
+	else
+		cat commit.raw >commit.exp
+	fi
+
+	<commit.raw "$DIFF_HIGHLIGHT" >commit.act &&
+	test -s commit.act &&
+	test_cmp commit.exp commit.act
+}
+
+test_chomp_eof() {
+	perl -pe 'chomp if eof'
+}
-- 
2.9.0
Junio C Hamano· Aug 17, 2016, 19:09 UTC · re: Brian Henderson · lore

Re: [PATCH v2 1/3] diff-highlight: add some tests.

Brian Henderson <henderson.bj@gmail.com> writes:
Show 11 quoted lines
> Signed-off-by: Brian Henderson <henderson.bj@gmail.com>
> ---
>  contrib/diff-highlight/Makefile                  |  5 ++
>  contrib/diff-highlight/t/Makefile                | 22 ++++++++
>  contrib/diff-highlight/t/t9400-diff-highlight.sh | 62 +++++++++++++++++++++
>  contrib/diff-highlight/t/test-diff-highlight.sh  | 69 ++++++++++++++++++++++++
>  4 files changed, 158 insertions(+)
>  create mode 100644 contrib/diff-highlight/Makefile
>  create mode 100644 contrib/diff-highlight/t/Makefile
>  create mode 100755 contrib/diff-highlight/t/t9400-diff-highlight.sh
>  create mode 100644 contrib/diff-highlight/t/test-diff-highlight.sh

I am not sure test-diff-highlight.sh should be there; the function definitions would still be useful but move them to the beginning of t9400-diff-highlight.sh perhaps?

Show 8 quoted lines
> diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile
> new file mode 100644
> index 0000000..b866259
> --- /dev/null
> +++ b/contrib/diff-highlight/Makefile
> @@ -0,0 +1,5 @@
> +# nothing to build
> +all:;
Drop ';'.
Show 16 quoted lines
> diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> new file mode 100755
> index 0000000..8eff178
> --- /dev/null
> +++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
> @@ -0,0 +1,62 @@
> +#!/bin/sh
> +
> +test_description='Test diff-highlight'
> +
> +. ./test-diff-highlight.sh
> +. "$TEST_DIRECTORY"/test-lib.sh
> +
> +# PERL is required, but assumed to be present, although not necessarily modern
> +# some tests require 5.8
> +test_expect_success PERL 'name' 'true'

If the platform lacks PERL prerequisite, this will simply be skipped, and if the platform has it, it will always succeed.

I am not sure what you are trying to achieve by having this line here.

Show 5 quoted lines
> +test_expect_success 'diff-highlight does not highlight whole line' '
> +	dh_test \
> +		"aaa\nbbb\nccc\n" \
> +		"aaa\n000\nccc\n"
> +'

Hmm, does this express the desired outcome, or just document the current (possibly broken--I dunno) behaviour? The same question for the next one.

Show 5 quoted lines
> +test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
> +	dh_test \
> +		"aaa\nbbb\n" \
> +		"aaa\nb0b\nccc\n"
> +'
> +dh_test() {
Style: "dh_test () {"
The other functions in this file share the same.
Show 17 quoted lines
> +	dh_diff_test "$@" &&
> +	dh_commit_test "$@"
> +}
> +
> +dh_diff_test() {
> +	a="$1" b="$2"
> +
> +	printf "$a" >file
> +	git add file
> +
> +	printf "$b" >file
> +	git diff file >diff.raw
> +
> +	if test $# -eq 3
> +	then
> +		# remove last newline
> +		head -n5 diff.raw | test_chomp_eof >diff.exp

A reader can see "remove last newline" by seeing test_chomp_eof and what it does without a comment, but it is totally unclear why you need to remove. The comment that says what it does without saying why it does it is useless.

Show 6 quoted lines
> +		printf "$3" >>diff.exp
> +	else
> +		cat diff.raw >diff.exp
> +	fi
> +
> +	<diff.raw "$DIFF_HIGHLIGHT" >diff.act &&

Even though this is technically kosher, I do not see a merit of deviating from the common practice of starting a line with the command, i.e.

	"$DIFF_HIGHLIGHT" <diff.raw >diff.actual
would be much easier to read.
> +	test -s diff.act &&

Why? If you always have the expected output that you are going to compare with, wouldn't that sufficient to do that test without this? Besides, having "test -s" means that you can never make sure that a certain pair of input does not show any changes. Perhaps drop it?

> +	diff diff.exp diff.act
Use test_cmp unless there is a strong reason why you shouldn't?
Show 8 quoted lines
> +}
> +
> +dh_commit_test() {
> +	a="$1" b="$2"
> +
> +	printf "$a" >file
> +	git add file
> +	git commit -m"Add a file" >/dev/null
Avoid sticking a short-option to its argument, i.e.
    git commit -m "Add a file"
> +
> +	printf "$b" >file
> +	git commit -am"Update a file" >/dev/null
Likewise.
    git commit -a -m "Update a file"

The remainder of the file invites the same set of questions and comments you see for dh_diff_test() above, so I won't repeat them.

Thanks.
Brian Henderson· Aug 19, 2016, 14:42 UTC · re: Junio C Hamano · lore

Re: [PATCH v2 1/3] diff-highlight: add some tests.

On Wed, Aug 17, 2016 at 12:09:25PM -0700, Junio C Hamano wrote:
> Brian Henderson <henderson.bj@gmail.com> writes:
<snip>
Show 11 quoted lines
> 
> > +
> > +# PERL is required, but assumed to be present, although not necessarily modern
> > +# some tests require 5.8
> > +test_expect_success PERL 'name' 'true'
> 
> If the platform lacks PERL prerequisite, this will simply be
> skipped, and if the platform has it, it will always succeed.
> 
> I am not sure what you are trying to achieve by having this line
> here.

I originally didn't have this line, and my comment was referring to the t/README which says

   Even without the PERL prerequisite, tests can assume there is a
   usable perl interpreter at $PERL_PATH, though it need not be
   particularly modern.

There is current functionality in diff-highlight which requires at least perl 5.8 (the utf8 functions). I was going to add a test for this as well, but I'm not super comfy with multibyte chars.

Eric recommended adding this line, what do you think?
would `test_set_prereq PERL` be better?
Show 6 quoted lines
> 
> > +test_expect_success 'diff-highlight does not highlight whole line' '
> > +	dh_test \
> > +		"aaa\nbbb\nccc\n" \
> > +		"aaa\n000\nccc\n"
> > +'

This (at least to me) is desired. See comment for `sub is_pair_interesting`

Show 10 quoted lines
> 
> Hmm, does this express the desired outcome, or just document the
> current (possibly broken--I dunno) behaviour?  The same question for
> the next one.
> 
> > +test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
> > +	dh_test \
> > +		"aaa\nbbb\n" \
> > +		"aaa\nb0b\nccc\n"
> > +'

This is undesired behavior, but currently implemented for simplicity, see `sub show_hunk`

Do they need comments or something?
<snip>
Show 7 quoted lines
> 
> > +	test -s diff.act &&
> 
> Why?  If you always have the expected output that you are going to
> compare with, wouldn't that sufficient to do that test without this?
> Besides, having "test -s" means that you can never make sure that a
> certain pair of input does not show any changes.  Perhaps drop it?

I was trying to address Eric's concern for `printf` or `git commit` et al failing. Also, this file will always be a diff, it just might not having any highlighting (so not empty?).

I'll take another stab.
Show 30 quoted lines
> 
> > +	diff diff.exp diff.act
> 
> Use test_cmp unless there is a strong reason why you shouldn't?
> 
> > +}
> > +
> > +dh_commit_test() {
> > +	a="$1" b="$2"
> > +
> > +	printf "$a" >file
> > +	git add file
> > +	git commit -m"Add a file" >/dev/null
> 
> Avoid sticking a short-option to its argument, i.e.
> 
>     git commit -m "Add a file"
> 
> > +
> > +	printf "$b" >file
> > +	git commit -am"Update a file" >/dev/null
> 
> Likewise.
> 
>     git commit -a -m "Update a file"
> 
> The remainder of the file invites the same set of questions and
> comments you see for dh_diff_test() above, so I won't repeat them.
> 
> Thanks.
thanks for the feedback.
Jeff King· Aug 19, 2016, 14:51 UTC · re: Brian Henderson · lore

Re: [PATCH v2 1/3] diff-highlight: add some tests.

On Fri, Aug 19, 2016 at 07:42:35AM -0700, Brian Henderson wrote:
Show 20 quoted lines
> > > +# PERL is required, but assumed to be present, although not necessarily modern
> > > +# some tests require 5.8
> > > +test_expect_success PERL 'name' 'true'
> > 
> > If the platform lacks PERL prerequisite, this will simply be
> > skipped, and if the platform has it, it will always succeed.
> > 
> > I am not sure what you are trying to achieve by having this line
> > here.
> 
> I originally didn't have this line, and my comment was referring to the
> t/README which says
> 
>    Even without the PERL prerequisite, tests can assume there is a
>    usable perl interpreter at $PERL_PATH, though it need not be
>    particularly modern.
> 
> There is current functionality in diff-highlight which requires at least
> perl 5.8 (the utf8 functions). I was going to add a test for this as
> well, but I'm not super comfy with multibyte chars.

Yeah, I'd agree this test would want the PERL prereq. It is not just using perl for one-liners in support of the script; it is testing major perl functionality that should be skipped if we do not have a modern perl available.

> Eric recommended adding this line, what do you think?
> 
> would `test_set_prereq PERL` be better?

test_set_prereq is for telling the test scripts that we _have_ perl, but what I think this script wants to do is test "do we have perl?" and abort otherwise. The way to do that is:

  if ! test_have_prereq PERL
  then
	skip_all='skipping diff-highlight tests; perl not available'
	test_done
  fi
Show 8 quoted lines
> > > +test_expect_success 'diff-highlight does not highlight whole line' '
> > > +	dh_test \
> > > +		"aaa\nbbb\nccc\n" \
> > > +		"aaa\n000\nccc\n"
> > > +'
> 
> This (at least to me) is desired. See comment for `sub
> is_pair_interesting`
Yeah, that is an intentional behavior, and makes sense to test.
Show 10 quoted lines
> > > +test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
> > > +	dh_test \
> > > +		"aaa\nbbb\n" \
> > > +		"aaa\nb0b\nccc\n"
> > > +'
> 
> This is undesired behavior, but currently implemented for simplicity,
> see `sub show_hunk`
> 
> Do they need comments or something?

Undesired behavior should generally not be tested for. It just makes life harder for somebody when they make a change that violates it, and they have to figure out "oh, but it's _good_ that I changed that, the tests were wrong" (or more likely "I didn't fix it, but it's just broken in a different way, and neither is preferable").

If you want to document known shortcomings, the best thing to do is show what you'd _like_ to have happen, and mark it as test_expect_failure; the test scripts show this as a known-breakage, and somebody later who fixes it can flip the "failure" to "success".

-Peff
Brian Henderson· Aug 19, 2016, 15:13 UTC · re: Jeff King · lore

Re: [PATCH v2 1/3] diff-highlight: add some tests.

On Fri, Aug 19, 2016 at 10:51:23AM -0400, Jeff King wrote:
Show 76 quoted lines
> On Fri, Aug 19, 2016 at 07:42:35AM -0700, Brian Henderson wrote:
> 
> > > > +# PERL is required, but assumed to be present, although not necessarily modern
> > > > +# some tests require 5.8
> > > > +test_expect_success PERL 'name' 'true'
> > > 
> > > If the platform lacks PERL prerequisite, this will simply be
> > > skipped, and if the platform has it, it will always succeed.
> > > 
> > > I am not sure what you are trying to achieve by having this line
> > > here.
> > 
> > I originally didn't have this line, and my comment was referring to the
> > t/README which says
> > 
> >    Even without the PERL prerequisite, tests can assume there is a
> >    usable perl interpreter at $PERL_PATH, though it need not be
> >    particularly modern.
> > 
> > There is current functionality in diff-highlight which requires at least
> > perl 5.8 (the utf8 functions). I was going to add a test for this as
> > well, but I'm not super comfy with multibyte chars.
> 
> Yeah, I'd agree this test would want the PERL prereq. It is not just
> using perl for one-liners in support of the script; it is testing major
> perl functionality that should be skipped if we do not have a modern
> perl available.
> 
> > Eric recommended adding this line, what do you think?
> > 
> > would `test_set_prereq PERL` be better?
> 
> test_set_prereq is for telling the test scripts that we _have_ perl, but
> what I think this script wants to do is test "do we have perl?" and
> abort otherwise. The way to do that is:
> 
>   if ! test_have_prereq PERL
>   then
> 	skip_all='skipping diff-highlight tests; perl not available'
> 	test_done
>   fi
> 
> > > > +test_expect_success 'diff-highlight does not highlight whole line' '
> > > > +	dh_test \
> > > > +		"aaa\nbbb\nccc\n" \
> > > > +		"aaa\n000\nccc\n"
> > > > +'
> > 
> > This (at least to me) is desired. See comment for `sub
> > is_pair_interesting`
> 
> Yeah, that is an intentional behavior, and makes sense to test.
> 
> > > > +test_expect_success 'diff-highlight does not highlight mismatched hunk size' '
> > > > +	dh_test \
> > > > +		"aaa\nbbb\n" \
> > > > +		"aaa\nb0b\nccc\n"
> > > > +'
> > 
> > This is undesired behavior, but currently implemented for simplicity,
> > see `sub show_hunk`
> > 
> > Do they need comments or something?
> 
> Undesired behavior should generally not be tested for. It just makes
> life harder for somebody when they make a change that violates it, and
> they have to figure out "oh, but it's _good_ that I changed that, the
> tests were wrong" (or more likely "I didn't fix it, but it's just broken
> in a different way, and neither is preferable").
> 
> If you want to document known shortcomings, the best thing to do is show
> what you'd _like_ to have happen, and mark it as test_expect_failure;
> the test scripts show this as a known-breakage, and somebody later who
> fixes it can flip the "failure" to "success".
> 
> -Peff
all very helpful, thanks!
Brian Henderson· Aug 17, 2016, 15:31 UTC · re: Brian Henderson · lore

[PATCH v2 3/3] diff-highlight: add support for --graph output.

Signed-off-by: Brian Henderson <henderson.bj@gmail.com>
---
 contrib/diff-highlight/diff-highlight | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
Show changes to contrib/diff-highlight/diff-highlight +10 −6
diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight
index ffefc31..9364423 100755
--- a/contrib/diff-highlight/diff-highlight
+++ b/contrib/diff-highlight/diff-highlight
@@ -21,6 +21,10 @@ my $RESET = "\x1b[m";
 my $COLOR = qr/\x1b\[[0-9;]*m/;
 my $BORING = qr/$COLOR|\s/;
 
+# The patch portion of git log -p --graph should only ever have preceding | and
+# not / or \ as merge history only shows up on the commit line.
+my $GRAPH = qr/$COLOR?\|$COLOR?\s+/;
+
 my @removed;
 my @added;
 my $in_hunk;
@@ -32,12 +36,12 @@ $SIG{PIPE} = 'DEFAULT';
 while (<>) {
 	if (!$in_hunk) {
 		print;
-		$in_hunk = /^$COLOR*\@/;
+		$in_hunk = /^$GRAPH*$COLOR*\@/;
 	}
-	elsif (/^$COLOR*-/) {
+	elsif (/^$GRAPH*$COLOR*-/) {
 		push @removed, $_;
 	}
-	elsif (/^$COLOR*\+/) {
+	elsif (/^$GRAPH*$COLOR*\+/) {
 		push @added, $_;
 	}
 	else {
@@ -46,7 +50,7 @@ while (<>) {
 		@added = ();
 
 		print;
-		$in_hunk = /^$COLOR*[\@ ]/;
+		$in_hunk = /^$GRAPH*$COLOR*[\@ ]/;
 	}
 
 	# Most of the time there is enough output to keep things streaming,
@@ -211,8 +215,8 @@ sub is_pair_interesting {
 	my $suffix_a = join('', @$a[($sa+1)..$#$a]);
 	my $suffix_b = join('', @$b[($sb+1)..$#$b]);
 
-	return $prefix_a !~ /^$COLOR*-$BORING*$/ ||
-	       $prefix_b !~ /^$COLOR*\+$BORING*$/ ||
+	return $prefix_a !~ /^$GRAPH*$COLOR*-$BORING*$/ ||
+	       $prefix_b !~ /^$GRAPH*$COLOR*\+$BORING*$/ ||
 	       $suffix_a !~ /^$BORING*$/ ||
 	       $suffix_b !~ /^$BORING*$/;
 }
-- 
2.9.0
Jeff King· Aug 19, 2016, 14:37 UTC · re: Brian Henderson · lore

Re: [PATCH v2 3/3] diff-highlight: add support for --graph output.

On Wed, Aug 17, 2016 at 08:31:24AM -0700, Brian Henderson wrote:
>  contrib/diff-highlight/diff-highlight | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)

Junio already commented on the tests, and I think everything he said in his review is sensible.

As for the code itself, this looks much simpler than some of the things we discussed off-list, which is good. There is one place that you did not touch that I think is interesting: split_line.

It splits on $COLOR to mark those bits in their own list elements (so they can be skipped). But we don't do anything special for $GRAPH there.

Obviously it would be wrong to find $GRAPH in the middle of the line. But I think we end up in highlight_pair() with a sequence like this for each line:

  [
    color-graph,
    "|"
    color-reset,
    " ",
    ... possibly more graph pipes ...
    "-" (or "+")
    ... actual line data ...
  ]

We ignore "$COLOR" in the middle of that list, but not the other syntactic bits. I think this just works because we have to skip forward to the "-" or "+" element, and that happens to skip over all of the graph cruft, as well.

In a more general sense, it might have been better for split_line() to return a list of records, with each one containing a bit for "am I interesting?" along with the actual token data. But I think because the graph data cannot contain "-" or "+", it's acceptable to simply leave this as it is. It might be worth a comment (either in-code, or describing the strategy in the commit message).

-Peff
Eric Wong· Aug 19, 2016, 21:19 UTC · re: Brian Henderson · lore

Re: [PATCH v2 0/3] diff-highlight: add support for git log --graph output.

Brian Henderson <henderson.bj@gmail.com> wrote:
Show 11 quoted lines
> On Wed, Aug 10, 2016 at 08:56:35AM +0000, Eric Wong wrote:
> > "local" is not a portable construct.  It's common for
> > Debian/Ubuntu systems to use dash as /bin/sh instead of bash;
> > (dash is faster, and mostly sticks to POSIX)
> > 
> > The "devscripts" package in Debian/Ubuntu-based systems has a
> > handy "checkbashisms" tool for checking portability of shell
> > scripts.
> 
> checkbashisms didn't output anything, and I found other instances of
> local in some tests. but I removed anyway.

Ah, I guess "checkbashisms --posix" is required nowadays since Debian policy deviated from POSIX, here (we don't blindly follow POSIX, either).

Anyways, some people still care about ksh93 as of a few months ago; so I think avoiding "local" is preferable:

  https://public-inbox.org/git/?q=ksh93&d:..20160801

I think all of our other "local" uses are limited to bash-specific parts: bash completion, mingw tests

<snip>
> I've rebased my changes. Unfortunately, having 3 commits made this somewhat
> tedious. I also find it weird that my new patch set makes it difficult to see
> what changes I've made from my first set. What's the standard workflow here?

I check out a new branch with the same base as the previous series and "git diff previous current"

(without git, I'd be using interdiff from the patchutils Debian package)

Sometimes I will rebase against both old+new against Junio's master to avoid/reduce conflicts.

Jeff King· Aug 19, 2016, 21:23 UTC · re: Eric Wong · lore

Re: [PATCH v2 0/3] diff-highlight: add support for git log --graph output.

On Fri, Aug 19, 2016 at 09:19:44PM +0000, Eric Wong wrote:
Show 11 quoted lines
> > I've rebased my changes. Unfortunately, having 3 commits made this somewhat
> > tedious. I also find it weird that my new patch set makes it difficult to see
> > what changes I've made from my first set. What's the standard workflow here?
> 
> I check out a new branch with the same base as the previous series
> and "git diff previous current"
> 
> (without git, I'd be using interdiff from the patchutils Debian package)
> 
> Sometimes I will rebase against both old+new against Junio's master
> to avoid/reduce conflicts.
You might also try Thomas Rast's topic-branch diff:
  https://github.com/trast/tbdiff

It gives better patch-by-patch differences. And it handles the case that the topics have different bases (which is handy if you've rebased, or if Junio happened to apply on a different base than you did).

-Peff
Lars Schneider· Aug 15, 2016, 16:40 UTC · re: Brian Henderson · lore

Re: [PATCH 1/3] diff-highlight: add some tests.

Show 14 quoted lines
> On 30 Jul 2016, at 17:11, Brian Henderson <henderson.bj@gmail.com> wrote:
> 
> ---
> contrib/diff-highlight/Makefile                  |  5 ++
> contrib/diff-highlight/t/Makefile                | 19 +++++++
> contrib/diff-highlight/t/t9400-diff-highlight.sh | 63 ++++++++++++++++++++++
> contrib/diff-highlight/t/test-diff-highlight.sh  | 69 ++++++++++++++++++++++++
> 4 files changed, 156 insertions(+)
> create mode 100644 contrib/diff-highlight/Makefile
> create mode 100644 contrib/diff-highlight/t/Makefile
> create mode 100644 contrib/diff-highlight/t/t9400-diff-highlight.sh
> create mode 100644 contrib/diff-highlight/t/test-diff-highlight.sh
> 
> diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile

Would it make sense to add the contrib tests to the Travis-CI build, too? https://travis-ci.org/git/git/branches

- Lars
Junio C Hamano· Aug 16, 2016, 20:48 UTC · re: Lars Schneider · lore

Re: [PATCH 1/3] diff-highlight: add some tests.

Lars Schneider <larsxschneider@gmail.com> writes:
Show 17 quoted lines
>> On 30 Jul 2016, at 17:11, Brian Henderson <henderson.bj@gmail.com> wrote:
>> 
>> ---
>> contrib/diff-highlight/Makefile                  |  5 ++
>> contrib/diff-highlight/t/Makefile                | 19 +++++++
>> contrib/diff-highlight/t/t9400-diff-highlight.sh | 63 ++++++++++++++++++++++
>> contrib/diff-highlight/t/test-diff-highlight.sh  | 69 ++++++++++++++++++++++++
>> 4 files changed, 156 insertions(+)
>> create mode 100644 contrib/diff-highlight/Makefile
>> create mode 100644 contrib/diff-highlight/t/Makefile
>> create mode 100644 contrib/diff-highlight/t/t9400-diff-highlight.sh
>> create mode 100644 contrib/diff-highlight/t/test-diff-highlight.sh
>> 
>> diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile
>
> Would it make sense to add the contrib tests to the Travis-CI build, too?
> https://travis-ci.org/git/git/branches

The more the merrier ;-)? I do not think of a downside, especially if you are adding it as a separate thing that comes after the main test, or for even better isolation, an entirely separate job.

By the way, how flaky are existing tests? Are people actively following breakage reports?

Lars Schneider· Aug 24, 2016, 09:38 UTC · re: Junio C Hamano · lore

Re: [PATCH 1/3] diff-highlight: add some tests.

Show 25 quoted lines
> On 16 Aug 2016, at 22:48, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Lars Schneider <larsxschneider@gmail.com> writes:
> 
>>> On 30 Jul 2016, at 17:11, Brian Henderson <henderson.bj@gmail.com> wrote:
>>> 
>>> ---
>>> contrib/diff-highlight/Makefile                  |  5 ++
>>> contrib/diff-highlight/t/Makefile                | 19 +++++++
>>> contrib/diff-highlight/t/t9400-diff-highlight.sh | 63 ++++++++++++++++++++++
>>> contrib/diff-highlight/t/test-diff-highlight.sh  | 69 ++++++++++++++++++++++++
>>> 4 files changed, 156 insertions(+)
>>> create mode 100644 contrib/diff-highlight/Makefile
>>> create mode 100644 contrib/diff-highlight/t/Makefile
>>> create mode 100644 contrib/diff-highlight/t/t9400-diff-highlight.sh
>>> create mode 100644 contrib/diff-highlight/t/test-diff-highlight.sh
>>> 
>>> diff --git a/contrib/diff-highlight/Makefile b/contrib/diff-highlight/Makefile
>> 
>> Would it make sense to add the contrib tests to the Travis-CI build, too?
>> https://travis-ci.org/git/git/branches
> 
> The more the merrier ;-)?  I do not think of a downside, especially
> if you are adding it as a separate thing that comes after the main
> test, or for even better isolation, an entirely separate job.
OK, if I will post a patch (might take a while).
> By the way, how flaky are existing tests?  Are people actively
> following breakage reports?

Good question - I was curious about that, too. That's why I made a little website (only tested on Chrome, requires JS):

https://larsxschneider.github.io/git-ci-stats/

There you can see all builds for all branches including their failure reason. In general I would say flakiness is no issue anymore.

I don't know who else is looking at the breakage reports but I do. That's the reason for my "next" breakage reports in the past:

http://public-inbox.org/git/A6131C47-3230-4EC4-B3F6-B2507C937A22@gmail.com/ http://public-inbox.org/git/4877318E-3CBF-4C87-B24D-AAE35C427D66@gmail.com/ http://public-inbox.org/git/FB76544F-16F7-45CA-9649-FD62EE44B0DE@gmail.com/ ...

Cheers, Lars

← back to recent threads