Skip to contentSkip to conversation

diff-highlight: add support for git log --graph output.

PATCH In review Brian Henderson 2 participants 2 messages Jul 28, 2016 – Jul 29, 2016

lore
Share & tools
lore
#0 lore raw

cover diff-highlight: add support for git log --graph output.

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
Signature · 1 line
2.9.0

From f2468205f5f43b17bfd0398959a1ae66588a8f0d Mon Sep 17 00:00:00 2001
From: Brian Henderson <[email protected]>
Date: Thu, 21 Jul 2016 09:43:54 -0700
Subject: [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
contrib/diff-highlight/Makefile new file +5 -0
new file mode 100644
index 0000000..b866259
@@ -0,0 +1,5 @@
+# nothing to build
+all:;
+
+test:
+	$(MAKE) -C t
contrib/diff-highlight/t/Makefile new file +19 -0
new file mode 100644
index 0000000..ac81fc0
@@ -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'.*
contrib/diff-highlight/t/t9400-diff-highlight.sh new file +63 -0

63 lines not on this page · raw message

contrib/diff-highlight/t/test-diff-highlight.sh new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.9.0

From 78cca284fb5d0c094dc47947cb4cc54c5a8c0f78 Mon Sep 17 00:00:00 2001
From: Brian Henderson <[email protected]>
Date: Tue, 26 Jul 2016 07:49:45 -0700
Subject: [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(+)
contrib/diff-highlight/t/t9400-diff-highlight.sh +13 -0
index ca7605f..2fb4869 100644
@@ -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
contrib/diff-highlight/t/test-diff-highlight.sh +42 -0

45 lines not on this page · raw message

Signature · 1 line
2.9.0

From 615451541643a07486e209f9f17edae9436b882c Mon Sep 17 00:00:00 2001
From: Brian Henderson <[email protected]>
Date: Tue, 26 Jul 2016 07:51:07 -0700
Subject: [PATCH 3/3] diff-highlight: add support for --graph output.

---
 contrib/diff-highlight/diff-highlight | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
contrib/diff-highlight/diff-highlight +7 -6
index ffefc31..ec31356 100755
@@ -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*$/;
 }
Signature · 1 line
2.9.0
#1 lore raw

W dniu 2016-07-28 o 18:27, Brian Henderson pisze:

Quoted 12 lines

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.

Quoted 7 lines

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.

Could you please follow SubmittingPatches, and send patches in separate emails, inline, with those emails being replies to cover letter (like git format-patch and git send-email would do), and not as attachments to cover letter?

With email as it stands it is really difficult to review individual patches.

Quoted 12 lines
 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