Skip to content

Commit

Permalink
contrib/git-svn: optimize sequential commits to svn
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Eric Wong authored and Junio C Hamano committed Feb 26, 2006
1 parent 8f22562 commit e17512f
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions contrib/git-svn/git-svn.perl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use File::Path qw/mkpath/;
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
use File::Spec qw//;
use POSIX qw/strftime/;
my $sha1 = qr/[a-f\d]{40}/;
my $sha1_short = qr/[a-f\d]{6,40}/;
my ($_revision,$_stdin,$_no_ignore_ext,$_no_stop_copy,$_help,$_rmdir,$_edit,
Expand Down Expand Up @@ -591,6 +592,7 @@ sub handle_rmdir {
sub svn_commit_tree {
my ($svn_rev, $commit) = @_;
my $commit_msg = "$GIT_DIR/$GIT_SVN/.svn-commit.tmp.$$";
my %log_msg = ( msg => '' );
open my $msg, '>', $commit_msg or croak $!;

chomp(my $type = `git-cat-file -t $commit`);
Expand All @@ -606,6 +608,7 @@ sub svn_commit_tree {
if (!$in_msg) {
$in_msg = 1 if (/^\s*$/);
} else {
$log_msg{msg} .= $_;
print $msg $_ or croak $!;
}
}
Expand All @@ -625,9 +628,30 @@ sub svn_commit_tree {
join("\n",@ci_output),"\n";
my ($rev_committed) = ($committed =~ /^Committed revision (\d+)\./);

# resync immediately
my @svn_up = (qw(svn up), "-r$svn_rev");
my @svn_up = qw(svn up);
push @svn_up, '--ignore-externals' unless $_no_ignore_ext;
if ($rev_committed == ($svn_rev + 1)) {
push @svn_up, "-r$rev_committed";
sys(@svn_up);
my $info = svn_info('.');
my $date = $info->{'Last Changed Date'} or die "Missing date\n";
if ($info->{'Last Changed Rev'} != $rev_committed) {
croak "$info->{'Last Changed Rev'} != $rev_committed\n"
}
my ($Y,$m,$d,$H,$M,$S,$tz) = ($date =~
/(\d{4})\-(\d\d)\-(\d\d)\s
(\d\d)\:(\d\d)\:(\d\d)\s([\-\+]\d+)/x)
or croak "Failed to parse date: $date\n";
$log_msg{date} = "$tz $Y-$m-$d $H:$M:$S";
$log_msg{author} = $info->{'Last Changed Author'};
$log_msg{revision} = $rev_committed;
$log_msg{msg} .= "\n";
my $parent = file_to_s("$REV_DIR/$svn_rev");
git_commit(\%log_msg, $parent, $commit);
return $rev_committed;
}
# resync immediately
push @svn_up, "-r$svn_rev";
sys(@svn_up);
return fetch("$rev_committed=$commit")->{revision};
}
Expand Down Expand Up @@ -724,7 +748,7 @@ sub svn_info {
# only single-lines seem to exist in svn info output
while (<$info_fh>) {
chomp $_;
if (m#^([^:]+)\s*:\s*(\S*)$#) {
if (m#^([^:]+)\s*:\s*(\S.*)$#) {
$ret->{$1} = $2;
push @{$ret->{-order}}, $1;
}
Expand Down

0 comments on commit e17512f

Please sign in to comment.