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 ($param,$user,$pass,$serv,$port) = ($1,$2,$3,$4,$5);
167 my ($proxyhost,$proxyport);
168 if ($param && ($param =~ m/proxy=([^;]+)/)) {
170 # Default proxyport, if not specified, is 8080.
172 if ($ENV{"CVS_PROXY_PORT"}) {
173 $proxyport = $ENV{"CVS_PROXY_PORT"};
175 if ($param =~ m/proxyport=([^;]+)/) {
180 $user="anonymous" unless defined $user;
183 $rr2 = ":pserver:$user\@$serv:$repo";
186 my $rr = ":pserver:$user\@$serv:$port$repo";
189 open(H
,$ENV{'HOME'}."/.cvspass") and do {
190 # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
194 my ($w,$p) = split(/\s/,$_,2);
195 if ($w eq $rr or $w eq $rr2) {
202 $pass="A" unless $pass;
207 # Use a HTTP Proxy. Only works for HTTP proxies that
208 # don't require user authentication
210 # See: http://www.ietf.org/rfc/rfc2817.txt
212 $s = IO
::Socket
::INET
->new(PeerHost
=> $proxyhost, PeerPort
=> $proxyport);
213 die "Socket to $proxyhost: $!\n" unless defined $s;
214 $s->write("CONNECT $serv:$port HTTP/1.1\r\nHost: $serv:$port\r\n\r\n")
215 or die "Write to $proxyhost: $!\n";
220 # The answer should look like 'HTTP/1.x 2yy ....'
221 if (!($rep =~ m
#^HTTP/1\.. 2[0-9][0-9]#)) {
222 die "Proxy connect: $rep\n";
224 # Skip up to the empty line of the proxy server output
225 # including the response headers.
226 while ($rep = <$s>) {
227 last if (!defined $rep ||
232 $s = IO
::Socket
::INET
->new(PeerHost
=> $serv, PeerPort
=> $port);
233 die "Socket to $serv: $!\n" unless defined $s;
236 $s->write("BEGIN AUTH REQUEST\n$repo\n$user\n$pass\nEND AUTH REQUEST\n")
237 or die "Write to $serv: $!\n";
242 if ($rep ne "I LOVE YOU\n") {
243 $rep="<unknown>" unless $rep;
244 die "AuthReply: $rep\n";
246 $self->{'socketo'} = $s;
247 $self->{'socketi'} = $s;
248 } else { # local or ext: Fork off our own cvs server.
249 my $pr = IO
::Pipe
->new();
250 my $pw = IO
::Pipe
->new();
252 die "Fork: $!\n" unless defined $pid;
254 $cvs = $ENV{CVS_SERVER
} if exists $ENV{CVS_SERVER
};
256 $rsh = $ENV{CVS_RSH
} if exists $ENV{CVS_RSH
};
258 my @cvs = ($cvs, 'server');
259 my ($local, $user, $host);
260 $local = $repo =~ s/:local://;
263 $local = !($repo =~ s/^(?:([^\@:]+)\@)?([^:]+)://);
264 ($user, $host) = ($1, $2);
268 unshift @cvs, $rsh, '-l', $user, $host;
270 unshift @cvs, $rsh, $host;
277 dup2
($pw->fileno(),0);
278 dup2
($pr->fileno(),1);
285 $self->{'socketo'} = $pw;
286 $self->{'socketi'} = $pr;
288 $self->{'socketo'}->write("Root $repo\n");
290 # Trial and error says that this probably is the minimum set
291 $self->{'socketo'}->write("Valid-responses ok error Valid-requests Mode M Mbinary E Checked-in Created Updated Merged Removed\n");
293 $self->{'socketo'}->write("valid-requests\n");
294 $self->{'socketo'}->flush();
296 chomp(my $rep=$self->readline());
297 if ($rep !~ s/^Valid-requests\s*//) {
298 $rep="<unknown>" unless $rep;
299 die "Expected Valid-requests from server, but got: $rep\n";
301 chomp(my $res=$self->readline());
302 die "validReply: $res\n" if $res ne "ok";
304 $self->{'socketo'}->write("UseUnchanged\n") if $rep =~ /\bUseUnchanged\b/;
305 $self->{'repo'} = $repo;
310 return $self->{'socketi'}->getline();
314 # Request a file with a given revision.
315 # Trial and error says this is a good way to do it. :-/
316 my ($self,$fn,$rev) = @_;
317 $self->{'socketo'}->write("Argument -N\n") or return undef;
318 $self->{'socketo'}->write("Argument -P\n") or return undef;
319 # -kk: Linus' version doesn't use it - defaults to off
321 $self->{'socketo'}->write("Argument -kk\n") or return undef;
323 $self->{'socketo'}->write("Argument -r\n") or return undef;
324 $self->{'socketo'}->write("Argument $rev\n") or return undef;
325 $self->{'socketo'}->write("Argument --\n") or return undef;
326 $self->{'socketo'}->write("Argument $self->{'subdir'}/$fn\n") or return undef;
327 $self->{'socketo'}->write("Directory .\n") or return undef;
328 $self->{'socketo'}->write("$self->{'repo'}\n") or return undef;
329 # $self->{'socketo'}->write("Sticky T1.0\n") or return undef;
330 $self->{'socketo'}->write("co\n") or return undef;
331 $self->{'socketo'}->flush() or return undef;
332 $self->{'lines'} = 0;
336 # Read a line from the server.
337 # ... except that 'line' may be an entire file. ;-)
338 my ($self, $fh) = @_;
339 die "Not in lines" unless defined $self->{'lines'};
343 while (defined($line = $self->readline())) {
344 # M U gnupg-cvs-rep/AUTHORS
345 # Updated gnupg-cvs-rep/
346 # /daten/src/rsync/gnupg-cvs-rep/AUTHORS
347 # /AUTHORS/1.1///T1.1
352 if ($line =~ s/^(?:Created|Updated) //) {
353 $line = $self->readline(); # path
354 $line = $self->readline(); # Entries line
355 my $mode = $self->readline(); chomp $mode;
356 $self->{'mode'} = $mode;
357 defined (my $cnt = $self->readline())
358 or die "EOF from server after 'Changed'\n";
360 die "Duh: Filesize $cnt" if $cnt !~ /^\d+$/;
362 $res = $self->_fetchfile($fh, $cnt);
363 } elsif ($line =~ s/^ //) {
365 $res += length($line);
366 } elsif ($line =~ /^M\b/) {
368 } elsif ($line =~ /^Mbinary\b/) {
370 die "EOF from server after 'Mbinary'" unless defined ($cnt = $self->readline());
372 die "Duh: Mbinary $cnt" if $cnt !~ /^\d+$/ or $cnt<1;
374 $res += $self->_fetchfile($fh, $cnt);
378 # print STDERR "S: ok (".length($res).")\n";
380 } elsif ($line =~ s/^E //) {
381 # print STDERR "S: $line\n";
382 } elsif ($line =~ /^(Remove-entry|Removed) /i) {
383 $line = $self->readline(); # filename
384 $line = $self->readline(); # OK
386 die "Unknown: $line" if $line ne "ok";
389 die "Unknown: $line\n";
396 my ($self,$fn,$rev) = @_;
399 my ($fh, $name) = tempfile
('gitcvs.XXXXXX',
400 DIR
=> File
::Spec
->tmpdir(), UNLINK
=> 1);
402 $self->_file($fn,$rev) and $res = $self->_line($fh);
405 print STDERR
"Server has gone away while fetching $fn $rev, retrying...\n";
408 $self->_file($fn,$rev) or die "No file command send";
409 $res = $self->_line($fh);
410 die "Retry failed" unless defined $res;
414 return ($name, $res);
417 my ($self, $fh, $cnt) = @_;
419 my $bufsize = 1024 * 1024;
421 if ($bufsize > $cnt) {
425 my $num = $self->{'socketi'}->read($buf,$bufsize);
426 die "Server: Filesize $cnt: $num: $!\n" if not defined $num or $num<=0;
437 my $cvs = CVSconn
->new($opt_d, $cvs_tree);
442 m
#(\d{2,4})/(\d\d)/(\d\d)\s(\d\d):(\d\d)(?::(\d\d))?#
443 or die "Unparseable date: $d\n";
444 my $y=$1; $y-=1900 if $y>1900;
445 return timegm
($6||0,$5,$4,$3,$2-1,$y);
453 for my $x(split(//,$mode)) {
458 } elsif ($x eq "u") { $um |= 0700;
459 } elsif ($x eq "g") { $um |= 0070;
460 } elsif ($x eq "o") { $um |= 0007;
461 } elsif ($x eq "r") { $mm |= 0444;
462 } elsif ($x eq "w") { $mm |= 0222;
463 } elsif ($x eq "x") { $mm |= 0111;
464 } elsif ($x eq "=") { # do nothing
465 } else { die "Unknown mode: $mode\n";
480 return $s =~ /^[a-f0-9]{40}$/;
483 sub get_headref
($$) {
487 my $f = "$git_dir/refs/heads/$name";
488 if (open(my $fh, $f)) {
489 chomp(my $r = <$fh>);
490 is_sha1
($r) or die "Cannot get head id for $name ($r): $!";
493 die "unable to open $f: $!" unless $! == POSIX
::ENOENT
;
498 or mkdir($git_tree,0777)
499 or die "Could not create $git_tree: $!";
502 my $last_branch = "";
503 my $orig_branch = "";
505 my $tip_at_start = undef;
507 my $git_dir = $ENV{"GIT_DIR"} || ".git";
508 $git_dir = getwd
()."/".$git_dir unless $git_dir =~ m
#^/#;
509 $ENV{"GIT_DIR"} = $git_dir;
511 $orig_git_index = $ENV{GIT_INDEX_FILE
} if exists $ENV{GIT_INDEX_FILE
};
513 my %index; # holds filenames of one index per branch
515 unless (-d
$git_dir) {
516 system("git-init-db");
517 die "Cannot init the GIT db at $git_tree: $?\n" if $?
;
518 system("git-read-tree");
519 die "Cannot init an empty tree: $?\n" if $?
;
521 $last_branch = $opt_o;
524 -f
"$git_dir/refs/heads/$opt_o"
525 or die "Branch '$opt_o' does not exist.\n".
526 "Either use the correct '-o branch' option,\n".
527 "or import to a new repository.\n";
529 open(F
, "git-symbolic-ref HEAD |") or
530 die "Cannot run git-symbolic-ref: $!\n";
531 chomp ($last_branch = <F
>);
532 $last_branch = basename
($last_branch);
534 unless ($last_branch) {
535 warn "Cannot read the last branch name: $! -- assuming 'master'\n";
536 $last_branch = "master";
538 $orig_branch = $last_branch;
539 $tip_at_start = `git-rev-parse --verify HEAD`;
541 # Get the last import timestamps
542 my $fmt = '($ref, $author) = (%(refname), %(author));';
543 open(H
, "git-for-each-ref --perl --format='$fmt' refs/heads |") or
544 die "Cannot run git-for-each-ref: $!\n";
545 while (defined(my $entry = <H
>)) {
547 eval($entry) || die "cannot eval refs list: $@";
548 my ($head) = ($ref =~ m
|^refs
/heads/(.*)|);
549 $author =~ /^.*\s(\d+)\s[-+]\d{4}$/;
550 $branch_date{$head} = $1;
556 or die "Could not create git subdir ($git_dir).\n";
558 # now we read (and possibly save) author-info as well
559 -f
"$git_dir/cvs-authors" and
560 read_author_info
("$git_dir/cvs-authors");
562 read_author_info
($opt_A);
563 write_author_info
("$git_dir/cvs-authors");
568 # run cvsps into a file unless we are getting
569 # it passed as a file via $opt_P
572 print "Running cvsps...\n" if $opt_v;
573 my $pid = open(CVSPS
,"-|");
574 die "Cannot fork: $!\n" unless defined $pid;
577 @opt = split(/,/,$opt_p) if defined $opt_p;
578 unshift @opt, '-z', $opt_z if defined $opt_z;
579 unshift @opt, '-q' unless defined $opt_v;
580 unless (defined($opt_p) && $opt_p =~ m/--no-cvs-direct/) {
581 push @opt, '--cvs-direct';
583 exec("cvsps","--norc",@opt,"-u","-A",'--root',$opt_d,$cvs_tree);
584 die "Could not start cvsps: $!\n";
586 my ($cvspsfh, $cvspsfile) = tempfile
('gitXXXXXX', SUFFIX
=> '.cvsps',
587 DIR
=> File
::Spec
->tmpdir());
597 open(CVS
, "<$opt_P") or die $!;
600 #---------------------
602 #Date: 1999/09/18 13:03:59
604 #Branch: STABLE-BRANCH-1-0
605 #Ancestor branch: HEAD
608 # See ChangeLog: Sat Sep 18 13:03:28 CEST 1999 Werner Koch
610 # README:1.57->1.57.2.1
611 # VERSION:1.96->1.96.2.1
613 #---------------------
617 sub update_index
(\@\@
) {
620 open(my $fh, '|-', qw(git-update-index -z --index-info))
621 or die "unable to open git-update-index: $!";
623 (map { "0 0000000000000000000000000000000000000000\t$_\0" }
625 (map { '100' . sprintf('%o', $_->[0]) . " $_->[1]\t$_->[2]\0" }
627 or die "unable to write to git-update-index: $!";
629 or die "unable to write to git-update-index: $!";
630 $?
and die "git-update-index reported error: $?";
634 open(my $fh, '-|', qw(git-write-tree))
635 or die "unable to open git-write-tree: $!";
636 chomp(my $tree = <$fh>);
638 or die "Cannot get tree id ($tree): $!";
640 or die "Error running git-write-tree: $?\n";
641 print "Tree ID $tree\n" if $opt_v;
645 my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
646 my (@old,@new,@skipped,%ignorebranch);
648 # commits that cvsps cannot place anywhere...
649 $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
652 if ($branch eq $opt_o && !$index{branch
} && !get_headref
($branch, $git_dir)) {
653 # looks like an initial commit
654 # use the index primed by git-init-db
655 $ENV{GIT_INDEX_FILE
} = '.git/index';
656 $index{$branch} = '.git/index';
658 # use an index per branch to speed up
659 # imports of projects with many branches
660 unless ($index{$branch}) {
661 $index{$branch} = tmpnam
();
662 $ENV{GIT_INDEX_FILE
} = $index{$branch};
664 system("git-read-tree", $ancestor);
666 system("git-read-tree", $branch);
668 die "read-tree failed: $?\n" if $?
;
671 $ENV{GIT_INDEX_FILE
} = $index{$branch};
673 update_index
(@old, @new);
675 my $tree = write_tree
();
676 my $parent = get_headref
($last_branch, $git_dir);
677 print "Parent ID " . ($parent ?
$parent : "(empty)") . "\n" if $opt_v;
680 push @commit_args, ("-p", $parent) if $parent;
682 # loose detection of merges
683 # based on the commit msg
684 foreach my $rx (@mergerx) {
685 next unless $logmsg =~ $rx && $1;
686 my $mparent = $1 eq 'HEAD' ?
$opt_o : $1;
687 if (my $sha1 = get_headref
($mparent, $git_dir)) {
688 push @commit_args, '-p', $mparent;
689 print "Merge parent branch: $mparent\n" if $opt_v;
693 my $commit_date = strftime
("+0000 %Y-%m-%d %H:%M:%S",gmtime($date));
694 $ENV{GIT_AUTHOR_NAME
} = $author_name;
695 $ENV{GIT_AUTHOR_EMAIL
} = $author_email;
696 $ENV{GIT_AUTHOR_DATE
} = $commit_date;
697 $ENV{GIT_COMMITTER_NAME
} = $author_name;
698 $ENV{GIT_COMMITTER_EMAIL
} = $author_email;
699 $ENV{GIT_COMMITTER_DATE
} = $commit_date;
700 my $pid = open2
(my $commit_read, my $commit_write,
701 'git-commit-tree', $tree, @commit_args);
703 # compatibility with git2cvs
704 substr($logmsg,32767) = "" if length($logmsg) > 32767;
705 $logmsg =~ s/[\s\n]+\z//;
708 $logmsg .= "\n\n\nSKIPPED:\n\t";
709 $logmsg .= join("\n\t", @skipped) . "\n";
713 print($commit_write "$logmsg\n") && close($commit_write)
714 or die "Error writing to git-commit-tree: $!\n";
716 print "Committed patch $patchset ($branch $commit_date)\n" if $opt_v;
717 chomp(my $cid = <$commit_read>);
718 is_sha1
($cid) or die "Cannot get commit id ($cid): $!\n";
719 print "Commit ID $cid\n" if $opt_v;
723 die "Error running git-commit-tree: $?\n" if $?
;
725 system("git-update-ref refs/heads/$branch $cid") == 0
726 or die "Cannot write branch $branch for update: $!\n";
729 my ($in, $out) = ('','');
731 $xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
732 $xtag =~ tr/_/\./ if ( $opt_u );
733 $xtag =~ s/[\/]/$opt_s/g
;
735 my $pid = open2
($in, $out, 'git-mktag');
736 print $out "object $cid\n".
739 "tagger $author_name <$author_email>\n"
740 or die "Cannot create tag object $xtag: $!\n";
742 or die "Cannot create tag object $xtag: $!\n";
747 if ( !close($in) or waitpid($pid, 0) != $pid or
748 $?
!= 0 or $tagobj !~ /^[0123456789abcdef]{40}$/ ) {
749 die "Cannot create tag object $xtag: $!\n";
753 open(C
,">$git_dir/refs/tags/$xtag")
754 or die "Cannot create tag $xtag: $!\n";
756 or die "Cannot write tag $xtag: $!\n";
758 or die "Cannot write tag $xtag: $!\n";
760 print "Created tag '$xtag' on '$branch'\n" if $opt_v;
767 if ($state == 0 and /^-+$/) {
769 } elsif ($state == 0) {
772 } elsif (($state==0 or $state==1) and s/^PatchSet\s+//) {
775 } elsif ($state == 2 and s/^Date:\s+//) {
778 print STDERR
"Could not parse date: $_\n";
783 } elsif ($state == 3 and s/^Author:\s+//) {
785 if (/^(.*?)\s+<(.*)>/) {
786 ($author_name, $author_email) = ($1, $2);
787 } elsif ($conv_author_name{$_}) {
788 $author_name = $conv_author_name{$_};
789 $author_email = $conv_author_email{$_};
791 $author_name = $author_email = $_;
794 } elsif ($state == 4 and s/^Branch:\s+//) {
799 } elsif ($state == 5 and s/^Ancestor branch:\s+//) {
802 $ancestor = $opt_o if $ancestor eq "HEAD";
804 } elsif ($state == 5) {
808 } elsif ($state == 6 and s/^Tag:\s+//) {
810 if ($_ eq "(none)") {
816 } elsif ($state == 7 and /^Log:/) {
819 } elsif ($state == 8 and /^Members:/) {
820 $branch = $opt_o if $branch eq "HEAD";
821 if (defined $branch_date{$branch} and $branch_date{$branch} >= $date) {
823 print "skip patchset $patchset: $date before $branch_date{$branch}\n" if $opt_v;
827 if (exists $ignorebranch{$branch}) {
828 print STDERR
"Skipping $branch\n";
833 if ($ancestor eq $branch) {
834 print STDERR
"Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
837 if (-f
"$git_dir/refs/heads/$branch") {
838 print STDERR
"Branch $branch already exists!\n";
842 unless (open(H
,"$git_dir/refs/heads/$ancestor")) {
843 print STDERR
"Branch $ancestor does not exist!\n";
844 $ignorebranch{$branch} = 1;
850 unless (open(H
,"> $git_dir/refs/heads/$branch")) {
851 print STDERR
"Could not create branch $branch: $!\n";
852 $ignorebranch{$branch} = 1;
857 or die "Could not write branch $branch: $!";
859 or die "Could not write branch $branch: $!";
861 $last_branch = $branch if $branch ne $last_branch;
863 } elsif ($state == 8) {
865 } elsif ($state == 9 and /^\s+(.+?):(INITIAL|\d+(?:\.\d+)+)->(\d+(?:\.\d+)+)\s*$/) {
866 # VERSION:1.96->1.96.2.1
867 my $init = ($2 eq "INITIAL");
871 if ($opt_S && $fn =~ m/$opt_S/) {
872 print "SKIPPING $fn v $rev\n";
876 print "Fetching $fn v $rev\n" if $opt_v;
877 my ($tmpname, $size) = $cvs->file($fn,$rev);
880 print "Drop $fn\n" if $opt_v;
882 print "".($init ?
"New" : "Update")." $fn: $size bytes\n" if $opt_v;
883 my $pid = open(my $F, '-|');
884 die $! unless defined $pid;
886 exec("git-hash-object", "-w", $tmpname)
887 or die "Cannot create object: $!\n";
892 my $mode = pmode
($cvs->{'mode'});
893 push(@new,[$mode, $sha, $fn]); # may be resurrected!
896 } elsif ($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
900 print "Delete $fn\n" if $opt_v;
901 } elsif ($state == 9 and /^\s*$/) {
903 } elsif (($state == 9 or $state == 10) and /^-+$/) {
905 if ($opt_L && $commitcount > $opt_L) {
909 if (($commitcount & 1023) == 0) {
910 system("git repack -a -d");
913 } elsif ($state == 11 and /^-+$/) {
915 } elsif (/^-+$/) { # end of unknown-line processing
917 } elsif ($state != 11) { # ignore stuff when skipping
918 print "* UNKNOWN LINE * $_\n";
921 commit
() if $branch and $state != 11;
923 # The heuristic of repacking every 1024 commits can leave a
924 # lot of unpacked data. If there is more than 1MB worth of
925 # not-packed objects, repack once more.
926 my $line = `git-count-objects`;
927 if ($line =~ /^(\d+) objects, (\d+) kilobytes$/) {
928 my ($n_objects, $kb) = ($1, $2);
930 and system("git repack -a -d");
933 foreach my $git_index (values %index) {
934 if ($git_index ne '.git/index') {
939 if (defined $orig_git_index) {
940 $ENV{GIT_INDEX_FILE
} = $orig_git_index;
942 delete $ENV{GIT_INDEX_FILE
};
945 # Now switch back to the branch we were in before all of this happened
947 print "DONE.\n" if $opt_v;
951 my $tip_at_end = `git-rev-parse --verify HEAD`;
952 if ($tip_at_start ne $tip_at_end) {
953 for ($tip_at_start, $tip_at_end) { chomp; }
954 print "Fetched into the current branch.\n" if $opt_v;
955 system(qw(git-read-tree -u -m),
956 $tip_at_start, $tip_at_end);
957 die "Fast-forward update failed: $?\n" if $?
;
960 system(qw(git-merge cvsimport HEAD), "refs/heads/$opt_o");
961 die "Could not merge $opt_o into the current branch.\n" if $?
;
964 $orig_branch = "master";
965 print "DONE; creating $orig_branch branch\n" if $opt_v;
966 system("git-update-ref", "refs/heads/master", "refs/heads/$opt_o")
967 unless -f
"$git_dir/refs/heads/master";
968 system('git-update-ref', 'HEAD', "$orig_branch");
970 system('git checkout');
971 die "checkout failed: $?\n" if $?
;