contrib/git-svn: optimize sequential commits to svn
Avoid running 'svn up' to a previous revision if we know the revision we just committed is the first descendant of the revision we came from. This reduces the time to do a series of commits by about 25%. Signed-off-by: Eric Wong <normalperson@yhbt.net> Signed-off-by: Junio C Hamano <junkio@cox.net>
Eric Wong committed
Feb 26, 2006 at 02:22 UTC
e17512f3de13b6af24672822b703ee54aa057582
1 file changed
+27
-3
contrib/git-svn/git-svn.perl
+27
-3
@@ -30,6 +30,7 @@ use File::Basename qw/dirname basename/;
30
use File::Path qw/mkpath/;
31
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
32
use File::Spec qw//;
33
+use POSIX qw/strftime/;
34
my $sha1 = qr/[a-f\d]{40}/;
35
my $sha1_short = qr/[a-f\d]{6,40}/;
36
my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
@@ -591,6 +592,7 @@ sub handle_rmdir {
592
sub svn_commit_tree {
593
my ($svn_rev, $commit) = @_;
594
my $commit_msg = "$GIT_DIR/$GIT_SVN/.svn-commit.tmp.$$";
595
+ my %log_msg = ( msg => '' );
596
open my $msg, '>', $commit_msg or croak $!;
597
598
chomp(my $type = `git-cat-file -t $commit`);
@@ -606,6 +608,7 @@ sub svn_commit_tree {
608
if (!$in_msg) {
609
$in_msg = 1 if (/^\s*$/);
610
} else {
611
+ $log_msg{msg} .= $_;
612
print $msg $_ or croak $!;
613
}
614
}
@@ -625,9 +628,30 @@ sub svn_commit_tree {
628
join("\n",@ci_output),"\n";
629
my ($rev_committed) = ($committed =~ /^Committed revision (\d+)\./);
630
628
- # resync immediately
629
- my @svn_up = (qw(svn up), "-r$svn_rev");
631
+ my @svn_up = qw(svn up);
632
push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
633
+ if ($rev_committed == ($svn_rev + 1)) {
634
+ push @svn_up, "-r$rev_committed";
635
+ sys(@svn_up);
636
+ my $info = svn_info('.');
637
+ my $date = $info->{'Last Changed Date'} or die "Missing date\n";
638
+ if ($info->{'Last Changed Rev'} != $rev_committed) {
639
+ croak "$info->{'Last Changed Rev'} != $rev_committed\n"
640
+ }
641
+ my ($Y,$m,$d,$H,$M,$S,$tz) = ($date =~
642
+ /(\d{4})\-(\d\d)\-(\d\d)\s
643
+ (\d\d)\:(\d\d)\:(\d\d)\s([\-\+]\d+)/x)
644
+ or croak "Failed to parse date: $date\n";
645
+ $log_msg{date} = "$tz $Y-$m-$d $H:$M:$S";
646
+ $log_msg{author} = $info->{'Last Changed Author'};
647
+ $log_msg{revision} = $rev_committed;
648
+ $log_msg{msg} .= "\n";
649
+ my $parent = file_to_s("$REV_DIR/$svn_rev");
650
+ git_commit(\%log_msg, $parent, $commit);
651
+ return $rev_committed;
652
+ }
653
+ # resync immediately
654
+ push @svn_up, "-r$svn_rev";
655
sys(@svn_up);
656
return fetch("$rev_committed=$commit")->{revision};
657
}
@@ -724,7 +748,7 @@ sub svn_info {
748
# only single-lines seem to exist in svn info output
749
while (<$info_fh>) {
750
chomp $_;
727
- if (m#^([^:]+)\s*:\s*(\S*)$#) {
751
+ if (m#^([^:]+)\s*:\s*(\S.*)$#) {
752
$ret->{$1} = $2;
753
push @{$ret->{-order}}, $1;
754
}