-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arbitrary diff improvements #293
Changes from 3 commits
50712aa
61519ba
f5b0774
7d4374f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,21 +163,37 @@ sub do_dsf_stuff { | |
######################### | ||
# Look for the filename # | ||
######################### | ||
# $4 $5 | ||
} elsif ($line =~ /^${ansi_color_regex}diff (-r|--git|--cc) (.+?)(\s|\e|$)/) { | ||
} elsif ($line =~ /^${ansi_color_regex}diff (.*)/) { | ||
my $diff_args = $4; | ||
|
||
# Mercurial looks like: diff -r 82e55d328c8c hello.c | ||
if ($4 eq "-r") { | ||
if ($diff_args =~ /^-r [0-9a-f]+ /) { | ||
$is_mercurial = 1; | ||
$meta_color ||= get_config_color("meta"); | ||
|
||
# Git looks like: diff --git a/diff-so-fancy b/diff-so-fancy | ||
} elsif ($diff_args =~ /^(?:--git|--cc) (.+?)(\s|\e|$)/) { | ||
$last_file_seen = $1; | ||
|
||
# Otherwise, last two args are file names. Assume they have no | ||
# spaces, as "a b c" is ambiguous anyway. | ||
} else { | ||
$last_file_seen = $5; | ||
$diff_args =~ s/\e.*$//; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do these two lines do? Can you at least add a comment on what these regexp replaces accomplish. Maybe a before and after so we know what the strings should look like? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added comments. |
||
$diff_args =~ /([^ ]+) [^ ]+$/; | ||
$last_file_seen = $1; | ||
} | ||
|
||
$last_file_seen =~ s|^\w/||; # Remove a/ (and handle diff.mnemonicPrefix). | ||
$in_hunk = 0; | ||
######################################## | ||
# Look for added / removed files (non git, non -N) | ||
######################################## | ||
} elsif ($line =~ /^${ansi_color_regex}Only in /) { | ||
unless ($1) { | ||
print get_config_color("meta"); | ||
} | ||
print $line; | ||
######################################## | ||
# Find the first file: --- a/README.md # | ||
######################################## | ||
} elsif (!$in_hunk && $line =~ /^$ansi_color_regex--- (\w\/)?(.+?)(\e|\t|$)/) { | ||
|
@@ -238,6 +254,8 @@ sub do_dsf_stuff { | |
|
||
if ($1) { | ||
print $1; # Print out whatever color we're using | ||
} elsif ($manually_color_lines) { | ||
print get_config_color("frag"); | ||
} | ||
|
||
my ($orig_offset, $orig_count, $new_offset, $new_count) = parse_hunk_header($hunk_header); | ||
|
@@ -800,6 +818,8 @@ sub color { | |
if ($str eq "meta") { | ||
# Default ANSI yellow | ||
$ret = DiffHighlight::color_config('color.diff.meta', color(11)); | ||
} elsif ($str eq "frag") { | ||
$ret = DiffHighlight::color_config('color.diff.frag', color('bold') . color(13)); | ||
} elsif ($str eq "reset") { | ||
$ret = color("reset"); | ||
} elsif ($str eq "add_line") { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Only in new: added.txt | ||
Only in old: deleted.txt | ||
diff -ur old/modified.txt new/modified.txt | ||
--- old/modified.txt 2018-03-22 11:45:03.000000000 -0700 | ||
+++ new/modified.txt 2018-03-22 11:45:11.000000000 -0700 | ||
@@ -1 +1 @@ | ||
-this is the old version | ||
+this is the new version | ||
diff -ur old/modified2.txt new/modified2.txt | ||
--- old/modified2.txt 2018-03-22 13:23:01.000000000 -0700 | ||
+++ new/modified2.txt 2018-03-22 13:23:16.000000000 -0700 | ||
@@ -1,6 +1,6 @@ | ||
context1 | ||
context2 | ||
-old stuff 1 | ||
+new stuff 1 | ||
context3 | ||
context4 | ||
context5 | ||
@@ -8,4 +8,4 @@ | ||
context7 | ||
context8 | ||
context9 | ||
-old stuff 2 | ||
+new stuff 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?:
is a non-capturing parenthesis right? I don't use this syntax very often so this might confuse me in the future. Is there a reason to do this, and not just have$last_file_seen = $2
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I used it out of a vague sense that it's more efficient, but even if it is, I'm sure it's trivial, so I'll switch it.