As the size of the hunk gets bigger, it becomes harder to jump back and forth between the removed and added lines, and highlighting becomes less beneficial. We add a new config option called diff-highlight.maxhunksize which controls the maximum size of the hunk allowed for which highlighting is still performed. The default value is set to 20. Signed-off-by: Jonathan Lebon <jonathan.lebon@xxxxxxxxx> --- contrib/diff-highlight/README | 20 ++++++++++++++++++++ contrib/diff-highlight/diff-highlight | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/contrib/diff-highlight/README b/contrib/diff-highlight/README index 885ff2f..ed12be1 100644 --- a/contrib/diff-highlight/README +++ b/contrib/diff-highlight/README @@ -89,6 +89,26 @@ newHighlight = "black #aaffaa" --------------------------------------------- +Max Hunk Config +--------------- + +By default, diff-highlight will not do any highlighting if either the +number of removed or added lines is greater than 20. This is because as +the hunk gets bigger, it becomes harder to jump back and forth between +the removed and added lines, and highlighting becomes less beneficial. + +You can change this default by setting the "diff-highlight.maxhunksize" +configuration. + +Example: + +--------------------------------------------- +# Increase the maximum diff-highlight to 30 +[diff-highlight] +maxhunksize = 30 +--------------------------------------------- + + Bugs ---- diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight index 46556fc..a005146 100755 --- a/contrib/diff-highlight/diff-highlight +++ b/contrib/diff-highlight/diff-highlight @@ -17,6 +17,8 @@ my @NEW_HIGHLIGHT = ( color_config('color.diff-highlight.newreset', $OLD_HIGHLIGHT[2]) ); +my $MAX_HUNK_SIZE = config('diff-highlight.maxhunksize', 20); + my $RESET = "\x1b[m"; my $COLOR = qr/\x1b\[[0-9;]*m/; my $BORING = qr/$COLOR|\s/; @@ -79,6 +81,13 @@ sub color_config { return length($s) ? $s : $default; } +# Also handle our own fallback here to be independent. +sub config { + my ($key, $default) = @_; + my $s = `git config --get $key 2>/dev/null`; + return length($s) ? $s : $default; +} + sub show_hunk { my ($a, $b) = @_; @@ -88,6 +97,13 @@ sub show_hunk { return; } + # Skip highlighting if the hunk gets bigger than the user configured + # limit. + if (@$a > $MAX_HUNK_SIZE || @$b > $MAX_HUNK_SIZE) { + print @$a, @$b; + return; + } + my @queue; match_and_highlight_pairs($a, 0, scalar @$a, $b, 0, scalar @$b, \@queue); print @queue; -- 2.6.0 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html