|
59 | 59 | ######################################## |
60 | 60 | # Check for "@@ -3,41 +3,63 @@" syntax # |
61 | 61 | ######################################## |
62 | | - } elsif ($change_hunk_indicators && $line =~ /^${ansi_sequence_regex}@@@* (.+?) @@@*(.*)/) { |
63 | | - my $file_str = $4; |
| 62 | + } elsif ($change_hunk_indicators && $line =~ /^${ansi_sequence_regex}(@@@* .+? @@@*)(.*)/) { |
| 63 | + |
| 64 | + my $hunk_header = $4; |
64 | 65 | my $remain = $5; |
65 | 66 |
|
66 | 67 | if ($1) { |
67 | 68 | print $1; # Print out whatever color we're using |
68 | 69 | } |
69 | 70 |
|
70 | | - my ($start_line) = $file_str =~ m/\+(\d+)/; |
71 | | - $start_line = abs($start_line + 0); |
72 | | - |
| 71 | + my ($orig_offset, $orig_count, $new_offset, $new_count) = parse_hunk_header($hunk_header); |
73 | 72 | $last_file_seen = basename($last_file_seen); |
74 | 73 |
|
75 | 74 | # Plus three line for context |
76 | | - print "@ $last_file_seen:" . ($start_line + 3) . " \@${remain}\n"; |
77 | | - #print $line; |
| 75 | + print "@ $last_file_seen:" . ($new_offset + 3) . " \@${remain}\n"; |
| 76 | + |
78 | 77 | ################################### |
79 | 78 | # Remove any new file permissions # |
80 | 79 | ################################### |
|
105 | 104 | } |
106 | 105 | } |
107 | 106 |
|
| 107 | +# Courtesy of github.com/git/git/blob/ab5d01a/git-add--interactive.perl#L798-L805 |
| 108 | +sub parse_hunk_header { |
| 109 | + my ($line) = @_; |
| 110 | + my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) = |
| 111 | + $line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/; |
| 112 | + $o_cnt = 1 unless defined $o_cnt; |
| 113 | + $n_cnt = 1 unless defined $n_cnt; |
| 114 | + return ($o_ofs, $o_cnt, $n_ofs, $n_cnt); |
| 115 | +} |
| 116 | + |
108 | 117 | sub strip_empty_first_line { |
109 | 118 | my $foo = shift(); # Array passed in by reference |
110 | 119 |
|
|
0 commit comments