cvsimport: add support for new style remote layout
authorAndy Whitcroft <apw@shadowen.org>
Wed, 30 May 2007 00:56:41 +0000 (01:56 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 6 Jun 2007 09:35:49 +0000 (02:35 -0700)
cvsimport creates any branches found in the remote CVS repository
in the refs/heads namespace. This makes sense for a repository
conversion. When using git as a sane interface to a remote CVS
repository, that repository may well remain as the 'master'
respository. In this model it makes sense to import the CVS
repository into the refs/remotes namespace.

Add a new option '-r <remote>' to set the remote name for
this import. When this option is specified branches are named
refs/remotes/<remote>/branch, with HEAD named as master matching
git-clone separate remotes layout. Without branches are placed
ion refs/heads, with HEAD named origin as before.

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-cvsimport.perl
index f68afe78a0a0ea4997b8988f241cd3a675d785f9..f16ac3d8a06692e5b93222dee55ff41b4bee2d64 100755 (executable)
@@ -29,7 +29,7 @@
 $SIG{'PIPE'}="IGNORE";
 $ENV{'TZ'}="UTC";
 
 $SIG{'PIPE'}="IGNORE";
 $ENV{'TZ'}="UTC";
 
-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);
+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, $opt_r);
 my (%conv_author_name, %conv_author_email);
 
 sub usage(;$) {
 my (%conv_author_name, %conv_author_email);
 
 sub usage(;$) {
@@ -114,7 +114,7 @@ sub read_repo_config {
     }
 }
 
     }
 }
 
-my $opts = "haivmkuo:d:p:C:z:s:M:P:A:S:L:";
+my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:";
 read_repo_config($opts);
 getopts($opts) or usage();
 usage if $opt_h;
 read_repo_config($opts);
 getopts($opts) or usage();
 usage if $opt_h;
@@ -134,13 +134,21 @@ sub read_repo_config {
 } else {
        usage("CVSROOT needs to be set");
 }
 } else {
        usage("CVSROOT needs to be set");
 }
-$opt_o ||= "origin";
 $opt_s ||= "-";
 $opt_a ||= 0;
 
 my $git_tree = $opt_C;
 $git_tree ||= ".";
 
 $opt_s ||= "-";
 $opt_a ||= 0;
 
 my $git_tree = $opt_C;
 $git_tree ||= ".";
 
