@matheusbsbs / matheus-bagliano / commits / 8b7f5fc1ca
Fork 0

cvsimport: add support for new style remote layout

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>

Andy Whitcroft committed May 30, 2007 at 01:56 UTC 8b7f5fc1cac8eb49b4846021706fc06ce074881b
1 file changed +22 -14
git-cvsimport.perl
+22 -14
@@ -29,7 +29,7 @@ use IPC::Open2;
29 $SIG{'PIPE'}="IGNORE";
30 $ENV{'TZ'}="UTC";
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, $opt_a);
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, $opt_r);
33 my (%conv_author_name, %conv_author_email);
34
35 sub usage(;$) {
@@ -114,7 +114,7 @@ sub read_repo_config {
114 }
115 }
116
117 -my $opts = "haivmkuo:d:p:C:z:s:M:P:A:S:L:";
117 +my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:";
118 read_repo_config($opts);
119 getopts($opts) or usage();
120 usage if $opt_h;
@@ -134,13 +134,21 @@ if ($opt_d) {
134 } else {
135 usage("CVSROOT needs to be set");
136 }
137 -$opt_o ||= "origin";
137 $opt_s ||= "-";
138 $opt_a ||= 0;
139
140 my $git_tree = $opt_C;
141 $git_tree ||= ".";
142
143 +my $remote;
144 +if (defined $opt_r) {
145 + $remote = 'refs/remotes/' . $opt_r;
146 + $opt_o ||= "master";
147 +} else {
148 + $opt_o ||= "origin";
149 + $remote = 'refs/heads';
150 +}
151 +
152 my $cvs_tree;
153 if ($#ARGV == 0) {
154 $cvs_tree = $ARGV[0];
@@ -522,7 +530,7 @@ sub get_headref ($$) {
530 my $name = shift;
531 my $git_dir = shift;
532
525 - my $f = "$git_dir/refs/heads/$name";
533 + my $f = "$git_dir/$remote/$name";
534 if (open(my $fh, $f)) {
535 chomp(my $r = <$fh>);
536 is_sha1($r) or die "Cannot get head id for $name ($r): $!";
@@ -573,12 +581,12 @@ unless (-d $git_dir) {
581
582 # Get the last import timestamps
583 my $fmt = '($ref, $author) = (%(refname), %(author));';
576 - open(H, "git-for-each-ref --perl --format='$fmt' refs/heads |") or
584 + open(H, "git-for-each-ref --perl --format='$fmt' $remote |") or
585 die "Cannot run git-for-each-ref: $!\n";
586 while (defined(my $entry = <H>)) {
587 my ($ref, $author);
588 eval($entry) || die "cannot eval refs list: $@";
581 - my ($head) = ($ref =~ m|^refs/heads/(.*)|);
589 + my ($head) = ($ref =~ m|^$remote/(.*)|);
590 $author =~ /^.*\s(\d+)\s[-+]\d{4}$/;
591 $branch_date{$head} = $1;
592 }
@@ -701,9 +709,9 @@ sub commit {
709 $index{$branch} = tmpnam();
710 $ENV{GIT_INDEX_FILE} = $index{$branch};
711 if ($ancestor) {
704 - system("git-read-tree", $ancestor);
712 + system("git-read-tree", "$remote/$ancestor");
713 } else {
706 - system("git-read-tree", $branch);
714 + system("git-read-tree", "$remote/$branch");
715 }
716 die "read-tree failed: $?\n" if $?;
717 }
@@ -762,7 +770,7 @@ sub commit {
770 waitpid($pid,0);
771 die "Error running git-commit-tree: $?\n" if $?;
772
765 - system("git-update-ref refs/heads/$branch $cid") == 0
773 + system("git-update-ref $remote/$branch $cid") == 0
774 or die "Cannot write branch $branch for update: $!\n";
775
776 if ($tag) {
@@ -883,12 +891,12 @@ while (<CVS>) {
891 print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
892 $ancestor = $opt_o;
893 }
886 - if (-f "$git_dir/refs/heads/$branch") {
894 + if (-f "$git_dir/$remote/$branch") {
895 print STDERR "Branch $branch already exists!\n";
896 $state=11;
897 next;
898 }
891 - unless (open(H,"$git_dir/refs/heads/$ancestor")) {
899 + unless (open(H,"$git_dir/$remote/$ancestor")) {
900 print STDERR "Branch $ancestor does not exist!\n";
901 $ignorebranch{$branch} = 1;
902 $state=11;
@@ -896,7 +904,7 @@ while (<CVS>) {
904 }
905 chomp(my $id = <H>);
906 close(H);
899 - unless (open(H,"> $git_dir/refs/heads/$branch")) {
907 + unless (open(H,"> $git_dir/$remote/$branch")) {
908 print STDERR "Could not create branch $branch: $!\n";
909 $ignorebranch{$branch} = 1;
910 $state=11;
@@ -1010,13 +1018,13 @@ if ($orig_branch) {
1018 die "Fast-forward update failed: $?\n" if $?;
1019 }
1020 else {
1013 - system(qw(git-merge cvsimport HEAD), "refs/heads/$opt_o");
1021 + system(qw(git-merge cvsimport HEAD), "$remote/$opt_o");
1022 die "Could not merge $opt_o into the current branch.\n" if $?;
1023 }
1024 } else {
1025 $orig_branch = "master";
1026 print "DONE; creating $orig_branch branch\n" if $opt_v;
1019 - system("git-update-ref", "refs/heads/master", "refs/heads/$opt_o")
1027 + system("git-update-ref", "refs/heads/master", "$remote/$opt_o")
1028 unless -f "$git_dir/refs/heads/master";
1029 system('git-update-ref', 'HEAD', "$orig_branch");
1030 unless ($opt_i) {