Skip to content

Commit

Permalink
use parse_hunk_header from git
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Mar 8, 2016
1 parent 48bc5e2 commit 59aebbd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions libs/header_clean/header_clean.pl
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,21 @@
########################################
# Check for "@@ -3,41 +3,63 @@" syntax #
########################################
} elsif ($change_hunk_indicators && $line =~ /^${ansi_sequence_regex}@@@* (.+?) @@@*(.*)/) {
my $file_str = $4;
} elsif ($change_hunk_indicators && $line =~ /^${ansi_sequence_regex}(@@@* .+? @@@*)(.*)/) {

my $hunk_header = $4;
my $remain = $5;

if ($1) {
print $1; # Print out whatever color we're using
}

my ($start_line) = $file_str =~ m/\+(\d+)/;
$start_line = abs($start_line + 0);

my ($orig_offset, $orig_count, $new_offset, $new_count) = parse_hunk_header($hunk_header);
$last_file_seen = basename($last_file_seen);

# Plus three line for context
print "@ $last_file_seen:" . ($start_line + 3) . " \@${remain}\n";
#print $line;
print "@ $last_file_seen:" . ($new_offset + 3) . " \@${remain}\n";

###################################
# Remove any new file permissions #
###################################
Expand Down Expand Up @@ -105,6 +104,16 @@
}
}

# Courtesy of github.com/git/git/blob/ab5d01a/git-add--interactive.perl#L798-L805
sub parse_hunk_header {
my ($line) = @_;
my ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =
$line =~ /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
$o_cnt = 1 unless defined $o_cnt;
$n_cnt = 1 unless defined $n_cnt;
return ($o_ofs, $o_cnt, $n_ofs, $n_cnt);
}

sub strip_empty_first_line {
my $foo = shift(); # Array passed in by reference

Expand Down

0 comments on commit 59aebbd

Please sign in to comment.