# 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);
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");
}
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");
+