~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to git-cvsimport.perl

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20070422133105-tkmhz328g2p0epz1
Tags: 1:1.5.1.2-1
* new upstream point release.
* debian/changelog.upstream: upstream changes taken from mailing list
  announcement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
$SIG{'PIPE'}="IGNORE";
30
30
$ENV{'TZ'}="UTC";
31
31
 
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);
 
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, $opt_a);
33
33
my (%conv_author_name, %conv_author_email);
34
34
 
35
 
sub usage() {
 
35
sub usage(;$) {
 
36
        my $msg = shift;
 
37
        print(STDERR "Error: $msg\n") if $msg;
36
38
        print STDERR <<END;
37
39
Usage: ${\basename $0}     # fetch/update GIT from CVS
38
40
       [-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]
 
41
       [-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
 
42
       [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
 
43
       [CVS_module]
41
44
END
42
45
        exit(1);
43
46
}
85
88
        close ($f);
86
89
}
87
90
 
88
 
getopts("hivmkuo:d:p:C:z:s:M:P:A:S:L:") or usage();
 
91
# convert getopts specs for use by git-repo-config
 
92
sub read_repo_config {
 
93
    # Split the string between characters, unless there is a ':'
 
94
    # So "abc:de" becomes ["a", "b", "c:", "d", "e"]
 
95
        my @opts = split(/ *(?!:)/, shift);
 
96
        foreach my $o (@opts) {
 
97
                my $key = $o;
 
98
                $key =~ s/://g;
 
99
                my $arg = 'git-repo-config';
 
100
                $arg .= ' --bool' if ($o !~ /:$/);
 
101
 
 
102
        chomp(my $tmp = `$arg --get cvsimport.$key`);
 
103
                if ($tmp && !($arg =~ /--bool/ && $tmp eq 'false')) {
 
104
            no strict 'refs';
 
105
            my $opt_name = "opt_" . $key;
 
106
            if (!$$opt_name) {
 
107
                $$opt_name = $tmp;
 
108
            }
 
109
                }
 
110
        }
 
111
    if (@ARGV == 0) {
 
112
        chomp(my $module = `git-repo-config --get cvsimport.module`);
 
113
        push(@ARGV, $module);
 
114
    }
 
115
}
 
116
 
 
117
my $opts = "haivmkuo:d:p:C:z:s:M:P:A:S:L:";
 
118
read_repo_config($opts);
 
119
getopts($opts) or usage();
89
120
usage if $opt_h;
90
121
 
91
 
@ARGV <= 1 or usage();
 
122
@ARGV <= 1 or usage("You can't specify more than one CVS module");
92
123
 
93
 
if($opt_d) {
 
124
if ($opt_d) {
94
125
        $ENV{"CVSROOT"} = $opt_d;
95
 
} elsif(-f 'CVS/Root') {
 
126
} elsif (-f 'CVS/Root') {
96
127
        open my $f, '<', 'CVS/Root' or die 'Failed to open CVS/Root';
97
128
        $opt_d = <$f>;
98
129
        chomp $opt_d;
99
130
        close $f;
100
131
        $ENV{"CVSROOT"} = $opt_d;
101
 
} elsif($ENV{"CVSROOT"}) {
 
132
} elsif ($ENV{"CVSROOT"}) {
102
133
        $opt_d = $ENV{"CVSROOT"};
103
134
} else {
104
 
        die "CVSROOT needs to be set";
 
135
        usage("CVSROOT needs to be set");
105
136
}
106
137
$opt_o ||= "origin";
107
138
$opt_s ||= "-";
 
139
$opt_a ||= 0;
 
140
 
108
141
my $git_tree = $opt_C;
109
142
$git_tree ||= ".";
110
143
 
118
151
        chomp $cvs_tree;
119
152
        close $f;
120
153
} else {
121
 
        usage();
 
154
        usage("CVS module has to be specified");
122
155
}
123
156
 
124
157
our @mergerx = ();
129
162
        push (@mergerx, qr/$opt_M/);
130
163
}
131
164
 
 
165
# Remember UTC of our starting time
 
166
# we'll want to avoid importing commits
 
167
# that are too recent
 
168
our $starttime = time();
 
169
 
132
170
select(STDERR); $|=1; select(STDOUT);
133
171
 
134
172
 
141
179
use POSIX qw(strftime dup2);
142
180
 
143
181
sub new {
144
 
        my($what,$repo,$subdir) = @_;
 
182
        my ($what,$repo,$subdir) = @_;
145
183
        $what=ref($what) if ref($what);
146
184
 
147
185
        my $self = {};
161
199
sub conn {
162
200
        my $self = shift;
163
201
        my $repo = $self->{'fullrep'};
164
 
        if($repo =~ s/^:pserver:(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?//) {
165
 
                my($user,$pass,$serv,$port) = ($1,$2,$3,$4);
 
202
        if ($repo =~ s/^:pserver(?:([^:]*)):(?:(.*?)(?::(.*?))?@)?([^:\/]*)(?::(\d*))?//) {
 
203
                my ($param,$user,$pass,$serv,$port) = ($1,$2,$3,$4,$5);
 
204
 
 
205
                my ($proxyhost,$proxyport);
 
206
                if ($param && ($param =~ m/proxy=([^;]+)/)) {
 
207
                        $proxyhost = $1;
 
208
                        # Default proxyport, if not specified, is 8080.
 
209
                        $proxyport = 8080;
 
210
                        if ($ENV{"CVS_PROXY_PORT"}) {
 
211
                                $proxyport = $ENV{"CVS_PROXY_PORT"};
 
212
                        }
 
213
                        if ($param =~ m/proxyport=([^;]+)/) {
 
214
                                $proxyport = $1;
 
215
                        }
 
216
                }
 
217
 
166
218
                $user="anonymous" unless defined $user;
167
219
                my $rr2 = "-";
168
 
                unless($port) {
 
220
                unless ($port) {
169
221
                        $rr2 = ":pserver:$user\@$serv:$repo";
170
222
                        $port=2401;
171
223
                }
172
224
                my $rr = ":pserver:$user\@$serv:$port$repo";
173
225
 
174
 
                unless($pass) {
 
226
                unless ($pass) {
175
227
                        open(H,$ENV{'HOME'}."/.cvspass") and do {
176
228
                                # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah<Z
177
 
                                while(<H>) {
 
229
                                while (<H>) {
178
230
                                        chomp;
179
231
                                        s/^\/\d+\s+//;
180
232
                                        my ($w,$p) = split(/\s/,$_,2);
181
 
                                        if($w eq $rr or $w eq $rr2) {
 
233
                                        if ($w eq $rr or $w eq $rr2) {
182
234
                                                $pass = $p;
183
235
                                                last;
184
236
                                        }
187
239
                }
188
240
                $pass="A" unless $pass;
189
241
 
190
 
                my $s = IO::Socket::INET->new(PeerHost => $serv, PeerPort => $port);
191
 
                die "Socket to $serv: $!\n" unless defined $s;
 
242
                my ($s, $rep);
 
243
                if ($proxyhost) {
 
244
 
 
245
                        # Use a HTTP Proxy. Only works for HTTP proxies that
 
246
                        # don't require user authentication
 
247
                        #
 
248
                        # See: http://www.ietf.org/rfc/rfc2817.txt
 
249
 
 
250
                        $s = IO::Socket::INET->new(PeerHost => $proxyhost, PeerPort => $proxyport);
 
251
                        die "Socket to $proxyhost: $!\n" unless defined $s;
 
252
                        $s->write("CONNECT $serv:$port HTTP/1.1\r\nHost: $serv:$port\r\n\r\n")
 
253
                                or die "Write to $proxyhost: $!\n";
 
254
                        $s->flush();
 
255
 
 
256
                        $rep = <$s>;
 
257
 
 
258
                        # The answer should look like 'HTTP/1.x 2yy ....'
 
259
                        if (!($rep =~ m#^HTTP/1\.. 2[0-9][0-9]#)) {
 
260
                                die "Proxy connect: $rep\n";
 
261
                        }
 
262
                        # Skip up to the empty line of the proxy server output
 
263
                        # including the response headers.
 
264
                        while ($rep = <$s>) {
 
265
                                last if (!defined $rep ||
 
266
                                         $rep eq "\n" ||
 
267
                                         $rep eq "\r\n");
 
268
                        }
 
269
                } else {
 
270
                        $s = IO::Socket::INET->new(PeerHost => $serv, PeerPort => $port);
 
271
                        die "Socket to $serv: $!\n" unless defined $s;
 
272
                }
 
273
 
192
274
                $s->write("BEGIN AUTH REQUEST\n$repo\n$user\n$pass\nEND AUTH REQUEST\n")
193
275
                        or die "Write to $serv: $!\n";
194
276
                $s->flush();
195
277
 
196
 
                my $rep = <$s>;
 
278
                $rep = <$s>;
197
279
 
198
 
                if($rep ne "I LOVE YOU\n") {
 
280
                if ($rep ne "I LOVE YOU\n") {
199
281
                        $rep="<unknown>" unless $rep;
200
282
                        die "AuthReply: $rep\n";
201
283
                }
227
309
                    }
228
310
                }
229
311
 
230
 
                unless($pid) {
 
312
                unless ($pid) {
231
313
                        $pr->writer();
232
314
                        $pw->reader();
233
315
                        dup2($pw->fileno(),0);
250
332
        $self->{'socketo'}->flush();
251
333
 
252
334
        chomp(my $rep=$self->readline());
253
 
        if($rep !~ s/^Valid-requests\s*//) {
 
335
        if ($rep !~ s/^Valid-requests\s*//) {
254
336
                $rep="<unknown>" unless $rep;
255
337
                die "Expected Valid-requests from server, but got: $rep\n";
256
338
        }
262
344
}
263
345
 
264
346
sub readline {
265
 
        my($self) = @_;
 
347
        my ($self) = @_;
266
348
        return $self->{'socketi'}->getline();
267
349
}
268
350
 
269
351
sub _file {
270
352
        # Request a file with a given revision.
271
353
        # Trial and error says this is a good way to do it. :-/
272
 
        my($self,$fn,$rev) = @_;
 
354
        my ($self,$fn,$rev) = @_;
273
355
        $self->{'socketo'}->write("Argument -N\n") or return undef;
274
356
        $self->{'socketo'}->write("Argument -P\n") or return undef;
275
357
        # -kk: Linus' version doesn't use it - defaults to off
291
373
sub _line {
292
374
        # Read a line from the server.
293
375
        # ... except that 'line' may be an entire file. ;-)
294
 
        my($self, $fh) = @_;
 
376
        my ($self, $fh) = @_;
295
377
        die "Not in lines" unless defined $self->{'lines'};
296
378
 
297
379
        my $line;
298
380
        my $res=0;
299
 
        while(defined($line = $self->readline())) {
 
381
        while (defined($line = $self->readline())) {
300
382
                # M U gnupg-cvs-rep/AUTHORS
301
383
                # Updated gnupg-cvs-rep/
302
384
                # /daten/src/rsync/gnupg-cvs-rep/AUTHORS
305
387
                # 0
306
388
                # ok
307
389
 
308
 
                if($line =~ s/^(?:Created|Updated) //) {
 
390
                if ($line =~ s/^(?:Created|Updated) //) {
309
391
                        $line = $self->readline(); # path
310
392
                        $line = $self->readline(); # Entries line
311
393
                        my $mode = $self->readline(); chomp $mode;
316
398
                        die "Duh: Filesize $cnt" if $cnt !~ /^\d+$/;
317
399
                        $line="";
318
400
                        $res = $self->_fetchfile($fh, $cnt);
319
 
                } elsif($line =~ s/^ //) {
 
401
                } elsif ($line =~ s/^ //) {
320
402
                        print $fh $line;
321
403
                        $res += length($line);
322
 
                } elsif($line =~ /^M\b/) {
 
404
                } elsif ($line =~ /^M\b/) {
323
405
                        # output, do nothing
324
 
                } elsif($line =~ /^Mbinary\b/) {
 
406
                } elsif ($line =~ /^Mbinary\b/) {
325
407
                        my $cnt;
326
408
                        die "EOF from server after 'Mbinary'" unless defined ($cnt = $self->readline());
327
409
                        chomp $cnt;
330
412
                        $res += $self->_fetchfile($fh, $cnt);
331
413
                } else {
332
414
                        chomp $line;
333
 
                        if($line eq "ok") {
 
415
                        if ($line eq "ok") {
334
416
                                # print STDERR "S: ok (".length($res).")\n";
335
417
                                return $res;
336
 
                        } elsif($line =~ s/^E //) {
 
418
                        } elsif ($line =~ s/^E //) {
337
419
                                # print STDERR "S: $line\n";
338
 
                        } elsif($line =~ /^(Remove-entry|Removed) /i) {
 
420
                        } elsif ($line =~ /^(Remove-entry|Removed) /i) {
339
421
                                $line = $self->readline(); # filename
340
422
                                $line = $self->readline(); # OK
341
423
                                chomp $line;
349
431
        return undef;
350
432
}
351
433
sub file {
352
 
        my($self,$fn,$rev) = @_;
 
434
        my ($self,$fn,$rev) = @_;
353
435
        my $res;
354
436
 
355
437
        my ($fh, $name) = tempfile('gitcvs.XXXXXX', 
373
455
        my ($self, $fh, $cnt) = @_;
374
456
        my $res = 0;
375
457
        my $bufsize = 1024 * 1024;
376
 
        while($cnt) {
 
458
        while ($cnt) {
377
459
            if ($bufsize > $cnt) {
378
460
                $bufsize = $cnt;
379
461
            }
394
476
 
395
477
 
396
478
sub pdate($) {
397
 
        my($d) = @_;
 
479
        my ($d) = @_;
398
480
        m#(\d{2,4})/(\d\d)/(\d\d)\s(\d\d):(\d\d)(?::(\d\d))?#
399
481
                or die "Unparseable date: $d\n";
400
482
        my $y=$1; $y-=1900 if $y>1900;
402
484
}
403
485
 
404
486
sub pmode($) {
405
 
        my($mode) = @_;
 
487
        my ($mode) = @_;
406
488
        my $m = 0;
407
489
        my $mm = 0;
408
490
        my $um = 0;
409
491
        for my $x(split(//,$mode)) {
410
 
                if($x eq ",") {
 
492
                if ($x eq ",") {
411
493
                        $m |= $mm&$um;
412
494
                        $mm = 0;
413
495
                        $um = 0;
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
 
496
                } elsif ($x eq "u") { $um |= 0700;
 
497
                } elsif ($x eq "g") { $um |= 0070;
 
498
                } elsif ($x eq "o") { $um |= 0007;
 
499
                } elsif ($x eq "r") { $mm |= 0444;
 
500
                } elsif ($x eq "w") { $mm |= 0222;
 
501
                } elsif ($x eq "x") { $mm |= 0111;
 
502
                } elsif ($x eq "=") { # do nothing
421
503
                } else { die "Unknown mode: $mode\n";
422
504
                }
423
505
        }
441
523
    my $git_dir = shift; 
442
524
    
443
525
    my $f = "$git_dir/refs/heads/$name";
444
 
    if(open(my $fh, $f)) {
 
526
    if (open(my $fh, $f)) {
445
527
            chomp(my $r = <$fh>);
446
528
            is_sha1($r) or die "Cannot get head id for $name ($r): $!";
447
529
            return $r;
468
550
 
469
551
my %index; # holds filenames of one index per branch
470
552
 
471
 
unless(-d $git_dir) {
472
 
        system("git-init-db");
 
553
unless (-d $git_dir) {
 
554
        system("git-init");
473
555
        die "Cannot init the GIT db at $git_tree: $?\n" if $?;
474
556
        system("git-read-tree");
475
557
        die "Cannot init an empty tree: $?\n" if $?;
487
569
        chomp ($last_branch = <F>);
488
570
        $last_branch = basename($last_branch);
489
571
        close(F);
490
 
        unless($last_branch) {
 
572
        unless ($last_branch) {
491
573
                warn "Cannot read the last branch name: $! -- assuming 'master'\n";
492
574
                $last_branch = "master";
493
575
        }
498
580
        my $fmt = '($ref, $author) = (%(refname), %(author));';
499
581
        open(H, "git-for-each-ref --perl --format='$fmt' refs/heads |") or
500
582
                die "Cannot run git-for-each-ref: $!\n";
501
 
        while(defined(my $entry = <H>)) {
 
583
        while (defined(my $entry = <H>)) {
502
584
                my ($ref, $author);
503
585
                eval($entry) || die "cannot eval refs list: $@";
504
586
                my ($head) = ($ref =~ m|^refs/heads/(.*)|);
524
606
# run cvsps into a file unless we are getting
525
607
# it passed as a file via $opt_P
526
608
#
 
609
my $cvspsfile;
527
610
unless ($opt_P) {
528
611
        print "Running cvsps...\n" if $opt_v;
529
612
        my $pid = open(CVSPS,"-|");
 
613
        my $cvspsfh;
530
614
        die "Cannot fork: $!\n" unless defined $pid;
531
 
        unless($pid) {
 
615
        unless ($pid) {
532
616
                my @opt;
533
617
                @opt = split(/,/,$opt_p) if defined $opt_p;
534
618
                unshift @opt, '-z', $opt_z if defined $opt_z;
539
623
                exec("cvsps","--norc",@opt,"-u","-A",'--root',$opt_d,$cvs_tree);
540
624
                die "Could not start cvsps: $!\n";
541
625
        }
542
 
        my ($cvspsfh, $cvspsfile) = tempfile('gitXXXXXX', SUFFIX => '.cvsps',
543
 
                                             DIR => File::Spec->tmpdir());
 
626
        ($cvspsfh, $cvspsfile) = tempfile('gitXXXXXX', SUFFIX => '.cvsps',
 
627
                                          DIR => File::Spec->tmpdir());
544
628
        while (<CVSPS>) {
545
629
            print $cvspsfh $_;
546
630
        }
547
631
        close CVSPS;
548
632
        close $cvspsfh;
549
 
        $opt_P = $cvspsfile;
 
633
} else {
 
634
        $cvspsfile = $opt_P;
550
635
}
551
636
 
552
 
 
553
 
open(CVS, "<$opt_P") or die $!;
 
637
open(CVS, "<$cvspsfile") or die $!;
554
638
 
555
639
## cvsps output:
556
640
#---------------------
598
682
        return $tree;
599
683
}
600
684
 
601
 
my($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
602
 
my(@old,@new,@skipped,%ignorebranch);
 
685
my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg);
 
686
my (@old,@new,@skipped,%ignorebranch);
603
687
 
604
688
# commits that cvsps cannot place anywhere...
605
689
$ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
607
691
sub commit {
608
692
        if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) {
609
693
            # looks like an initial commit
610
 
            # use the index primed by git-init-db
 
694
            # use the index primed by git-init
611
695
            $ENV{GIT_INDEX_FILE} = '.git/index';
612
696
            $index{$branch} = '.git/index';
613
697
        } else {
640
724
        foreach my $rx (@mergerx) {
641
725
                next unless $logmsg =~ $rx && $1;
642
726
                my $mparent = $1 eq 'HEAD' ? $opt_o : $1;
643
 
                if(my $sha1 = get_headref($mparent, $git_dir)) {
 
727
                if (my $sha1 = get_headref($mparent, $git_dir)) {
644
728
                        push @commit_args, '-p', $mparent;
645
729
                        print "Merge parent branch: $mparent\n" if $opt_v;
646
730
                }
681
765
        system("git-update-ref refs/heads/$branch $cid") == 0
682
766
                or die "Cannot write branch $branch for update: $!\n";
683
767
 
684
 
        if($tag) {
685
 
                my($in, $out) = ('','');
686
 
                my($xtag) = $tag;
 
768
        if ($tag) {
 
769
                my ($in, $out) = ('','');
 
770
                my ($xtag) = $tag;
687
771
                $xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY **
688
772
                $xtag =~ tr/_/\./ if ( $opt_u );
689
773
                $xtag =~ s/[\/]/$opt_s/g;
718
802
};
719
803
 
720
804
my $commitcount = 1;
721
 
while(<CVS>) {
 
805
while (<CVS>) {
722
806
        chomp;
723
 
        if($state == 0 and /^-+$/) {
 
807
        if ($state == 0 and /^-+$/) {
724
808
                $state = 1;
725
 
        } elsif($state == 0) {
 
809
        } elsif ($state == 0) {
726
810
                $state = 1;
727
811
                redo;
728
 
        } elsif(($state==0 or $state==1) and s/^PatchSet\s+//) {
 
812
        } elsif (($state==0 or $state==1) and s/^PatchSet\s+//) {
729
813
                $patchset = 0+$_;
730
814
                $state=2;
731
 
        } elsif($state == 2 and s/^Date:\s+//) {
 
815
        } elsif ($state == 2 and s/^Date:\s+//) {
732
816
                $date = pdate($_);
733
 
                unless($date) {
 
817
                unless ($date) {
734
818
                        print STDERR "Could not parse date: $_\n";
735
819
                        $state=0;
736
820
                        next;
737
821
                }
738
822
                $state=3;
739
 
        } elsif($state == 3 and s/^Author:\s+//) {
 
823
        } elsif ($state == 3 and s/^Author:\s+//) {
740
824
                s/\s+$//;
741
825
                if (/^(.*?)\s+<(.*)>/) {
742
826
                    ($author_name, $author_email) = ($1, $2);
747
831
                    $author_name = $author_email = $_;
748
832
                }
749
833
                $state = 4;
750
 
        } elsif($state == 4 and s/^Branch:\s+//) {
 
834
        } elsif ($state == 4 and s/^Branch:\s+//) {
751
835
                s/\s+$//;
752
836
                s/[\/]/$opt_s/g;
753
837
                $branch = $_;
754
838
                $state = 5;
755
 
        } elsif($state == 5 and s/^Ancestor branch:\s+//) {
 
839
        } elsif ($state == 5 and s/^Ancestor branch:\s+//) {
756
840
                s/\s+$//;
757
841
                $ancestor = $_;
758
842
                $ancestor = $opt_o if $ancestor eq "HEAD";
759
843
                $state = 6;
760
 
        } elsif($state == 5) {
 
844
        } elsif ($state == 5) {
761
845
                $ancestor = undef;
762
846
                $state = 6;
763
847
                redo;
764
 
        } elsif($state == 6 and s/^Tag:\s+//) {
 
848
        } elsif ($state == 6 and s/^Tag:\s+//) {
765
849
                s/\s+$//;
766
 
                if($_ eq "(none)") {
 
850
                if ($_ eq "(none)") {
767
851
                        $tag = undef;
768
852
                } else {
769
853
                        $tag = $_;
770
854
                }
771
855
                $state = 7;
772
 
        } elsif($state == 7 and /^Log:/) {
 
856
        } elsif ($state == 7 and /^Log:/) {
773
857
                $logmsg = "";
774
858
                $state = 8;
775
 
        } elsif($state == 8 and /^Members:/) {
 
859
        } elsif ($state == 8 and /^Members:/) {
776
860
                $branch = $opt_o if $branch eq "HEAD";
777
 
                if(defined $branch_date{$branch} and $branch_date{$branch} >= $date) {
 
861
                if (defined $branch_date{$branch} and $branch_date{$branch} >= $date) {
778
862
                        # skip
779
863
                        print "skip patchset $patchset: $date before $branch_date{$branch}\n" if $opt_v;
780
864
                        $state = 11;
781
865
                        next;
782
866
                }
 
867
                if (!$opt_a && $starttime - 300 - (defined $opt_z ? $opt_z : 300) <= $date) {
 
868
                        # skip if the commit is too recent
 
869
                        # that the cvsps default fuzz is 300s, we give ourselves another
 
870
                        # 300s just in case -- this also prevents skipping commits
 
871
                        # due to server clock drift
 
872
                        print "skip patchset $patchset: $date too recent\n" if $opt_v;
 
873
                        $state = 11;
 
874
                        next;
 
875
                }
783
876
                if (exists $ignorebranch{$branch}) {
784
877
                        print STDERR "Skipping $branch\n";
785
878
                        $state = 11;
786
879
                        next;
787
880
                }
788
 
                if($ancestor) {
789
 
                        if($ancestor eq $branch) {
 
881
                if ($ancestor) {
 
882
                        if ($ancestor eq $branch) {
790
883
                                print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
791
884
                                $ancestor = $opt_o;
792
885
                        }
793
 
                        if(-f "$git_dir/refs/heads/$branch") {
 
886
                        if (-f "$git_dir/refs/heads/$branch") {
794
887
                                print STDERR "Branch $branch already exists!\n";
795
888
                                $state=11;
796
889
                                next;
797
890
                        }
798
 
                        unless(open(H,"$git_dir/refs/heads/$ancestor")) {
 
891
                        unless (open(H,"$git_dir/refs/heads/$ancestor")) {
799
892
                                print STDERR "Branch $ancestor does not exist!\n";
800
893
                                $ignorebranch{$branch} = 1;
801
894
                                $state=11;
803
896
                        }
804
897
                        chomp(my $id = <H>);
805
898
                        close(H);
806
 
                        unless(open(H,"> $git_dir/refs/heads/$branch")) {
 
899
                        unless (open(H,"> $git_dir/refs/heads/$branch")) {
807
900
                                print STDERR "Could not create branch $branch: $!\n";
808
901
                                $ignorebranch{$branch} = 1;
809
902
                                $state=11;
816
909
                }
817
910
                $last_branch = $branch if $branch ne $last_branch;
818
911
                $state = 9;
819
 
        } elsif($state == 8) {
 
912
        } elsif ($state == 8) {
820
913
                $logmsg .= "$_\n";
821
 
        } elsif($state == 9 and /^\s+(.+?):(INITIAL|\d+(?:\.\d+)+)->(\d+(?:\.\d+)+)\s*$/) {
 
914
        } elsif ($state == 9 and /^\s+(.+?):(INITIAL|\d+(?:\.\d+)+)->(\d+(?:\.\d+)+)\s*$/) {
822
915
#       VERSION:1.96->1.96.2.1
823
916
                my $init = ($2 eq "INITIAL");
824
917
                my $fn = $1;
831
924
                }
832
925
                print "Fetching $fn   v $rev\n" if $opt_v;
833
926
                my ($tmpname, $size) = $cvs->file($fn,$rev);
834
 
                if($size == -1) {
 
927
                if ($size == -1) {
835
928
                        push(@old,$fn);
836
929
                        print "Drop $fn\n" if $opt_v;
837
930
                } else {
849
942
                        push(@new,[$mode, $sha, $fn]); # may be resurrected!
850
943
                }
851
944
                unlink($tmpname);
852
 
        } elsif($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
 
945
        } elsif ($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) {
853
946
                my $fn = $1;
854
947
                $fn =~ s#^/+##;
855
948
                push(@old,$fn);
856
949
                print "Delete $fn\n" if $opt_v;
857
 
        } elsif($state == 9 and /^\s*$/) {
 
950
        } elsif ($state == 9 and /^\s*$/) {
858
951
                $state = 10;
859
 
        } elsif(($state == 9 or $state == 10) and /^-+$/) {
 
952
        } elsif (($state == 9 or $state == 10) and /^-+$/) {
860
953
                $commitcount++;
861
954
                if ($opt_L && $commitcount > $opt_L) {
862
955
                        last;
866
959
                        system("git repack -a -d");
867
960
                }
868
961
                $state = 1;
869
 
        } elsif($state == 11 and /^-+$/) {
870
 
                $state = 1;
871
 
        } elsif(/^-+$/) { # end of unknown-line processing
872
 
                $state = 1;
873
 
        } elsif($state != 11) { # ignore stuff when skipping
 
962
        } elsif ($state == 11 and /^-+$/) {
 
963
                $state = 1;
 
964
        } elsif (/^-+$/) { # end of unknown-line processing
 
965
                $state = 1;
 
966
        } elsif ($state != 11) { # ignore stuff when skipping
874
967
                print "* UNKNOWN LINE * $_\n";
875
968
        }
876
969
}
877
970
commit() if $branch and $state != 11;
878
971
 
 
972
unless ($opt_P) {
 
973
        unlink($cvspsfile);
 
974
}
 
975
 
879
976
# The heuristic of repacking every 1024 commits can leave a
880
977
# lot of unpacked data.  If there is more than 1MB worth of
881
978
# not-packed objects, repack once more.
899
996
}
900
997
 
901
998
# Now switch back to the branch we were in before all of this happened
902
 
if($orig_branch) {
 
999
if ($orig_branch) {
903
1000
        print "DONE.\n" if $opt_v;
904
1001
        if ($opt_i) {
905
1002
                exit 0;