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 aggregate CVS check-ins into related changes.
7 # Fortunately, "cvsps" does that for us; all we have to do is to parse
10 # Checking out the files is done by a single long-running CVS connection
13 # The head revision is on branch "origin" by default.
14 # You can change that with the '-o' option.
20 use File
::Temp
qw(tempfile tmpnam);
21 use File
::Path
qw(mkpath);
22 use File
::Basename
qw(basename dirname);
26 use POSIX
qw(strftime dup2 ENOENT);
29 $SIG{'PIPE'}="IGNORE";
32 our($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,$opt_M,$opt_A,$opt_S,$opt_L);
33 my (%conv_author_name, %conv_author_email);
37 Usage: ${\basename $0} # fetch/update GIT from CVS
38 [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
39 [-p opts-for-cvsps] [-C GIT_repository] [-z fuzz] [-i] [-k] [-u]
40 [-s subst] [-m] [-M regex] [-S regex] [CVS_module]
45 sub read_author_info
($) {
48 open my $f, '<', "$file" or die("Failed to open $file: $!\n");
51 # Expected format is this:
52 # exon=Andreas Ericsson <ae@op5.se>
53 if (m/^(\S+?)\s*=\s*(.+?)\s*<(.+)>\s*$/) {
55 $conv_author_name{$user} = $2;
56 $conv_author_email{$user} = $3;
58 # However, we also read from CVSROOT/users format
60 elsif (/^(\w+):(['"]?)(.+?)\2\s*$/) {
62 ($user, $mapped) = ($1, $3);
63 if ($mapped =~ /^\s*(.*?)\s*<(.*)>\s*$/) {
64 $conv_author_name{$user} = $1;
65 $conv_author_email{$user} = $2;
67 elsif ($mapped =~ /^<?(.*)>?$/) {
68 $conv_author_name{$user} = $user;
69 $conv_author_email{$user} = $1;
72 # NEEDSWORK: Maybe warn on unrecognized lines?
77 sub write_author_info
($) {
79 open my $f, '>', $file or
80 die("Failed to open $file for writing: $!");
82 foreach (keys %conv_author_name) {
83 print $f "$_=$conv_author_name{$_} <$conv_author_email{$_}>\n";
88 getopts
("hivmkuo:d:p:C:z:s:M:P:A:S:L:") or usage
();
91 @ARGV <= 1 or usage
();
94 $ENV{"CVSROOT"} = $opt_d;
95 } elsif(-f
'CVS/Root') {
96 open my $f, '<', 'CVS/Root' or die 'Failed to open CVS/Root';
100 $ENV{"CVSROOT"} = $opt_d;
101 } elsif($ENV{"CVSROOT"}) {
102 $opt_d = $ENV{"CVSROOT"};
104 die "CVSROOT needs to be set";
108 my $git_tree = $opt_C;
113 $cvs_tree = $ARGV[0];
114 } elsif (-f
'CVS/Repository') {
115 open my $f, '<', 'CVS/Repository' or
116 die 'Failed to open CVS/Repository';
126 @mergerx = ( qr/\W(?:from|of|merge|merging|merged) (\w+)/i );
129 push (@mergerx, qr/$opt_M/);
132 select(STDERR
); $|=1; select(STDOUT
);
137 # We're only interested in connecting and downloading, so ...
140 use File
::Temp
qw(tempfile);
141 use POSIX
qw(strftime dup2);
144 my($what,$repo,$subdir) = @_;
145 $what=ref($what) if ref($what);
148 $self->{'buffer'} = "";
152 $self->{'fullrep'} = $repo;
155 $self->{'subdir'} = $subdir;
156 $self->{'lines'} = undef;
163 my $repo = $self->{'fullrep'};
164 if($repo =~ s/^:pserver:(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?//) {
165 my($user,$pass,$serv,$port) = ($1,$2,$3,$4);
166 $user="anonymous" unless defined $user;
169 $rr2 = ":pserver:$user\@$serv:$repo";
172 my $rr = ":pserver:$user\@$serv:$port$repo";
175 open(H
,$ENV{'HOME'}."/.cvspass") and do {
176 # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
180 my ($w,$p) = split(/\s/,$_,2);
181 if($w eq $rr or $w eq $rr2) {
188 $pass="A" unless $pass;
190 my $s = IO
::Socket
::INET
->new(PeerHost
=> $serv, PeerPort
=> $port);
191 die "Socket to $serv: $!\n" unless defined $s;
192 $s->write("BEGIN AUTH REQUEST\n$repo\n$user\n$pass\nEND AUTH REQUEST\n")
193 or die "Write to $serv: $!\n";
198 if($rep ne "I LOVE YOU\n") {
199 $rep="<unknown>" unless $rep;
200 die "AuthReply: $rep\n";
202 $self->{'socketo'} = $s;
203 $self->{'socketi'} = $s;
204 } else { # local or ext: Fork off our own cvs server.
205 my $pr = IO
::Pipe
->new();
206 my $pw = IO
::Pipe
->new();
208 die "Fork: $!\n" unless defined $pid;
210 $cvs = $ENV{CVS_SERVER
} if exists $ENV{CVS_SERVER
};
212 $rsh = $ENV{CVS_RSH
} if exists $ENV{CVS_RSH
};
214 my @cvs = ($cvs, 'server');
215 my ($local, $user, $host);
216 $local = $repo =~ s/:local://;
219 $local = !($repo =~ s/^(?:([^\@:]+)\@)?([^:]+)://);
220 ($user, $host) = ($1, $2);
224 unshift @cvs, $rsh, '-l', $user, $host;
226 unshift @cvs, $rsh, $host;
233 dup2
($pw->fileno(),0);
234 dup2
($pr->fileno(),1);
241 $self->{'socketo'} = $pw;
242 $self->{'socketi'} = $pr;
244 $self->{'socketo'}->write("Root $repo\n");
246 # Trial and error says that this probably is the minimum set
247 $self->{'socketo'}->write("Valid-responses ok error Valid-requests Mode M Mbinary E Checked-in Created Updated Merged Removed\n");
249 $self->{'socketo'}->write("valid-requests\n");
250 $self->{'socketo'}->flush();
252 chomp(my $rep=$self->readline());
253 if($rep !~ s/^Valid-requests\s*//) {
254 $rep="<unknown>" unless $rep;
255 die "Expected Valid-requests from server, but got: $rep\n";
257 chomp(my $res=$self->readline());
258 die "validReply: $res\n" if $res ne "ok";
260 $self->{'socketo'}->write("UseUnchanged\n") if $rep =~ /\bUseUnchanged\b/;
261 $self->{'repo'} = $repo;
266 return $self->{'socketi'}->getline();
270 # Request a file with a given revision.
271 # Trial and error says this is a good way to do it. :-/
272 my($self,$fn,$rev) = @_;
273 $self->{'socketo'}->write("Argument -N\n") or return undef;
274 $self->{'socketo'}->write("Argument -P\n") or return undef;
275 # -kk: Linus' version doesn't use it - defaults to off
277 $self->{'socketo'}->write("Argument -kk\n") or return undef;
279 $self->{'socketo'}->write("Argument -r\n") or return undef;
280 $self->{'socketo'}->write("Argument $rev\n") or return undef;
281 $self->{'socketo'}->write("Argument --\n") or return undef;
282 $self->{'socketo'}->write("Argument $self->{'subdir'}/$fn\n") or return undef;
283 $self->{'socketo'}->write("Directory .\n") or return undef;
284 $self->{'socketo'}->write("$self->{'repo'}\n") or return undef;
285 # $self->{'socketo'}->write("Sticky T1.0\n") or return undef;
286 $self->{'socketo'}->write("co\n") or return undef;
287 $self->{'socketo'}->flush() or return undef;
288 $self->{'lines'} = 0;
292 # Read a line from the server.
293 # ... except that 'line' may be an entire file. ;-)
295 die "Not in lines" unless defined $self->{'lines'};
299 while(defined($line = $self->readline())) {
300 # M U gnupg-cvs-rep/AUTHORS
301 # Updated gnupg-cvs-rep/
302 # /daten/src/rsync/gnupg-cvs-rep/AUTHORS
303 # /AUTHORS/1.1///T1.1
308 if($line =~ s/^(?:Created|Updated) //) {
309 $line = $self->readline(); # path
310 $line = $self->readline(); # Entries line
311 my $mode = $self->readline(); chomp $mode;
312 $self->{'mode'} = $mode;
313 defined (my $cnt = $self->readline())
314 or die "EOF from server after 'Changed'\n";
316 die "Duh: Filesize $cnt" if $cnt !~ /^\d+$/;
318 $res = $self->_fetchfile($fh, $cnt);
319 } elsif($line =~ s/^ //) {
321 $res += length($line);
322 } elsif($line =~ /^M\b/) {
324 } elsif($line =~ /^Mbinary\b/) {
326 die "EOF from server after 'Mbinary'" unless defined ($cnt = $self->readline());
328 die "Duh: Mbinary $cnt" if $cnt !~ /^\d+$/ or $cnt<1;
330 $res += $self->_fetchfile($fh, $cnt);
334 # print STDERR "S: ok (".length($res).")\n";
336 } elsif($line =~ s/^E //) {
337 # print STDERR "S: $line\n";
338 } elsif($line =~ /^(Remove-entry|Removed) /i) {
339 $line = $self->readline(); # filename
340 $line = $self->readline(); # OK
342 die "Unknown: $line" if $line ne "ok";
345 die "Unknown: $line\n";
352 my($self,$fn,$rev) = @_;
355 my ($fh, $name) = tempfile
('gitcvs.XXXXXX',
356 DIR
=> File
::Spec
->tmpdir(), UNLINK
=> 1);
358 $self->_file($fn,$rev) and $res = $self->_line($fh);
361 print STDERR
"Server has gone away while fetching $fn $rev, retrying...\n";
364 $self->_file($fn,$rev) or die "No file command send";
365 $res = $self->_line($fh);
366 die "Retry failed" unless defined $res;
370 return ($name, $res);
373 my ($self, $fh, $cnt) = @_;
375 my $bufsize = 1024 * 1024;
377 if ($bufsize > $cnt) {
381 my $num = $self->{'socketi'}->read($buf,$bufsize);
382 die "Server: Filesize $cnt: $num: $!\n" if not defined $num or $num<=0;
393 my $cvs = CVSconn
->new($opt_d, $cvs_tree);
398 m
#(\d{2,4})/(\d\d)/(\d\d)\s(\d\d):(\d\d)(?::(\d\d))?#
399 or die "Unparseable date: $d\n";
400 my $y=$1; $y-=1900 if $y>1900;
401 return timegm
($6||0,$5,$4,$3,$2-1,$y);
409 for my $x(split(//,$mode)) {
414 } elsif($x eq "u") { $um |= 0700;
415 } elsif($x eq "g") { $um |= 0070;
416 } elsif($x eq "o") { $um |= 0007;
417 } elsif($x eq "r") { $mm |= 0444;
418 } elsif($x eq "w") { $mm |= 0222;
419 } elsif($x eq "x") { $mm |= 0111;
420 } elsif($x eq "=") { # do nothing
421 } else { die "Unknown mode: $mode\n";
436 return $s =~ /^[a-f0-9]{40}$/;
439 sub get_headref
($$) {
443 my $f = "$git_dir/refs/heads/$name";
444 if(open(my $fh, $f)) {
445 chomp(my $r = <$fh>);
446 is_sha1
($r) or die "Cannot get head id for $name ($r): $!";
449 die "unable to open $f: $!" unless $! == POSIX
::ENOENT
;
454 or mkdir($git_tree,0777)
455 or die "Could not create $git_tree: $!";
458 my $last_branch = "";
459 my $orig_branch = "";
461 my $tip_at_start = undef;
463 my $git_dir = $ENV{"GIT_DIR"} || ".git";
464 $git_dir = getwd
()."/".$git_dir unless $git_dir =~ m
#^/#;
465 $ENV{"GIT_DIR"} = $git_dir;
467 $orig_git_index = $ENV{GIT_INDEX_FILE
} if exists $ENV{GIT_INDEX_FILE
};
469 my %index; # holds filenames of one index per branch
470 $index{$opt_o} = tmpnam
();
472 $ENV{GIT_INDEX_FILE
} = $index{$opt_o};
473 system("git-read-tree", $opt_o);
474 die "read-tree failed: $?\n" if $?
;
476 unless(-d
$git_dir) {
477 system("git-init-db");
478 die "Cannot init the GIT db at $git_tree: $?\n" if $?
;
479 system("git-read-tree");
480 die "Cannot init an empty tree: $?\n" if $?
;
482 $last_branch = $opt_o;
485 -f
"$git_dir/refs/heads/$opt_o"
486 or die "Branch '$opt_o' does not exist.\n".
487 "Either use the correct '-o branch' option,\n".
488 "or import to a new repository.\n";
490 open(F
, "git-symbolic-ref HEAD |") or
491 die "Cannot run git-symbolic-ref: $!\n";
492 chomp ($last_branch = <F
>);
493 $last_branch = basename
($last_branch);
495 unless($last_branch) {
496 warn "Cannot read the last branch name: $! -- assuming 'master'\n";
497 $last_branch = "master";
499 $orig_branch = $last_branch;
500 $tip_at_start = `git-rev-parse --verify HEAD`;
503 unless ($index{$last_branch}) {
504 $index{$last_branch} = tmpnam
();
506 $ENV{GIT_INDEX_FILE
} = $index{$last_branch};
507 system('git-read-tree', $last_branch);
508 die "read-tree failed: $?\n" if $?
;
510 # Get the last import timestamps
511 opendir(D
,"$git_dir/refs/heads");
512 while(defined(my $head = readdir(D
))) {
513 next if $head =~ /^\./;
514 open(F
,"$git_dir/refs/heads/$head")
515 or die "Bad head branch: $head: $!\n";
516 chomp(my $ftag = <F
>);
518 open(F
,"git-cat-file commit $ftag |");
520 next unless /^author\s.*\s(\d+)\s[-+]\d{4}$/;
521 $branch_date{$head} = $1;
530 or die "Could not create git subdir ($git_dir).\n";
532 # now we read (and possibly save) author-info as well
533 -f
"$git_dir/cvs-authors" and
534 read_author_info
("$git_dir/cvs-authors");
536 read_author_info
($opt_A);
537 write_author_info
("$git_dir/cvs-authors");
542 # run cvsps into a file unless we are getting
543 # it passed as a file via $opt_P
546 print "Running cvsps...\n" if $opt_v;
547 my $pid = open(CVSPS
,"-|");
548 die "Cannot fork: $!\n" unless defined $pid;
551 @opt = split(/,/,$opt_p) if defined $opt_p;
552 unshift @opt, '-z', $opt_z if defined $opt_z;
553 unshift @opt, '-q' unless defined $opt_v;
554 unless (defined($opt_p) && $opt_p =~ m/--no-cvs-direct/) {
555 push @opt, '--cvs-direct';
557 exec("cvsps","--norc",@opt,"-u","-A",'--root',$opt_d,$cvs_tree);
558 die "Could not start cvsps: $!\n";
560 my ($cvspsfh, $cvspsfile) = tempfile
('gitXXXXXX', SUFFIX
=> '.cvsps',
561 DIR
=> File
::Spec
->tmpdir());
571 open(CVS
, "<$opt_P") or die $!;
574 #---------------------
576 #Date: 1999/09/18 13:03:59
578 #Branch: STABLE-BRANCH-1-0
579 #Ancestor branch: HEAD
582 # See ChangeLog: Sat Sep 18 13:03:28 CEST 1999 Werner Koch
584 # README:1.57->1.57.2.1
585 # VERSION:1.96->1.96.2.1
587 #---------------------
591 sub update_index
(\@\@
) {
594 open(my $fh, '|-', qw(git-update-index -z --index-info))
595 or die "unable to open git-update-index: $!";
597 (map { "0 0000000000000000000000000000000000000000\t$_\0" }
599 (map { '100' . sprintf('%o', $_->[0]) . " $_->[1]\t$_->[2]\0" }
601 or die "unable to write to git-update-index: $!";
603 or die "unable to write to git-update-index: $!";
604 $?
and die "git-update-index reported error: $?";
608 open(my $fh, '-|', qw(git-write-tree))
609 or die "unable to open git-write-tree: $!";
610 chomp(my $tree = <$fh>);
612 or die "Cannot get tree id ($tree): $!";
614 or die "Error running git-write-tree: $?\n";
615 print "Tree ID $tree\n" if $opt_v;
619 my($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
620 my(@old,@new,@skipped,%ignorebranch);
622 # commits that cvsps cannot place anywhere...
623 $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
626 update_index
(@old, @new);
628 my $tree = write_tree
();
629 my $parent = get_headref
($last_branch, $git_dir);
630 print "Parent ID " . ($parent ?
$parent : "(empty)") . "\n" if $opt_v;
633 push @commit_args, ("-p", $parent) if $parent;
635 # loose detection of merges
636 # based on the commit msg
637 foreach my $rx (@mergerx) {
638 next unless $logmsg =~ $rx && $1;
639 my $mparent = $1 eq 'HEAD' ?
$opt_o : $1;
640 if(my $sha1 = get_headref
($mparent, $git_dir)) {
641 push @commit_args, '-p', $mparent;
642 print "Merge parent branch: $mparent\n" if $opt_v;
646 my $commit_date = strftime
("+0000 %Y-%m-%d %H:%M:%S",gmtime($date));
647 $ENV{GIT_AUTHOR_NAME
} = $author_name;
648 $ENV{GIT_AUTHOR_EMAIL
} = $author_email;
649 $ENV{GIT_AUTHOR_DATE
} = $commit_date;
650 $ENV{GIT_COMMITTER_NAME
} = $author_name;
651 $ENV{GIT_COMMITTER_EMAIL
} = $author_email;
652 $ENV{GIT_COMMITTER_DATE
} = $commit_date;
653 my $pid = open2
(my $commit_read, my $commit_write,
654 'git-commit-tree', $tree, @commit_args);
656 # compatibility with git2cvs
657 substr($logmsg,32767) = "" if length($logmsg) > 32767;
658 $logmsg =~ s/[\s\n]+\z//;
661 $logmsg .= "\n\n\nSKIPPED:\n\t";
662 $logmsg .= join("\n\t", @skipped) . "\n";
666 print($commit_write "$logmsg\n") && close($commit_write)
667 or die "Error writing to git-commit-tree: $!\n";
669 print "Committed patch $patchset ($branch $commit_date)\n" if $opt_v;
670 chomp(my $cid = <$commit_read>);
671 is_sha1
($cid) or die "Cannot get commit id ($cid): $!\n";
672 print "Commit ID $cid\n" if $opt_v;
676 die "Error running git-commit-tree: $?\n" if $?
;
678 system("git-update-ref refs/heads/$branch $cid") == 0
679 or die "Cannot write branch $branch for update: $!\n";
682 my($in, $out) = ('','');
684 $xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
685 $xtag =~ tr/_/\./ if ( $opt_u );
686 $xtag =~ s/[\/]/$opt_s/g
;
688 my $pid = open2
($in, $out, 'git-mktag');
689 print $out "object $cid\n".
692 "tagger $author_name <$author_email>\n"
693 or die "Cannot create tag object $xtag: $!\n";
695 or die "Cannot create tag object $xtag: $!\n";
700 if ( !close($in) or waitpid($pid, 0) != $pid or
701 $?
!= 0 or $tagobj !~ /^[0123456789abcdef]{40}$/ ) {
702 die "Cannot create tag object $xtag: $!\n";
706 open(C
,">$git_dir/refs/tags/$xtag")
707 or die "Cannot create tag $xtag: $!\n";
709 or die "Cannot write tag $xtag: $!\n";
711 or die "Cannot write tag $xtag: $!\n";
713 print "Created tag '$xtag' on '$branch'\n" if $opt_v;
720 if($state == 0 and /^-+$/) {
722 } elsif($state == 0) {
725 } elsif(($state==0 or $state==1) and s/^PatchSet\s+//) {
728 } elsif($state == 2 and s/^Date:\s+//) {
731 print STDERR
"Could not parse date: $_\n";
736 } elsif($state == 3 and s/^Author:\s+//) {
738 if (/^(.*?)\s+<(.*)>/) {
739 ($author_name, $author_email) = ($1, $2);
740 } elsif ($conv_author_name{$_}) {
741 $author_name = $conv_author_name{$_};
742 $author_email = $conv_author_email{$_};
744 $author_name = $author_email = $_;
747 } elsif($state == 4 and s/^Branch:\s+//) {
752 } elsif($state == 5 and s/^Ancestor branch:\s+//) {
755 $ancestor = $opt_o if $ancestor eq "HEAD";
757 } elsif($state == 5) {
761 } elsif($state == 6 and s/^Tag:\s+//) {
769 } elsif($state == 7 and /^Log:/) {
772 } elsif($state == 8 and /^Members:/) {
773 $branch = $opt_o if $branch eq "HEAD";
774 if(defined $branch_date{$branch} and $branch_date{$branch} >= $date) {
776 print "skip patchset $patchset: $date before $branch_date{$branch}\n" if $opt_v;
780 if (exists $ignorebranch{$branch}) {
781 print STDERR
"Skipping $branch\n";
786 if($ancestor eq $branch) {
787 print STDERR
"Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
790 if(-f
"$git_dir/refs/heads/$branch") {
791 print STDERR
"Branch $branch already exists!\n";
795 unless(open(H
,"$git_dir/refs/heads/$ancestor")) {
796 print STDERR
"Branch $ancestor does not exist!\n";
797 $ignorebranch{$branch} = 1;
803 unless(open(H
,"> $git_dir/refs/heads/$branch")) {
804 print STDERR
"Could not create branch $branch: $!\n";
805 $ignorebranch{$branch} = 1;
810 or die "Could not write branch $branch: $!";
812 or die "Could not write branch $branch: $!";
814 if(($ancestor || $branch) ne $last_branch) {
815 print "Switching from $last_branch to $branch\n" if $opt_v;
816 unless ($index{$branch}) {
817 $index{$branch} = tmpnam
();
818 $ENV{GIT_INDEX_FILE
} = $index{$branch};
819 system("git-read-tree", $branch);
820 die "read-tree failed: $?\n" if $?
;
823 $ENV{GIT_INDEX_FILE
} = $index{$branch};
825 print "have ancestor $ancestor" if $opt_v;
826 system("git-read-tree", $ancestor);
827 die "read-tree failed: $?\n" if $?
;
831 unless ($index{$branch}) {
832 $index{$branch} = tmpnam
();
833 $ENV{GIT_INDEX_FILE
} = $index{$branch};
834 system("git-read-tree", $branch);
835 die "read-tree failed: $?\n" if $?
;
838 $last_branch = $branch if $branch ne $last_branch;
840 } elsif($state == 8) {
842 } elsif($state == 9 and /^\s+(.+?):(INITIAL|\d+(?:\.\d+)+)->(\d+(?:\.\d+)+)\s*$/) {
843 # VERSION:1.96->1.96.2.1
844 my $init = ($2 eq "INITIAL");
848 if ($opt_S && $fn =~ m/$opt_S/) {
849 print "SKIPPING $fn v $rev\n";
853 print "Fetching $fn v $rev\n" if $opt_v;
854 my ($tmpname, $size) = $cvs->file($fn,$rev);
857 print "Drop $fn\n" if $opt_v;
859 print "".($init ?
"New" : "Update")." $fn: $size bytes\n" if $opt_v;
860 my $pid = open(my $F, '-|');
861 die $! unless defined $pid;
863 exec("git-hash-object", "-w", $tmpname)
864 or die "Cannot create object: $!\n";
869 my $mode = pmode
($cvs->{'mode'});
870 push(@new,[$mode, $sha, $fn]); # may be resurrected!
873 } elsif($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
877 print "Delete $fn\n" if $opt_v;
878 } elsif($state == 9 and /^\s*$/) {
880 } elsif(($state == 9 or $state == 10) and /^-+$/) {
882 if ($opt_L && $commitcount > $opt_L) {
886 if (($commitcount & 1023) == 0) {
887 system("git repack -a -d");
890 } elsif($state == 11 and /^-+$/) {
892 } elsif(/^-+$/) { # end of unknown-line processing
894 } elsif($state != 11) { # ignore stuff when skipping
895 print "* UNKNOWN LINE * $_\n";
898 commit
() if $branch and $state != 11;
900 foreach my $git_index (values %index) {
904 if (defined $orig_git_index) {
905 $ENV{GIT_INDEX_FILE
} = $orig_git_index;
907 delete $ENV{GIT_INDEX_FILE
};
910 # Now switch back to the branch we were in before all of this happened
912 print "DONE.\n" if $opt_v;
916 my $tip_at_end = `git-rev-parse --verify HEAD`;
917 if ($tip_at_start ne $tip_at_end) {
918 for ($tip_at_start, $tip_at_end) { chomp; }
919 print "Fetched into the current branch.\n" if $opt_v;
920 system(qw(git-read-tree -u -m),
921 $tip_at_start, $tip_at_end);
922 die "Fast-forward update failed: $?\n" if $?
;
925 system(qw(git-merge cvsimport HEAD), "refs/heads/$opt_o");
926 die "Could not merge $opt_o into the current branch.\n" if $?
;
929 $orig_branch = "master";
930 print "DONE; creating $orig_branch branch\n" if $opt_v;
931 system("git-update-ref", "refs/heads/master", "refs/heads/$opt_o")
932 unless -f
"$git_dir/refs/heads/master";
933 system('git-update-ref', 'HEAD', "$orig_branch");
935 system('git checkout');
936 die "checkout failed: $?\n" if $?
;