hjp: Programs: svnsearch

svnsearch

A simple Perl script to search backwards through a subversion repository for a given pattern.

 1: #!/usr/bin/perl
 2: use warnings;
 3: use strict;
 4: 
 5: my $pattern = shift;
 6: 
 7: push @ARGV, "." unless (@ARGV);
 8: 
 9: for my $target (@ARGV) {
10:     open(my $svnlog_fh, '-|', 'svn', 'log', $target) or die "cannot invoke svn log $target: $!";
11:     my $atstart;
12:     while (<$svnlog_fh>) {
13:         if (/^------------------------------------------------------------------------$/) {
14:             $atstart = 1;
15:             next;
16:         }
17:         if ($atstart && /^r(\d+) \| /) {
18:             my $revline = $_;
19:             chomp $revline;
20:             my $revision = $1;
21:             open(my $svndiff_fh, '-|', 'svn', 'diff', "-c$revision", $target) or die "cannot invoke svn diff -c$revision $target: $!";
22:             local $/ = undef;
23:             my $diff = <$svndiff_fh>;
24:             if ($diff =~ m/$pattern/) {
25:                 print "\n=== $revline ===\n$diff\n======\n\n";
26:             }
27:         }
28:         $atstart = 0;
29:     }
30: }
31: 
32: # vim: tw=0
33: 
download
$Date$
vim: sw=2