Skip to content

Commit

Permalink
added tool to find a specific diff hunk
Browse files Browse the repository at this point in the history
  • Loading branch information
rofl0r committed Mar 28, 2012
1 parent 753dc92 commit 30db00c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions utils/hunkfinder.pl
@@ -0,0 +1,26 @@
#!/usr/bin/env perl
use strict;
use warnings;

#usage: cat mayday.diff | utils/hunkfinder.pl data/init/interface.txt 24

my $filename = $ARGV[0] or die "need filename of diffed file";
my $hunkno = $ARGV[1] or die "need hunknumber as second arg";

my $infile = 0;
my $hunk = 0;
my $switched = 0;

while(<STDIN>) {
$switched = 0;
$infile = 1, $switched = 1 if(!$infile && /^diff (.*?)\Q$filename\E/);
if($infile) {
if(/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/) {
$hunk++;
}
if($hunk == $hunkno) {
print;
}
$infile = 0 if(!$switched && /^diff /);
}
}

0 comments on commit 30db00c

Please sign in to comment.