-
Notifications
You must be signed in to change notification settings - Fork 334
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
Closed
RyanKoppenhaver-NCC
wants to merge
4
commits into
so-fancy:next
from
RyanKoppenhaver-NCC:arbitrary-diff-improvements
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
50712aa
Match filename lines including arbitrary arguments.
RyanKoppenhaver-NCC 61519ba
manually color fragments
RyanKoppenhaver-NCC f5b0774
highlight "Only in ..." lines as meta
RyanKoppenhaver-NCC 7d4374f
Simpler regex, more comments.
RyanKoppenhaver-NCC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.