# Basic CVS dialog.
# We're only interested in connecting and downloading, so ...
+use POSIX qw(strftime dup2);
+
sub new {
my($what,$repo,$subdir) = @_;
$what=ref($what) if ref($what);
$self->{'socketo'}->write("Argument $self->{'subdir'}/$fn\n") or return undef;
$self->{'socketo'}->write("Directory .\n") or return undef;
$self->{'socketo'}->write("$self->{'repo'}\n") or return undef;
- $self->{'socketo'}->write("Sticky T1.1\n") or return undef;
+ # $self->{'socketo'}->write("Sticky T1.0\n") or return undef;
$self->{'socketo'}->write("co\n") or return undef;
$self->{'socketo'}->flush() or return undef;
$self->{'lines'} = 0;
chdir($git_tree);
my $last_branch = "";
+my $orig_branch = "";
my %branch_date;
my $git_dir = $ENV{"GIT_DIR"} || ".git";
die "Cannot init an empty tree: $?\n" if $?;
$last_branch = $opt_o;
+ $orig_branch = "";
} else {
$last_branch = basename(readlink("$git_dir/HEAD"));
- die "Cannot read the last branch name: $!\n" unless $last_branch;
+ unless($last_branch) {
+ warn "Cannot read the last branch name: $! -- assuming 'master'\n";
+ $last_branch = "master";
+ }
+ $orig_branch = $last_branch;
# Get the last import timestamps
opendir(D,"$git_dir/refs/heads");
my(@old,@new);
my $commit = sub {
my $pid;
- system("git-update-cache","--force-remove","--",@old) if @old;
- die "Cannot remove files: $?\n" if $?;
- system("git-update-cache","--add","--",@new) if @new;
- die "Cannot add files: $?\n" if $?;
+ while(@old) {
+ my @o2;
+ if(@old > 55) {
+ @o2 = splice(@old,0,50);
+ } else {
+ @o2 = @old;
+ @old = ();
+ }
+ system("git-update-cache","--force-remove","--",@o2);
+ die "Cannot remove files: $?\n" if $?;
+ }
+ while(@new) {
+ my @n2;
+ if(@new > 55) {
+ @n2 = splice(@new,0,50);
+ } else {
+ @n2 = @new;
+ @new = ();
+ }
+ system("git-update-cache","--add","--",@n2);
+ die "Cannot add files: $?\n" if $?;
+ }
$pid = open(C,"-|");
die "Cannot fork: $!" unless defined $pid;
or die "Cannot write tag $branch: $!\n";
print "Created tag '$tag' on '$branch'\n" if $opt_v;
}
-
- @old = ();
- @new = ();
};
while(<CVS>) {
} elsif($state == 5 and s/^Ancestor branch:\s+//) {
s/\s+$//;
$ancestor = $_;
- $ancestor = $opt_o if $ancestor == "HEAD";
+ $ancestor = $opt_o if $ancestor eq "HEAD";
$state = 6;
} elsif($state == 5) {
$ancestor = undef;
}
if(($ancestor || $branch) ne $last_branch) {
print "Switching from $last_branch to $branch\n" if $opt_v;
- system("git-read-tree -m -u $last_branch $branch");
- die "read-tree $branch failed at $branch: $?\n" if $?;
+ system("git-read-tree","-m","-u","$last_branch","$branch");
+ die "read-tree failed: $?\n" if $?;
}
if($branch ne $last_branch) {
unlink("$git_dir/HEAD");
# VERSION:1.96->1.96.2.1
my $init = ($2 eq "INITIAL");
my $fn = $1;
- my $data = $cvs->file($fn,$3);
+ my $rev = $3;
+ $fn =~ s#^/+##;
+ my $data = $cvs->file($fn,$rev);
print "".($init ? "New" : "Update")." $fn: ".length($data)." bytes.\n";
mkpath(dirname($fn),$opt_v);
open(F,"> ./$fn")
chmod(pmode($cvs->{'mode'}), $fn);
push(@new,$fn); # may be resurrected!
} elsif($state == 9 and /^\s+(\S+):\d(?:\.\d+)+->(\d(?:\.\d+)+)\(DEAD\)\s*$/) {
- push(@old,$1);
+ my $fn = $1;
+ $fn =~ s#^/+##;
+ push(@old,$fn);
} elsif($state == 9 and /^\s*$/) {
$state = 10;
} elsif(($state == 9 or $state == 10) and /^-+$/) {
}
&$commit() if $branch and $state != 11;
-print "DONE\n" if $opt_v;
+# Now switch back to the branch we were in before all of this happened
+if($orig_branch) {
+ print "DONE; switching back to $orig_branch\n" if $opt_v;
+} else {
+ $orig_branch = "master";
+ print "DONE; creating $orig_branch branch\n" if $opt_v;
+ system("cp","$git_dir/refs/heads/$opt_o","$git_dir/refs/heads/master")
+ unless -f "$git_dir/refs/heads/master";
+}
+
+system("git-read-tree","-m","-u","$last_branch","$orig_branch");
+die "read-tree failed: $?\n" if $?;
+
+unlink("$git_dir/HEAD");
+symlink("refs/heads/$orig_branch","$git_dir/HEAD");
+