#!/usr/bin/perl

use warnings;
use strict;

# svn2git.pl
#
# 09/12/2009 09:27:10 PM CEST Dobrica Pavlinusic <dpavlin@rot13.org>

use File::Slurp;

my ( $repo, $rev ) = split(/\s+/, read_file '.svn2git' );

warn "# $repo $rev\n";

system("svn export -r $rev --force $repo .") == 0
	or die "can't checkout revision $rev: $?";

my $log = `svn log $repo -r $rev`;
$log =~ s/^-{72}$//gm;

write_file '/tmp/log', $log;

system "git diff > /tmp/$rev.diff";

die "no changes in revision $rev" if -z "/tmp/$rev.diff";

system "vi -R -o /tmp/log /tmp/$rev.diff";

print "\nenter to commit changes or CTRL+C to abort\n";
<STDIN>;

$rev++;
write_file '/tmp/.svn2git', "$repo $rev";
system "git commit -F /tmp/log -a && mv /tmp/.svn2git .svn2git";

