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 = $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;
58 @ARGV == 1 or @ARGV == 2 or usage
();
62 my $git_tree = $opt_C;
65 my $svn_url = $ARGV[0];
66 my $svn_dir = $ARGV[1];
70 my $branch_esc = quotemeta ($branch_name);
71 my $trunk_esc = quotemeta ($trunk_name);
74 qr!\b(?:merg(?:ed?|ing))\b.*?\b((?:(?<=$branch_esc/)[\w\.\-]+)|(?:$trunk_esc))\b!i,
75 qr!\b(?:from|of)\W+((?:(?<=$branch_esc/)[\w\.\-]+)|(?:$trunk_esc))\b!i,
76 qr!\b(?:from|of)\W+(?:the )?([\w\.\-]+)[-\s]branch\b!i
80 unshift (@mergerx, qr/$opt_M/);
83 # Absolutize filename now, since we will have chdir'ed by the time we
84 # get around to opening it.
85 $opt_A = File
::Spec
->rel2abs($opt_A) if $opt_A;
88 our $users_file = undef;
90 $users_file = File
::Spec
->rel2abs(@_);
91 die "Cannot open $users_file\n" unless -f
$users_file;
92 open(my $authors,$users_file);
95 next unless /^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/;
96 (my $user,my $name,my $email) = ($1,$2,$3);
97 $users{$user} = [$name,$email];
102 select(STDERR
); $|=1; select(STDOUT
);
106 # Basic SVN connection.
107 # We're only interested in connecting and downloading, so ...
110 use File
::Temp
qw(tempfile);
111 use POSIX
qw(strftime dup2);
112 use Fcntl
qw(SEEK_SET);
115 my($what,$repo) = @_;
116 $what=ref($what) if ref($what);
119 $self->{'buffer'} = "";
123 $self->{'fullrep'} = $repo;
131 my $repo = $self->{'fullrep'};
132 my $auth = SVN
::Core
::auth_open
([SVN
::Client
::get_simple_provider
,
133 SVN
::Client
::get_ssl_server_trust_file_provider
,
134 SVN
::Client
::get_username_provider
]);
135 my $s = SVN
::Ra
->new(url
=> $repo, auth
=> $auth);
136 die "SVN connection to $repo: $!\n" unless defined $s;
138 $self->{'repo'} = $repo;
139 $self->{'maxrev'} = $s->get_latest_revnum();
143 my($self,$path,$rev) = @_;
145 my ($fh, $name) = tempfile
('gitsvn.XXXXXX',
146 DIR
=> File
::Spec
->tmpdir(), UNLINK
=> 1);
148 print "... $rev $path ...\n" if $opt_v;
149 my (undef, $properties);
150 my $pool = SVN
::Pool
->new();
151 eval { (undef, $properties)
152 = $self->{'svn'}->get_file($path,$rev,$fh,$pool); };
155 return undef if $@
=~ /Attempted to get checksum/;
159 if (exists $properties->{'svn:executable'}) {
161 } elsif (exists $properties->{'svn:special'}) {
162 my ($special_content, $filesize);
163 $filesize = tell $fh;
164 seek $fh, 0, SEEK_SET
;
165 read $fh, $special_content, $filesize;
166 if ($special_content =~ s/^link //) {
168 seek $fh, 0, SEEK_SET
;
170 print $fh $special_content;
172 die "unexpected svn:special file encountered";
179 return ($name, $mode);
183 my($self,$path,$rev) = @_;
185 print "... $rev $path ...\n" if $opt_v;
186 my (undef,undef,$properties)
187 = $self->{'svn'}->get_dir($path,$rev,undef);
188 if (exists $properties->{'svn:ignore'}) {
189 my ($fh, $name) = tempfile
('gitsvn.XXXXXX',
190 DIR
=> File
::Spec
->tmpdir(),
192 print $fh $properties->{'svn:ignore'};
201 my($self,$path,$rev) = @_;
202 my ($dirents,undef,$properties)
203 = $self->{'svn'}->get_dir($path,$rev,undef);
211 $svn .= "/$svn_dir" if defined $svn_dir;
212 my $svn2 = SVNconn
->new($svn);
213 $svn = SVNconn
->new($svn);
216 if($opt_d or $opt_D) {
217 $svn_url = URI
->new($svn_url)->canonical;
219 $svn_dir =~ s
#/*$#/#;
223 if ($svn_url->scheme eq "http") {
225 $lwp_ua = LWP
::UserAgent
->new(keep_alive
=> 1, requests_redirectable
=> []);
227 print STDERR
"Warning: not HTTP; turning off direct file access\n";
234 $d =~ m
#(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)#
235 or die "Unparseable date: $d\n";
236 my $y=$1; $y-=1900 if $y>1900;
237 return timegm
($6||0,$5,$4,$3,$2-1,$y);
247 sub get_headref
($$) {
252 if (open(C
,"$git_dir/refs/heads/$name")) {
256 or die "Cannot get head id for $name ($sha): $!\n";
263 or mkdir($git_tree,0777)
264 or die "Could not create $git_tree: $!";
267 my $orig_branch = "";
268 my $forward_master = 0;
271 my $git_dir = $ENV{"GIT_DIR"} || ".git";
272 $git_dir = getwd
()."/".$git_dir unless $git_dir =~ m
#^/#;
273 $ENV{"GIT_DIR"} = $git_dir;
275 $orig_git_index = $ENV{GIT_INDEX_FILE
} if exists $ENV{GIT_INDEX_FILE
};
276 my ($git_ih, $git_index) = tempfile
('gitXXXXXX', SUFFIX
=> '.idx',
277 DIR
=> File
::Spec
->tmpdir());
279 $ENV{GIT_INDEX_FILE
} = $git_index;
283 my $current_rev = $opt_s || 1;
284 unless(-d
$git_dir) {
285 system("git-init-db");
286 die "Cannot init the GIT db at $git_tree: $?\n" if $?
;
287 system("git-read-tree");
288 die "Cannot init an empty tree: $?\n" if $?
;
290 $last_branch = $opt_o;
293 -f
"$git_dir/refs/heads/$opt_o"
294 or die "Branch '$opt_o' does not exist.\n".
295 "Either use the correct '-o branch' option,\n".
296 "or import to a new repository.\n";
298 -f
"$git_dir/svn2git"
299 or die "'$git_dir/svn2git' does not exist.\n".
300 "You need that file for incremental imports.\n";
301 open(F
, "git-symbolic-ref HEAD |") or
302 die "Cannot run git-symbolic-ref: $!\n";
303 chomp ($last_branch = <F
>);
304 $last_branch = basename
($last_branch);
306 unless($last_branch) {
307 warn "Cannot read the last branch name: $! -- assuming 'master'\n";
308 $last_branch = "master";
310 $orig_branch = $last_branch;
311 $last_rev = get_headref
($orig_branch, $git_dir);
312 if (-f
"$git_dir/SVN2GIT_HEAD") {
315 Make sure your working directory corresponds to HEAD and remove SVN2GIT_HEAD.
318 git-read-tree -m -u SVN2GIT_HEAD HEAD
321 system('cp', "$git_dir/HEAD", "$git_dir/SVN2GIT_HEAD");
324 $opt_o ne 'master' && -f
"$git_dir/refs/heads/master" &&
325 system('cmp', '-s', "$git_dir/refs/heads/master",
326 "$git_dir/refs/heads/$opt_o") == 0;
329 system('git-read-tree', $last_rev);
330 die "read-tree failed: $?\n" if $?
;
332 # Get the last import timestamps
333 open my $B,"<", "$git_dir/svn2git";
336 my($num,$branch,$ref) = split;
337 $branches{$branch}{$num} = $ref;
338 $branches{$branch}{"LAST"} = $ref;
339 $current_rev = $num+1 if $current_rev <= $num;
344 or die "Could not create git subdir ($git_dir).\n";
346 my $default_authors = "$git_dir/svn-authors";
349 copy
($opt_A,$default_authors) or die "Copy failed: $!";
351 read_users
($default_authors) if -f
$default_authors;
354 open BRANCHES
,">>", "$git_dir/svn2git";
357 my ($svnpath, $revision) = @_;
358 my $pool=SVN
::Pool
->new;
359 my $kind = $svn->{'svn'}->check_path($svnpath,$revision,$pool);
365 my($svnpath,$rev,$path) = @_;
372 # /svn/!svn/bc/2/django/trunk/django-docs/build.py
373 my $url=$svn_url->clone();
374 $url->path($url->path."/!svn/bc/$rev/$svn_dir$svnpath");
375 print "... $path...\n" if $opt_v;
376 $req = HTTP
::Request
->new(GET
=> $url);
377 $res = $lwp_ua->request($req);
378 if ($res->is_success) {
380 ($fh, $name) = tempfile
('gitsvn.XXXXXX',
381 DIR
=> File
::Spec
->tmpdir(), UNLINK
=> 1);
382 print $fh $res->content;
383 close($fh) or die "Could not write $name: $!\n";
385 return undef if $res->code == 301; # directory?
386 die $res->status_line." at $url\n";
388 $mode = '0644'; # can't obtain mode via direct http request?
390 ($name,$mode) = $svn->file("$svnpath",$rev);
391 return undef unless defined $name;
394 my $pid = open(my $F, '-|');
395 die $! unless defined $pid;
397 exec("git-hash-object", "-w", $name)
398 or die "Cannot create object: $!\n";
404 return [$mode, $sha, $path];
407 sub get_ignore
($$$$$) {
408 my($new,$old,$rev,$path,$svnpath) = @_;
410 return unless $opt_I;
411 my $name = $svn->ignore("$svnpath",$rev);
415 $path = File
::Spec
->catfile($path,$opt_I);
418 my $pid = open(my $F, '-|');
419 die $! unless defined $pid;
421 exec("git-hash-object", "-w", $name)
422 or die "Cannot create object: $!\n";
428 push(@
$new,['0644',$sha,$path]);
429 } elsif (defined $old) {
436 my ($path, $project) = @_;
438 $path = "/".$path unless ($path =~ m
#^\/#) ;
439 return $1 if ($path =~ m
#^$project\/(.*)$#);
441 $path =~ s
#\.#\\\.#g;
442 $path =~ s
#\+#\\\+#g;
443 return "/" if ($project =~ m
#^$path.*$#);
452 if($path =~ s
#^/\Q$tag_name\E/([^/]+)/?##) {
454 } elsif($path =~ s
#^/\Q$trunk_name\E/?##) {
456 } elsif($path =~ s
#^/\Q$branch_name\E/([^/]+)/?##) {
464 print STDERR
"$rev: Unrecognized path: $path\n" unless (defined $no_error{$path});
469 } elsif ($project_name) {
470 $path = project_path
($path, $project_name);
472 return ($branch,$path);
477 my ($srcbranch,$uptorev) = @_;
479 my $bbranches = $branches{$srcbranch};
480 my @revs = reverse sort { ($a eq 'LAST' ?
0 : $a) <=> ($b eq 'LAST' ?
0 : $b) } keys %$bbranches;
482 foreach my $arev(@revs) {
483 next if ($arev eq 'LAST');
484 if ($arev <= $uptorev) {
492 sub expand_svndir
($$$);
494 sub expand_svndir
($$$)
496 my ($svnpath, $rev, $path) = @_;
498 get_ignore
(\
@list, undef, $rev, $path, $svnpath);
499 my $dirents = $svn->dir_list($svnpath, $rev);
500 foreach my $p(keys %$dirents) {
501 my $kind = node_kind
($svnpath.'/'.$p, $rev);
502 if ($kind eq $SVN::Node
::file
) {
503 my $f = get_file
($svnpath.'/'.$p, $rev, $path.'/'.$p);
504 push(@list, $f) if $f;
505 } elsif ($kind eq $SVN::Node
::dir
) {
507 expand_svndir
($svnpath.'/'.$p, $rev, $path.'/'.$p));
513 sub copy_path
($$$$$$$$) {
514 # Somebody copied a whole subdirectory.
515 # We need to find the index entries from the old version which the
516 # SVN log entry points to, and add them to the new place.
518 my($newrev,$newbranch,$path,$oldpath,$rev,$node_kind,$new,$parents) = @_;
520 my($srcbranch,$srcpath) = split_path
($rev,$oldpath);
521 unless(defined $srcbranch && defined $srcpath) {
522 print "Path not found when copying from $oldpath @ $rev.\n".
523 "Will try to copy from original SVN location...\n"
525 push (@
$new, expand_svndir
($oldpath, $rev, $path));
528 my $therev = branch_rev
($srcbranch, $rev);
529 my $gitrev = $branches{$srcbranch}{$therev};
531 print STDERR
"$newrev:$newbranch: could not find $oldpath \@ $rev\n";
534 if ($srcbranch ne $newbranch) {
535 push(@
$parents, $branches{$srcbranch}{'LAST'});
537 print "$newrev:$newbranch:$path: copying from $srcbranch:$srcpath @ $rev\n" if $opt_v;
538 if ($node_kind eq $SVN::Node
::dir
) {
539 $srcpath =~ s
#/*$#/#;
542 my $pid = open my $f,'-|';
543 die $! unless defined $pid;
545 exec("git-ls-tree","-r","-z",$gitrev,$srcpath)
551 my($m,$p) = split(/\t/,$_,2);
552 my($mode,$type,$sha1) = split(/ /,$m);
553 next if $type ne "blob";
554 if ($node_kind eq $SVN::Node
::dir
) {
555 $p = $path . substr($p,length($srcpath)-1);
559 push(@
$new,[$mode,$sha1,$p]);
562 print STDERR
"$newrev:$newbranch: could not list files in $oldpath \@ $rev\n";
566 my($branch, $changed_paths, $revision, $author, $date, $message) = @_;
567 my($committer_name,$committer_email,$dest);
568 my($author_name,$author_email);
569 my(@old,@new,@parents);
571 if (not defined $author or $author eq "") {
572 $committer_name = $committer_email = "unknown";
573 } elsif (defined $users_file) {
574 die "User $author is not listed in $users_file\n"
575 unless exists $users{$author};
576 ($committer_name,$committer_email) = @
{$users{$author}};
577 } elsif ($author =~ /^(.*?)\s+<(.*)>$/) {
578 ($committer_name, $committer_email) = ($1, $2);
580 $author =~ s/^<(.*)>$/$1/;
581 $committer_name = $committer_email = $author;
584 if ($opt_F && $message =~ /From:\s+(.*?)\s+<(.*)>\s*\n/) {
585 ($author_name, $author_email) = ($1, $2);
586 print "Author from From: $1 <$2>\n" if ($opt_v);;
587 } elsif ($opt_S && $message =~ /Signed-off-by:\s+(.*?)\s+<(.*)>\s*\n/) {
588 ($author_name, $author_email) = ($1, $2);
589 print "Author from Signed-off-by: $1 <$2>\n" if ($opt_v);;
591 $author_name = $committer_name;
592 $author_email = $committer_email;
595 $date = pdate
($date);
599 if($branch eq "/") { # trunk
601 } elsif($branch =~ m
#^/(.+)#) { # tag
604 } else { # "normal" branch
610 my $prev = $changed_paths->{"/"};
611 if($prev and $prev->[0] eq "A") {
612 delete $changed_paths->{"/"};
613 my $oldpath = $prev->[1];
615 if(defined $oldpath) {
617 ($parent,$p) = split_path
($revision,$oldpath);
618 if(defined $parent) {
622 $parent =~ s
#^/##; # if it's a tag
631 if($revision > $opt_s and defined $parent) {
632 open(H
,"git-rev-parse --verify $parent |");
635 print STDERR
"$revision: cannot find commit '$parent'!\n";
639 if(length($rev) != 40) {
640 print STDERR
"$revision: cannot find commit '$parent'!\n";
643 $rev = $branches{($parent eq $opt_o) ?
"/" : $parent}{"LAST"};
644 if($revision != $opt_s and not $rev) {
645 print STDERR
"$revision: do not know ancestor for '$parent'!\n";
652 # if($prev and $prev->[0] eq "A") {
654 # unless(open(H,"> $git_dir/refs/heads/$branch")) {
655 # print STDERR "$revision: Could not create branch $branch: $!\n";
660 # or die "Could not write branch $branch: $!";
662 # or die "Could not write branch $branch: $!";
665 if(not defined $rev) {
667 } elsif ($rev ne $last_rev) {
668 print "Switching from $last_rev to $rev ($branch)\n" if $opt_v;
669 system("git-read-tree", $rev);
670 die "read-tree failed for $rev: $?\n" if $?
;
674 push (@parents, $rev) if defined $rev;
677 if($tag and not %$changed_paths) {
680 my @paths = sort keys %$changed_paths;
681 foreach my $path(@paths) {
682 my $action = $changed_paths->{$path};
684 if ($action->[0] eq "R") {
685 # refer to a file/tree in an earlier commit
686 push(@old,$path); # remove any old stuff
688 if(($action->[0] eq "A") || ($action->[0] eq "R")) {
689 my $node_kind = node_kind
($action->[3], $revision);
690 if ($node_kind eq $SVN::Node
::file
) {
691 my $f = get_file
($action->[3],
696 my $opath = $action->[3];
697 print STDERR
"$revision: $branch: could not fetch '$opath'\n";
699 } elsif ($node_kind eq $SVN::Node
::dir
) {
701 copy_path
($revision, $branch,
703 $action->[2], $node_kind,
706 get_ignore
(\
@new, \
@old, $revision,
707 $path, $action->[3]);
710 } elsif ($action->[0] eq "D") {
712 } elsif ($action->[0] eq "M") {
713 my $node_kind = node_kind
($action->[3], $revision);
714 if ($node_kind eq $SVN::Node
::file
) {
715 my $f = get_file
($action->[3],
718 } elsif ($node_kind eq $SVN::Node
::dir
) {
719 get_ignore
(\
@new, \
@old, $revision,
720 $path, $action->[3]);
723 die "$revision: unknown action '".$action->[0]."' for $path\n";
730 @o1 = splice(@old,0,50);
735 my $pid = open my $F, "-|";
736 die "$!" unless defined $pid;
738 exec("git-ls-files", "-z", @o1) or die $!;
751 @o2 = splice(@o1,0,50);
756 system("git-update-index","--force-remove","--",@o2);
757 die "Cannot remove files: $?\n" if $?
;
763 @n2 = splice(@new,0,10);
768 system("git-update-index","--add",
769 (map { ('--cacheinfo', @
$_) } @n2));
770 die "Cannot add files: $?\n" if $?
;
773 my $pid = open(C
,"-|");
774 die "Cannot fork: $!" unless defined $pid;
776 exec("git-write-tree");
777 die "Cannot exec git-write-tree: $!\n";
779 chomp(my $tree = <C
>);
781 or die "Cannot get tree id ($tree): $!\n";
783 or die "Error running git-write-tree: $?\n";
784 print "Tree ID $tree\n" if $opt_v;
786 my $pr = IO
::Pipe
->new() or die "Cannot open pipe: $!\n";
787 my $pw = IO
::Pipe
->new() or die "Cannot open pipe: $!\n";
789 die "Fork: $!\n" unless defined $pid;
793 open(OUT
,">&STDOUT");
794 dup2
($pw->fileno(),0);
795 dup2
($pr->fileno(),1);
801 # loose detection of merges
802 # based on the commit msg
803 foreach my $rx (@mergerx) {
804 if ($message =~ $rx) {
806 if ($mparent eq 'HEAD') { $mparent = $opt_o };
807 if ( -e
"$git_dir/refs/heads/$mparent") {
808 $mparent = get_headref
($mparent, $git_dir);
809 push (@parents, $mparent);
810 print OUT
"Merge parent branch: $mparent\n" if $opt_v;
814 my %seen_parents = ();
815 my @unique_parents = grep { ! $seen_parents{$_} ++ } @parents;
816 foreach my $bparent (@unique_parents) {
817 push @par, '-p', $bparent;
818 print OUT
"Merge parent branch: $bparent\n" if $opt_v;
822 "GIT_AUTHOR_NAME=$author_name",
823 "GIT_AUTHOR_EMAIL=$author_email",
824 "GIT_AUTHOR_DATE=".strftime
("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
825 "GIT_COMMITTER_NAME=$committer_name",
826 "GIT_COMMITTER_EMAIL=$committer_email",
827 "GIT_COMMITTER_DATE=".strftime
("+0000 %Y-%m-%d %H:%M:%S",gmtime($date)),
828 "git-commit-tree", $tree,@par);
829 die "Cannot exec git-commit-tree: $!\n";
834 $message =~ s/[\s\n]+\z//;
835 $message = "r$revision: $message" if $opt_r;
837 print $pw "$message\n"
838 or die "Error writing to git-commit-tree: $!\n";
841 print "Committed change $revision:$branch ".strftime
("%Y-%m-%d %H:%M:%S",gmtime($date)).")\n" if $opt_v;
844 or die "Cannot get commit id ($cid): $!\n";
845 print "Commit ID $cid\n" if $opt_v;
849 die "Error running git-commit-tree: $?\n" if $?
;
852 if (not defined $cid) {
853 $cid = $branches{"/"}{"LAST"};
856 if(not defined $dest) {
857 print "... no known parent\n" if $opt_v;
859 print "Writing to refs/heads/$dest\n" if $opt_v;
860 open(C
,">$git_dir/refs/heads/$dest") and
861 print C
("$cid\n") and
863 or die "Cannot write branch $dest for update: $!\n";
867 my($in, $out) = ('','');
868 $last_rev = "-" if %$changed_paths;
869 # the tag was 'complex', i.e. did not refer to a "real" revision
871 $dest =~ tr/_/\./ if $opt_u;
874 my $pid = open2
($in, $out, 'git-mktag');
875 print $out ("object $cid\n".
878 "tagger $committer_name <$committer_email> 0 +0000\n") and
880 or die "Cannot create tag object $dest: $!\n";
885 if ( !close($in) or waitpid($pid, 0) != $pid or
886 $?
!= 0 or $tagobj !~ /^[0123456789abcdef]{40}$/ ) {
887 die "Cannot create tag object $dest: $!\n";
890 open(C
,">$git_dir/refs/tags/$dest") and
891 print C
("$tagobj\n") and
893 or die "Cannot create tag $branch: $!\n";
895 print "Created tag '$dest' on '$branch'\n" if $opt_v;
897 $branches{$branch}{"LAST"} = $cid;
898 $branches{$branch}{$revision} = $cid;
900 print BRANCHES
"$revision $branch $cid\n";
901 print "DONE: $revision $dest $cid\n" if $opt_v;
905 # Recursive use of the SVN connection does not work
908 my ($changed_paths, $revision, $author, $date, $message, $pool) = @_;
910 while(my($path,$action) = each %$changed_paths) {
911 $p{$path} = [ $action->action,$action->copyfrom_path, $action->copyfrom_rev, $path ];
913 $changed_paths = \
%p;
920 while(my($path,$action) = each %$changed_paths) {
921 ($branch,$path) = split_path
($revision,$path);
922 next if not defined $branch;
923 next if not defined $path;
924 $done{$branch}{$path} = $action;
926 while(($branch,$changed_paths) = each %done) {
927 commit
($branch, $changed_paths, $revision, $author, $date, $message);
931 $opt_l = $svn->{'maxrev'} if not defined $opt_l or $opt_l > $svn->{'maxrev'};
933 if ($opt_l < $current_rev) {
934 print "Up to date: no new revisions to fetch!\n" if $opt_v;
935 unlink("$git_dir/SVN2GIT_HEAD");
939 print "Processing from $current_rev to $opt_l ...\n" if $opt_v;
942 my $to_rev = $current_rev;
944 while ($to_rev < $opt_l) {
946 $to_rev = $from_rev + $repack_after;
947 $to_rev = $opt_l if $opt_l < $to_rev;
948 print "Fetching from $from_rev to $to_rev ...\n" if $opt_v;
949 my $pool=SVN
::Pool
->new;
950 $svn->{'svn'}->get_log("/",$from_rev,$to_rev,0,1,1,\
&commit_all
,$pool);
953 die "Fork: $!\n" unless defined $pid;
955 exec("git-repack", "-d")
956 or die "Cannot repack: $!\n";
964 if (defined $orig_git_index) {
965 $ENV{GIT_INDEX_FILE
} = $orig_git_index;
967 delete $ENV{GIT_INDEX_FILE
};
970 # Now switch back to the branch we were in before all of this happened
972 print "DONE\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
973 system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
976 system('git-read-tree', '-m', '-u', 'SVN2GIT_HEAD', 'HEAD');
977 die "read-tree failed: $?\n" if $?
;
980 $orig_branch = "master";
981 print "DONE; creating $orig_branch branch\n" if $opt_v and (not defined $opt_l or $opt_l > 0);
982 system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
983 unless -f
"$git_dir/refs/heads/master";
984 system('git-update-ref', 'HEAD', "$orig_branch");
986 system('git checkout');
987 die "checkout failed: $?\n" if $?
;
990 unlink("$git_dir/SVN2GIT_HEAD");