diff-highlight: add support for --graph output
Signed-off-by: Brian Henderson <henderson.bj@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
							parent
							
								
									caf5ea707c
								
							
						
					
					
						commit
						7e4ffb4c17
					
				|  | @ -21,6 +21,10 @@ my $RESET = "\x1b[m"; | ||||||
| my $COLOR = qr/\x1b\[[0-9;]*m/; | my $COLOR = qr/\x1b\[[0-9;]*m/; | ||||||
| my $BORING = qr/$COLOR|\s/; | 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 @removed; | ||||||
| my @added; | my @added; | ||||||
| my $in_hunk; | my $in_hunk; | ||||||
|  | @ -32,12 +36,12 @@ $SIG{PIPE} = 'DEFAULT'; | ||||||
| while (<>) { | while (<>) { | ||||||
| 	if (!$in_hunk) { | 	if (!$in_hunk) { | ||||||
| 		print; | 		print; | ||||||
| 		$in_hunk = /^$COLOR*\@/; | 		$in_hunk = /^$GRAPH*$COLOR*\@/; | ||||||
| 	} | 	} | ||||||
| 	elsif (/^$COLOR*-/) { | 	elsif (/^$GRAPH*$COLOR*-/) { | ||||||
| 		push @removed, $_; | 		push @removed, $_; | ||||||
| 	} | 	} | ||||||
| 	elsif (/^$COLOR*\+/) { | 	elsif (/^$GRAPH*$COLOR*\+/) { | ||||||
| 		push @added, $_; | 		push @added, $_; | ||||||
| 	} | 	} | ||||||
| 	else { | 	else { | ||||||
|  | @ -46,7 +50,7 @@ while (<>) { | ||||||
| 		@added = (); | 		@added = (); | ||||||
|  |  | ||||||
| 		print; | 		print; | ||||||
| 		$in_hunk = /^$COLOR*[\@ ]/; | 		$in_hunk = /^$GRAPH*$COLOR*[\@ ]/; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	# Most of the time there is enough output to keep things streaming, | 	# Most of the time there is enough output to keep things streaming, | ||||||
|  | @ -163,6 +167,9 @@ sub highlight_pair { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | # we split either by $COLOR or by character. This has the side effect of | ||||||
|  | # leaving in graph cruft. It works because the graph cruft does not contain "-" | ||||||
|  | # or "+" | ||||||
| sub split_line { | sub split_line { | ||||||
| 	local $_ = shift; | 	local $_ = shift; | ||||||
| 	return utf8::decode($_) ? | 	return utf8::decode($_) ? | ||||||
|  | @ -211,8 +218,8 @@ sub is_pair_interesting { | ||||||
| 	my $suffix_a = join('', @$a[($sa+1)..$#$a]); | 	my $suffix_a = join('', @$a[($sa+1)..$#$a]); | ||||||
| 	my $suffix_b = join('', @$b[($sb+1)..$#$b]); | 	my $suffix_b = join('', @$b[($sb+1)..$#$b]); | ||||||
|  |  | ||||||
| 	return $prefix_a !~ /^$COLOR*-$BORING*$/ || | 	return $prefix_a !~ /^$GRAPH*$COLOR*-$BORING*$/ || | ||||||
| 	       $prefix_b !~ /^$COLOR*\+$BORING*$/ || | 	       $prefix_b !~ /^$GRAPH*$COLOR*\+$BORING*$/ || | ||||||
| 	       $suffix_a !~ /^$BORING*$/ || | 	       $suffix_a !~ /^$BORING*$/ || | ||||||
| 	       $suffix_b !~ /^$BORING*$/; | 	       $suffix_b !~ /^$BORING*$/; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -209,7 +209,7 @@ test_expect_failure 'diff-highlight highlights mismatched hunk size' ' | ||||||
|  |  | ||||||
| # TODO add multi-byte test | # TODO add multi-byte test | ||||||
|  |  | ||||||
| test_expect_failure 'diff-highlight works with the --graph option' ' | test_expect_success 'diff-highlight works with the --graph option' ' | ||||||
| 	dh_test_setup_history && | 	dh_test_setup_history && | ||||||
|  |  | ||||||
| 	# topo-order so that the order of the commits is the same as with --graph | 	# topo-order so that the order of the commits is the same as with --graph | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Brian Henderson
						Brian Henderson