Friday, May 2, 2008

Finding Recent SVN Commits

Here's a quick Perl script I whipped up to ease finding newly committed files in our subversion repository. It's a little cleaner than what the client provides and nice to quickly find changes.

#!/usr/bin/perl -w

#
# quick script to succinctly display SVN changes since a given date
# usage: svnsince.pl YYYY-MM-DD HH:MM
#

use strict;
use Date::Calc qw(Date_to_Time);

if (!defined($ARGV[0]) || $ARGV[0] !~ /^\d\d\d\d-\d\d-\d\d$/) {
die("Invalid date. Usage: $0 YYYY-MM-DD HH:MM.");
}

if (!defined($ARGV[1]) || $ARGV[1] !~ /^\d\d:\d\d$/) {
die("Invalid time. Usage: $0 YYYY-MM-DD HH:MM.");
}

my $date_thresh = date_to_epoch($ARGV[0], $ARGV[1]);
my $svn_file = "";
my $svn_date = "";
open(SVN, "svn info -R |") || die("Can't run svn client: $!");

while (<SVN>) {
if (/^Path: (.+)/) {
$svn_file = $1;
}

if (/^Last Changed Date: (\d\d\d\d-\d\d-\d\d) (\d\d:\d\d)/) {
$svn_date = date_to_epoch($1, $2);
if ($svn_date >= $date_thresh) {
print "$1 $2 $svn_file\n";
}
}
}
close(SVN);

sub date_to_epoch {
my ($date, $time) = @_;
my ($year, $month, $day) = split(/-/, $date);
my ($hour, $minute) = split(/:/, $time);
return Date_to_Time($year, $month, $day, $hour, $minute, 0);
}

1 comment:

Anonymous said...

Very useful - thanks.