3 # This tool is copyright (c) 2005, Matthias Urlichs.
4 # It is released under the Gnu Public License, version 2.
6 # The basic idea is to pull and analyze SVN changes.
8 # Checking out the files is done by a single long-running SVN connection.
10 # The head revision is on branch "origin" by default.
11 # You can change that with the '-o' option.
18 use File
::Temp
qw(tempfile);
19 use File
::Path
qw(mkpath);
20 use File
::Basename
qw(basename dirname);
23 use POSIX
qw(strftime dup2);
28 die "Need SVN:Core 1.2.1 or better" if $SVN::Core
::VERSION
lt "1.2.1";
30 $SIG{'PIPE'}="IGNORE";
33 our($opt_h,$opt_o,$opt_v,$opt_u,$opt_C,$opt_i,$opt_m,$opt_M,$opt_t,$opt_T,
34 $opt_b,$opt_r,$opt_I,$opt_A,$opt_s,$opt_l,$opt_d,$opt_D,$opt_S,$opt_F,
39 Usage: ${\basename $0} # fetch/update GIT from SVN
40 [-o branch-for-HEAD] [-h] [-v] [-l max_rev] [-R repack_each_revs]
41 [-C GIT_repository] [-t tagname] [-T trunkname] [-b branchname]
42 [-d|-D] [-i] [-u] [-r] [-I ignorefilename] [-s start_chg]
43 [-m] [-M regex] [-A author_file] [-S] [-F] [-P project_name] [SVN_URL]
48 getopts
("A:b:C:dDFhiI:l:mM:o:rs:t:T:SP:R:uv") or usage
();
51 my $tag_name = $opt_t || "tags";
52 my $trunk_name = defined $opt_T ?
$opt_T : "trunk";
53 my $branch_name = $opt_b || "branches";
54 my $project_name = $opt_P || "";
55 $project_name = "/" . $project_name if ($project_name);
56 my $repack_after = $opt_R || 1000;
57 my $root_pool = SVN
::Pool
->new_default;
59 @ARGV == 1 or @ARGV == 2 or usage
();
63 my $git_tree = $opt_C;
66 my $svn_url = $ARGV[0];
67 my $svn_dir = $ARGV[1];
71 my $branch_esc = quotemeta ($branch_name);
72 my $trunk_esc = quotemeta ($trunk_name);
75 qr!\b(?:merg(?:ed?|ing))\b.*?\b((?:(?<=$branch_esc/)[\w\.\-]+)|(?:$trunk_esc))\b!i,
76 qr!\b(?:from|of)\W+((?:(?<=$branch_esc/)[\w\.\-]+)|(?:$trunk_esc))\b!i,
77 qr!\b(?:from|of)\W+(?:the )?([\w\.\-]+)[-\s]branch\b!i
81 unshift (@mergerx, qr/$opt_M/);
84 # Absolutize filename now, since we will have chdir'ed by the time we
85 # get around to opening it.
86 $opt_A = File
::Spec
->rel2abs($opt_A) if $opt_A;
89 our $users_file = undef;
91 $users_file = File
::Spec
->rel2abs(@_);
92 die "Cannot open $users_file\n" unless -f
$users_file;
93 open(my $authors,$users_file);
96 next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
97 (my $user,my $name,my $email) = ($1,$2,$3);
98 $users{$user} = [$name,$email];
103 select(STDERR
); $|=1; select(STDOUT
);
107 # Basic SVN connection.
108 # We're only interested in connecting and downloading, so ...
111 use File
::Temp
qw(tempfile);
112 use POSIX
qw(strftime dup2);
113 use Fcntl
qw(SEEK_SET);
116 my($what,$repo) = @_;
117 $what=ref($what) if ref($what);
120 $self->{'buffer'} = "";
124 $self->{'fullrep'} = $repo;
132 my $repo = $self->{'fullrep'};
133 my $auth = SVN
::Core
::auth_open
([SVN
::Client
::get_simple_provider
,
134 SVN
::Client
::get_ssl_server_trust_file_provider
,
135 SVN
::Client
::get_username_provider
]);
136 my $s = SVN
::Ra
->new(url
=> $repo, auth
=> $auth, pool
=> $root_pool);
137 die "SVN connection to $repo: $!\n" unless defined $s;
139 $self->{'repo'} = $repo;
140 $self->{'maxrev'} = $s->get_latest_revnum();
144 my($self,$path,$rev) = @_;
146 my ($fh, $name) = tempfile
('gitsvn.XXXXXX',
147 DIR
=> File
::Spec
->tmpdir(), UNLINK
=> 1);
149 print "... $rev $path ...\n" if $opt_v;
150 my (undef, $properties);
152 my $subpool = SVN
::Pool
::new_default_sub
;
153 eval { (undef, $properties)
154 = $self->{'svn'}->get_file($path,$rev,$fh); };
156 return undef if $@
=~ /Attempted to get checksum/;
160 if (exists $properties->{'svn:executable'}) {
162 } elsif (exists $properties->{'svn:special'}) {
163 my ($special_content, $filesize);
164 $filesize = tell $fh;
165 seek $fh, 0, SEEK_SET
;
166 read $fh, $special_content, $filesize;
167 if ($special_content =~ s/^link //) {
169 seek $fh, 0, SEEK_SET
;
171 print $fh $special_content;
173 die "unexpected svn:special file encountered";
180 return ($name, $mode);
184 my($self,$path,$rev) = @_;
186 print "... $rev $path ...\n" if $opt_v;
188 my $subpool = SVN
::Pool
::new_default_sub
;
189 my (undef,undef,$properties)
190 = $self->{'svn'}->get_dir($path,$rev,undef);
191 if (exists $properties->{'svn:ignore'}) {
192 my ($fh, $name) = tempfile
('gitsvn.XXXXXX',
193 DIR
=> File
::Spec
->tmpdir(),
195 print $fh $properties->{'svn:ignore'};
204 my($self,$path,$rev) = @_;
206 my $subpool = SVN
::Pool
::new_default_sub
;
207 my ($dirents,undef,$properties)
208 = $self->{'svn'}->get_dir($path,$rev,undef);
216 $svn .= "/$svn_dir" if defined $svn_dir;
217 my $svn2 = SVNconn
->new($svn);
218 $svn = SVNconn
->new($svn);
221 if($opt_d or $opt_D) {
222 $svn_url = URI
->new($svn_url)->canonical;
224 $svn_dir =~ s
#/*$#/#;
228 if ($svn_url->scheme eq "http") {
230 $lwp_ua = LWP
::UserAgent
->new(keep_alive
=> 1, requests_redirectable
=> []);
232 print STDERR
"Warning: not HTTP; turning off direct file access\n";
239 $d =~ m
#(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)#
240 or die "Unparseable date: $d\n";
241 my $y=$1; $y-=1900 if $y>1900;
242 return timegm
($6||0,$5,$4,$3,$2-1,$y);
252 sub get_headref
($$) {
257 if (open(C
,"$git_dir/refs/heads/$name")) {
261 or die "Cannot get head id for $name ($sha): $!\n";
268 or mkdir($git_tree,0777)
269 or die "Could not create $git_tree: $!";
272 my $orig_branch = "";
273 my $forward_master = 0;
276 my $git_dir = $ENV{"GIT_DIR"} || ".git";
277 $git_dir = getwd
()."/".$git_dir unless $git_dir =~ m
#^/#;
278 $ENV{"GIT_DIR"} = $git_dir;
280 $orig_git_index = $ENV{GIT_INDEX_FILE
} if exists $ENV{GIT_INDEX_FILE
};
281 my ($git_ih, $git_index) = tempfile
('gitXXXXXX', SUFFIX
=> '.idx',
282 DIR
=> File
::Spec
->tmpdir());
284 $ENV{GIT_INDEX_FILE
} = $git_index;
288 my $current_rev = $opt_s || 1;
289 unless(-d
$git_dir) {
291 die "Cannot init the GIT db at $git_tree: $?\n" if $?
;
292 system("git-read-tree");
293 die "Cannot init an empty tree: $?\n" if $?
;
295 $last_branch = $opt_o;
298 -f
"$git_dir/refs/heads/$opt_o"
299 or die "Branch '$opt_o' does not exist.\n".
300 "Either use the correct '-o branch' option,\n".
301 "or import to a new repository.\n";
303 -f
"$git_dir/svn2git"
304 or die "'$git_dir/svn2git' does not exist.\n".
305 "You need that file for incremental imports.\n";
306 open(F
, "git-symbolic-ref HEAD |") or
307 die "Cannot run git-symbolic-ref: $!\n";
308 chomp ($last_branch = <F
>);
309 $last_branch = basename
($last_branch);
311 unless($last_branch) {
312 warn "Cannot read the last branch name: $! -- assuming 'master'\n";
313 $last_branch = "master";
315 $orig_branch = $last_branch;
316 $last_rev = get_headref
($orig_branch, $git_dir);
317 if (-f
"$git_dir/SVN2GIT_HEAD") {
320 Make sure your working directory corresponds to HEAD and remove SVN2GIT_HEAD.
323 git-read-tree -m -u SVN2GIT_HEAD HEAD
326 system('cp', "$git_dir/HEAD", "$git_dir/SVN2GIT_HEAD");
329 $opt_o ne 'master' && -f
"$git_dir/refs/heads/master" &&
330 system('cmp', '-s', "$git_dir/refs/heads/master",
331 "$git_dir/refs/heads/$opt_o") == 0;
334 system('git-read-tree', $last_rev);
335 die "read-tree failed: $?\n" if $?
;
337 # Get the last import timestamps
338 open my $B,"<", "$git_dir/svn2git";
341 my($num,$branch,$ref) = split;
342 $branches{$branch}{$num} = $ref;
343 $branches{$branch}{"LAST"} = $ref;
344 $current_rev = $num+1 if $current_rev <= $num;
349 or die "Could not create git subdir ($git_dir).\n";
351 my $default_authors = "$git_dir/svn-authors";
354 copy
($opt_A,$default_authors) or die "Copy failed: $!";
356 read_users
($default_authors) if -f
$default_authors;
359 open BRANCHES
,">>", "$git_dir/svn2git";
362 my ($svnpath, $revision) = @_;
364 my $subpool = SVN
::Pool
::new_default_sub
;
365 my $kind = $svn->{'svn'}->check_path($svnpath,$revision);
370 my($svnpath,$rev,$path) = @_;
377 # /svn/!svn/bc/2/django/trunk/django-docs/build.py
378 my $url=$svn_url->clone();
379 $url->path($url->path."/!svn/bc/$rev/$svn_dir$svnpath");
380 print "... $path...\n" if $opt_v;
381 $req = HTTP
::Request
->new(GET
=> $url);
382 $res = $lwp_ua->request($req);
383 if ($res->is_success) {
385 ($fh, $name) = tempfile
('gitsvn.XXXXXX',
386 DIR
=> File
::Spec
->tmpdir(), UNLINK
=> 1);
387 print $fh $res->content;
388 close($fh) or die "Could not write $name: $!\n";
390 return undef if $res->code == 301; # directory?
391 die $res->status_line." at $url\n";
393 $mode = '0644'; # can't obtain mode via direct http request?
395 ($name,$mode) = $svn->file("$svnpath",$rev);
396 return undef unless defined $name;
399 my $pid = open(my $F, '-|');
400 die $! unless defined $pid;
402 exec("git-hash-object", "-w", $name)
403 or die "Cannot create object: $!\n";
409 return [$mode, $sha, $path];
412 sub get_ignore
($$$$$) {
413 my($new,$old,$rev,$path,$svnpath) = @_;
415 return unless $opt_I;
416 my $name = $svn->ignore("$svnpath",$rev);
420 $path = File
::Spec
->catfile($path,$opt_I);
423 my $pid = open(my $F, '-|');
424 die $! unless defined $pid;
426 exec("git-hash-object", "-w", $name)
427 or die "Cannot create object: $!\n";
433 push(@
$new,['0644',$sha,$path]);
434 } elsif (defined $old) {
441 my ($path, $project) = @_;
443 $path = "/".$path unless ($path =~ m
#^\/#) ;
444 return $1 if ($path =~ m
#^$project\/(.*)$#);
446 $path =~ s
#\.#\\\.#g;
447 $path =~ s
#\+#\\\+#g;
448 return "/" if ($project =~ m
#^$path.*$#);
457 if($path =~ s
#^/\Q$tag_name\E/([^/]+)/?##) {
459 } elsif($path =~ s
#^/\Q$trunk_name\E/?##) {
461 } elsif($path =~ s
#^/\Q$branch_name\E/([^/]+)/?##) {
469 print STDERR
"$rev: Unrecognized path: $path\n" unless (defined $no_error{$path});
474 } elsif ($project_name) {
475 $path = project_path
($path, $project_name);
477 return ($branch,$path);
482 my ($srcbranch,$uptorev) = @_;
484 my $bbranches = $branches{$srcbranch};
485 my @revs = reverse sort { ($a eq 'LAST' ?
0 : $a) <=> ($b eq 'LAST' ?
0 : $b) } keys %$bbranches;
487 foreach my $arev(@revs) {
488 next if ($arev eq 'LAST');
489 if ($arev <= $uptorev) {
497 sub expand_svndir
($$$);
499 sub expand_svndir
($$$)
501 my ($svnpath, $rev, $path) = @_;
503 get_ignore
(\
@list, undef, $rev, $path, $svnpath);
504 my $dirents = $svn->dir_list($svnpath, $rev);
505 foreach my $p(keys %$dirents) {
506 my $kind = node_kind
($svnpath.'/'.$p, $rev);
507 if ($kind eq $SVN::Node
::file
) {
508 my $f = get_file
($svnpath.'/'.$p, $rev, $path.'/'.$p);
509 push(@list, $f) if $f;
510 } elsif ($kind eq $SVN::Node
::dir
) {
512 expand_svndir
($svnpath.'/'.$p, $rev, $path.'/'.$p));
518 sub copy_path
($$$$$$$$) {
519 # Somebody copied a whole subdirectory.
520 # We need to find the index entries from the old version which the
521 # SVN log entry points to, and add them to the new place.
523 my($newrev,$newbranch,$path,$oldpath,$rev,$node_kind,$new,$parents) = @_;
525 my($srcbranch,$srcpath) = split_path
($rev,$oldpath);
526 unless(defined $srcbranch && defined $srcpath) {
527 print "Path not found when copying from $oldpath @ $rev.\n".
528 "Will try to copy from original SVN location...\n"
530 push (@
$new, expand_svndir
($oldpath, $rev, $path));
533 my $therev = branch_rev
($srcbranch, $rev);
534 my $gitrev = $branches{$srcbranch}{$therev};
536 print STDERR
"$newrev:$newbranch: could not find $oldpath \@ $rev\n";
539 if ($srcbranch ne $newbranch) {
540 push(@
$parents, $branches{$srcbranch}{'LAST'});
542 print "$newrev:$newbranch:$path: copying from $srcbranch:$srcpath @ $rev\n" if $opt_v;
543 if ($node_kind eq $SVN::Node
::dir
) {
544 $srcpath =~ s
#/*$#/#;
547 my $pid = open my $f,'-|';
548 die $! unless defined $pid;
550 exec("git-ls-tree","-r","-z",$gitrev,$srcpath)
556 my($m,$p) = split(/\t/,$_,2);
557 my($mode,$type,$sha1) = split(/ /,$m);
558 next if $type ne "blob";
559 if ($node_kind eq $SVN::Node
::dir
) {
560 $p = $path . substr($p,length($srcpath)-1);
564 push(@
$new,[$mode,$sha1,$p]);
567 print STDERR
"$newrev:$newbranch: could not list files in $oldpath \@ $rev\n";
571 my($branch, $changed_paths, $revision, $author, $date, $message) = @_;
572 my($committer_name,$committer_email,$dest);
573 my($author_name,$author_email);
574 my(@old,@new,@parents);
576 if (not defined $author or $author eq "") {
577 $committer_name = $committer_email = "unknown";
578 } elsif (defined $users_file) {
579 die "User $author is not listed in $users_file\n"
580 unless exists $users{$author};
581 ($committer_name,$committer_email) = @
{$users{$author}};
582 } elsif ($author =~ /^(.*?)\s+<(.*)>$/) {
583 ($committer_name, $committer_email) = ($1, $2);
585 $author =~ s/^<(.*)>$/$1/;
586 $committer_name = $committer_email = $author;
589 if ($opt_F && $message =~ /From:\s+(.*?)\s+<(.*)>\s*\n/) {
590 ($author_name, $author_email) = ($1, $2);
591 print "Author from From: $1 <$2>\n" if ($opt_v);;
592 } elsif ($opt_S && $message =~ /Signed-off-by:\s+(.*?)\s+<(.*)>\s*\n/) {
593 ($author_name, $author_email) = ($1, $2);
594 print "Author from Signed-off-by: $1 <$2>\n" if ($opt_v);;
596 $author_name = $committer_name;
597 $author_email = $committer_email;
600 $date = pdate
($date);
604 if($branch eq "/") { # trunk
606 } elsif($branch =~ m
#^/(.+)#) { # tag
609 } else { # "normal" branch
615 my $prev = $changed_paths->{"/"};
616 if($prev and $prev->[0] eq "A") {
617 delete $changed_paths->{"/"};
618 my $oldpath = $prev->[1];
620 if(defined $oldpath) {
622 ($parent,$p) = split_path
($revision,$oldpath);
623 if(defined $parent) {
627 $parent =~ s
#^/##; # if it's a tag
636 if($revision > $opt_s and defined $parent) {
637 open(H
,'-|',"git-rev-parse","--verify",$parent);
640 print STDERR
"$revision: cannot find commit '$parent'!\n";
644 if(length($rev) != 40) {
645 print STDERR
"$revision: cannot find commit '$parent'!\n";
648 $rev = $branches{($parent eq $opt_o) ?
"/" : $parent}{"LAST"};
649 if($revision != $opt_s and not $rev) {
650 print STDERR
"$revision: do not know ancestor for '$parent'!\n";
657 # if($prev and $prev->[0] eq "A") {
659 # unless(open(H,"> $git_dir/refs/heads/$branch")) {
660 # print STDERR "$revision: Could not create branch $branch: $!\n";
665 # or die "Could not write branch $branch: $!";
667 # or die "Could not write branch $branch: $!";
670 if(not defined $rev) {
672 } elsif ($rev ne $last_rev) {
673 print "Switching from $last_rev to $rev ($branch)\n" if $opt_v;
674 system("git-read-tree", $rev);
675 die "read-tree failed for $rev: $?\n" if $?
;
679 push (@parents, $rev) if defined $rev;
682 if($tag and not %$changed_paths) {
685 my @paths = sort keys %$changed_paths;
686 foreach my $path(@paths) {
687 my $action = $changed_paths->{$path};
689 if ($action->[0] eq "R") {
690 # refer to a file/tree in an earlier commit
691 push(@old,$path); # remove any old stuff
693 if(($action->[0] eq "A") || ($action->[0] eq "R")) {
694 my $node_kind = node_kind
($action->[3], $revision);
695 if ($node_kind eq $SVN::Node
::file
) {
696 my $f = get_file
($action->[3],
701 my $opath = $action->[3];
702 print STDERR
"$revision: $branch: could not fetch '$opath'\n";
704 } elsif ($node_kind eq $SVN::Node
::dir
) {
706 copy_path
($revision, $branch,
708 $action->[2], $node_kind,
711 get_ignore
(\
@new, \
@old, $revision,
712 $path, $action->[3]);
715 } elsif ($action->[0] eq "D") {
717 } elsif ($action->[0] eq "M") {
718 my $node_kind = node_kind
($action->[3], $revision);
719 if ($node_kind eq $SVN::Node
::file
) {
720 my $f = get_file
($action->[3],
723 } elsif ($node_kind eq $SVN::Node
::dir
) {
724 get_ignore
(\
@new, \
@old, $revision,
725 $path, $action->[3]);
728 die "$revision: unknown action '".$action->[0]."' for $path\n";
735 @o1 = splice(@old,0,50);
740 my $pid = open my $F, "-|";
741 die "$!" unless defined $pid;
743 exec("git-ls-files", "-z", @o1) or die $!;
756 @o2 = splice(@o1,0,50);
761 system("git-update-index","--force-remove","--",@o2);
762 die "Cannot remove files: $?\n" if $?
;
768 @n2 = splice(@new,0,10);
773 system("git-update-index","--add",
774 (map { ('--cacheinfo', @
$_) } @n2));
775 die "Cannot add files: $?\n" if $?
;
778 my $pid = open(C
,"-|");
779 die "Cannot fork: $!" unless defined $pid;
781 exec("git-write-tree");
782 die "Cannot exec git-write-tree: $!\n";
784 chomp(my $tree = <C
>);
786 or die "Cannot get tree id ($tree): $!\n";
788 or die "Error running git-write-tree: $?\n";
789 print "Tree ID $tree\n" if $opt_v;
791 my $pr = IO
::Pipe
->new() or die "Cannot open pipe: $!\n";
792 my $pw = IO
::Pipe
->new() or die "Cannot open pipe: $!\n";
794 die "Fork: $!\n" unless defined $pid;
798 open(OUT
,">&STDOUT");
799 dup2
($pw->fileno(),0);
800 dup2
($pr->fileno(),1);
806 # loose detection of merges
807 # based on the commit msg
808 foreach my $rx (@mergerx) {
809 if ($message =~ $rx) {
811 if ($mparent eq 'HEAD') { $mparent = $opt_o };
812 if ( -e
"$git_dir/refs/heads/$mparent") {
813 $mparent = get_headref
($mparent, $git_dir);
814 push (@parents, $mparent);
815 print OUT
"Merge parent branch: $mparent\n" if $opt_v;
819 my %seen_parents = ();
820 my @unique_parents = grep { ! $seen_parents{$_} ++ } @parents;
821 foreach my $bparent (@unique_parents) {
822 push @par, '-p', $bparent;
823 print OUT
"Merge parent branch: $bparent\n" if $opt_v;
827 "GIT_AUTHOR_NAME=$author_name",
828 "GIT_AUTHOR_EMAIL=$author_email",
829 "GIT_AUTHOR_DATE=".strftime
("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
830 "GIT_COMMITTER_NAME=$committer_name",
831 "GIT_COMMITTER_EMAIL=$committer_email",
832 "GIT_COMMITTER_DATE=".strftime
("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
833 "git-commit-tree", $tree,@par);
834 die "Cannot exec git-commit-tree: $!\n";
839 $message =~ s/[\s\n]+\z//;
840 $message = "r$revision: $message" if $opt_r;
842 print $pw "$message\n"
843 or die "Error writing to git-commit-tree: $!\n";
846 print "Committed change $revision:$branch ".strftime
("%Y-%m-%d %H:%M:%S",gmtime($date)).")\n" if $opt_v;
849 or die "Cannot get commit id ($cid): $!\n";
850 print "Commit ID $cid\n" if $opt_v;
854 die "Error running git-commit-tree: $?\n" if $?
;
857 if (not defined $cid) {
858 $cid = $branches{"/"}{"LAST"};
861 if(not defined $dest) {
862 print "... no known parent\n" if $opt_v;
864 print "Writing to refs/heads/$dest\n" if $opt_v;
865 open(C
,">$git_dir/refs/heads/$dest") and
866 print C
("$cid\n") and
868 or die "Cannot write branch $dest for update: $!\n";
872 $last_rev = "-" if %$changed_paths;
873 # the tag was 'complex', i.e. did not refer to a "real" revision
875 $dest =~ tr/_/\./ if $opt_u;
877 system('git-tag', '-f', $dest, $cid) == 0
878 or die "Cannot create tag $dest: $!\n";
880 print "Created tag '$dest' on '$branch'\n" if $opt_v;
882 $branches{$branch}{"LAST"} = $cid;
883 $branches{$branch}{$revision} = $cid;
885 print BRANCHES
"$revision $branch $cid\n";
886 print "DONE: $revision $dest $cid\n" if $opt_v;
890 # Recursive use of the SVN connection does not work
893 my ($changed_paths, $revision, $author, $date, $message) = @_;
895 while(my($path,$action) = each %$changed_paths) {
896 $p{$path} = [ $action->action,$action->copyfrom_path, $action->copyfrom_rev, $path ];
898 $changed_paths = \
%p;
905 while(my($path,$action) = each %$changed_paths) {
906 ($branch,$path) = split_path
($revision,$path);
907 next if not defined $branch;
908 next if not defined $path;
909 $done{$branch}{$path} = $action;
911 while(($branch,$changed_paths) = each %done) {
912 commit
($branch, $changed_paths, $revision, $author, $date, $message);
916 $opt_l = $svn->{'maxrev'} if not defined $opt_l or $opt_l > $svn->{'maxrev'};
918 if ($opt_l < $current_rev) {
919 print "Up to date: no new revisions to fetch!\n" if $opt_v;
920 unlink("$git_dir/SVN2GIT_HEAD");
924 print "Processing from $current_rev to $opt_l ...\n" if $opt_v;
927 my $to_rev = $current_rev - 1;
929 my $subpool = SVN
::Pool
::new_default_sub
;
930 while ($to_rev < $opt_l) {
932 $from_rev = $to_rev + 1;
933 $to_rev = $from_rev + $repack_after;
934 $to_rev = $opt_l if $opt_l < $to_rev;
935 print "Fetching from $from_rev to $to_rev ...\n" if $opt_v;
936 $svn->{'svn'}->get_log("/",$from_rev,$to_rev,0,1,1,\
&commit_all
);
938 die "Fork: $!\n" unless defined $pid;
940 exec("git-repack", "-d")
941 or die "Cannot repack: $!\n";
949 if (defined $orig_git_index) {
950 $ENV{GIT_INDEX_FILE
} = $orig_git_index;
952 delete $ENV{GIT_INDEX_FILE
};
955 # Now switch back to the branch we were in before all of this happened
957 print "DONE\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
958 system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
961 system('git-read-tree', '-m', '-u', 'SVN2GIT_HEAD', 'HEAD');
962 die "read-tree failed: $?\n" if $?
;
965 $orig_branch = "master";
966 print "DONE; creating $orig_branch branch\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
967 system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
968 unless -f
"$git_dir/refs/heads/master";
969 system('git-update-ref', 'HEAD', "$orig_branch");
971 system('git checkout');
972 die "checkout failed: $?\n" if $?
;
975 unlink("$git_dir/SVN2GIT_HEAD");