+my $remote;
+if (defined $opt_r) {
+       $remote = 'refs/remotes/' . $opt_r;
+       $opt_o ||= "master";
+} else {
+       $opt_o ||= "origin";
+       $remote = 'refs/heads';
+}
+
 my $cvs_tree;
 if ($#ARGV == 0) {
        $cvs_tree = $ARGV[0];
 my $cvs_tree;
 if ($#ARGV == 0) {
        $cvs_tree = $ARGV[0];
@@ -522,7 +530,7 @@ ($$)
     my $name    = shift;
     my $git_dir = shift; 
     
     my $name    = shift;
     my $git_dir = shift; 
     
-    my $f = "$git_dir/refs/heads/$name";
+    my $f = "$git_dir/$remote/$name";
     if (open(my $fh, $f)) {
            chomp(my $r = <$fh>);
            is_sha1($r) or die "Cannot get head id for $name ($r): $!";
     if (open(my $fh, $f)) {
            chomp(my $r = <$fh>);
            is_sha1($r) or die "Cannot get head id for $name ($r): $!";
@@ -573,12 +581,12 @@ ($$)
 
        # Get the last import timestamps
        my $fmt = '($ref, $author) = (%(refname), %(author));';
 
        # Get the last import timestamps
        my $fmt = '($ref, $author) = (%(refname), %(author));';
-       open(H, "git-for-each-ref --perl --format='$fmt' refs/heads |") or
+       open(H, "git-for-each-ref --perl --format='$fmt' $remote |") or
                die "Cannot run git-for-each-ref: $!\n";
        while (defined(my $entry = <H>)) {
                my ($ref, $author);
                eval($entry) || die "cannot eval refs list: $@";
                die "Cannot run git-for-each-ref: $!\n";
        while (defined(my $entry = <H>)) {
                my ($ref, $author);
                eval($entry) || die "cannot eval refs list: $@";
-               my ($head) = ($ref =~ m|^refs/heads/(.*)|);
+               my ($head) = ($ref =~ m|^$remote/(.*)|);
                $author =~ /^.*\s(\d+)\s[-+]\d{4}$/;
                $branch_date{$head} = $1;
        }
                $author =~ /^.*\s(\d+)\s[-+]\d{4}$/;
                $branch_date{$head} = $1;
        }
@@ -701,9 +709,9 @@ sub commit {
                $index{$branch} = tmpnam();
                $ENV{GIT_INDEX_FILE} = $index{$branch};
                if ($ancestor) {
                $index{$branch} = tmpnam();
                $ENV{GIT_INDEX_FILE} = $index{$branch};
                if ($ancestor) {
-                   system("git-read-tree", $ancestor);
+                   system("git-read-tree", "$remote/$ancestor");
                } else {
                } else {
-                   system("git-read-tree", $branch);
+                   system("git-read-tree", "$remote/$branch");
                }
                die "read-tree failed: $?\n" if $?;
            }
                }
                die "read-tree failed: $?\n" if $?;
            }
@@ -762,7 +770,7 @@ sub commit {
        waitpid($pid,0);
        die "Error running git-commit-tree: $?\n" if $?;
 
        waitpid($pid,0);
        die "Error running git-commit-tree: $?\n" if $?;
 
-       system("git-update-ref refs/heads/$branch $cid") == 0
+       system("git-update-ref $remote/$branch $cid") == 0
                or die "Cannot write branch $branch for update: $!\n";
 
        if ($tag) {
                or die "Cannot write branch $branch for update: $!\n";
 
        if ($tag) {
@@ -883,12 +891,12 @@ sub commit {
                                print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
                                $ancestor = $opt_o;
                        }
                                print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
                                $ancestor = $opt_o;
                        }
-                       if (-f "$git_dir/refs/heads/$branch") {
+                       if (-f "$git_dir/$remote/$branch") {
                                print STDERR "Branch $branch already exists!\n";
                                $state=11;
                                next;
                        }
                                print STDERR "Branch $branch already exists!\n";
                                $state=11;
                                next;
                        }
-                       unless (open(H,"$git_dir/refs/heads/$ancestor")) {
+                       unless (open(H,"$git_dir/$remote/$ancestor")) {
                                print STDERR "Branch $ancestor does not exist!\n";
                                $ignorebranch{$branch} = 1;
                                $state=11;
                                print STDERR "Branch $ancestor does not exist!\n";
                                $ignorebranch{$branch} = 1;
                                $state=11;
@@ -896,7 +904,7 @@ sub commit {
                        }
                        chomp(my $id = <H>);
                        close(H);
                        }
                        chomp(my $id = <H>);
                        close(H);
-                       unless (open(H,"> $git_dir/refs/heads/$branch")) {
+                       unless (open(H,"> $git_dir/$remote/$branch")) {
                                print STDERR "Could not create branch $branch: $!\n";
                                $ignorebranch{$branch} = 1;
                                $state=11;
                                print STDERR "Could not create branch $branch: $!\n";
                                $ignorebranch{$branch} = 1;
                                $state=11;
@@ -1010,13 +1018,13 @@ sub commit {
                die "Fast-forward update failed: $?\n" if $?;
        }
        else {
                die "Fast-forward update failed: $?\n" if $?;
        }
        else {
-               system(qw(git-merge cvsimport HEAD), "refs/heads/$opt_o");
+               system(qw(git-merge cvsimport HEAD), "$remote/$opt_o");
                die "Could not merge $opt_o into the current branch.\n" if $?;
        }
 } else {
        $orig_branch = "master";
        print "DONE; creating $orig_branch branch\n" if $opt_v;
                die "Could not merge $opt_o into the current branch.\n" if $?;
        }
 } else {
        $orig_branch = "master";
        print "DONE; creating $orig_branch branch\n" if $opt_v;
-       system("git-update-ref", "refs/heads/master", "refs/heads/$opt_o")
+       system("git-update-ref", "refs/heads/master", "$remote/$opt_o")
                unless -f "$git_dir/refs/heads/master";
        system('git-update-ref', 'HEAD', "$orig_branch");
        unless ($opt_i) {
                unless -f "$git_dir/refs/heads/master";
        system('git-update-ref', 'HEAD', "$orig_branch");
        unless ($opt_i) {