git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cvsimport: add support for new style remote layout
@ 2007-05-30  0:56 Andy Whitcroft
  2007-05-30 13:24 ` James Bowes
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Andy Whitcroft @ 2007-05-30  0:56 UTC (permalink / raw)
  To: git


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>
---

	Given that separate remotes is the default for 1.5
	it could be argued that this the default should be the
	equivalent of '-r origin'.  This patch does not do that.
---
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index f68afe7..f16ac3d 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -29,7 +29,7 @@ use IPC::Open2;
 $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(;$) {
@@ -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;
@@ -134,13 +134,21 @@ if ($opt_d) {
 } else {
 	usage("CVSROOT needs to be set");
 }
-$opt_o ||= "origin";
 $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];
@@ -522,7 +530,7 @@ sub get_headref ($$) {
     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): $!";
@@ -573,12 +581,12 @@ unless (-d $git_dir) {
 
 	# 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: $@";
-		my ($head) = ($ref =~ m|^refs/heads/(.*)|);
+		my ($head) = ($ref =~ m|^$remote/(.*)|);
 		$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) {
-		    system("git-read-tree", $ancestor);
+		    system("git-read-tree", "$remote/$ancestor");
 		} else {
-		    system("git-read-tree", $branch);
+		    system("git-read-tree", "$remote/$branch");
 		}
 		die "read-tree failed: $?\n" if $?;
 	    }
@@ -762,7 +770,7 @@ sub commit {
 	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) {
@@ -883,12 +891,12 @@ while (<CVS>) {
 				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;
 			}
-			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;
@@ -896,7 +904,7 @@ while (<CVS>) {
 			}
 			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;
@@ -1010,13 +1018,13 @@ if ($orig_branch) {
 		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;
-	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) {

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] cvsimport: add support for new style remote layout
  2007-05-30  0:56 [PATCH] cvsimport: add support for new style remote layout Andy Whitcroft
@ 2007-05-30 13:24 ` James Bowes
  2007-06-03 22:00 ` Junio C Hamano
  2007-06-06 11:52 ` [PATCH] cvsimport: add support for new style remote layout Jeffrey C. Ollie
  2 siblings, 0 replies; 7+ messages in thread
From: James Bowes @ 2007-05-30 13:24 UTC (permalink / raw)
  To: Andy Whitcroft; +Cc: git

On 5/29/07, Andy Whitcroft <apw@shadowen.org> wrote:
> 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.

I love this. It's really nice to have 'git branch' not cluttered with
remote branches.

-James

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] cvsimport: add support for new style remote layout
  2007-05-30  0:56 [PATCH] cvsimport: add support for new style remote layout Andy Whitcroft
  2007-05-30 13:24 ` James Bowes
@ 2007-06-03 22:00 ` Junio C Hamano
  2007-06-04  8:58   ` Andy Whitcroft
  2007-06-06 11:52 ` [PATCH] cvsimport: add support for new style remote layout Jeffrey C. Ollie
  2 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2007-06-03 22:00 UTC (permalink / raw)
  To: Andy Whitcroft; +Cc: git

Andy Whitcroft <apw@shadowen.org> writes:

> 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.

Sounds good.  Docs?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] cvsimport: add support for new style remote layout
  2007-06-03 22:00 ` Junio C Hamano
@ 2007-06-04  8:58   ` Andy Whitcroft
  2007-06-04  9:01     ` [PATCH 1/2] cvsimport: update documentation to include separate remotes option Andy Whitcroft
  2007-06-04  9:01     ` [PATCH 2/2] cvsimport: add <remote>/HEAD reference in separate remotes more Andy Whitcroft
  0 siblings, 2 replies; 7+ messages in thread
From: Andy Whitcroft @ 2007-06-04  8:58 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano wrote:
> Andy Whitcroft <apw@shadowen.org> writes:
> 
>> 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.
> 
> Sounds good.  Docs?

Heh, yep if its something wanted then it needs docs.  Will drop a couple
of patches following this email.  The first is the documentation
updates.  The second adds a HEAD link matching git-clone behaviour, and
handily calling cvs HEAD remotes/<remote>/HEAD which seems appropriate.

-apw

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] cvsimport: update documentation to include separate remotes option
  2007-06-04  8:58   ` Andy Whitcroft
@ 2007-06-04  9:01     ` Andy Whitcroft
  2007-06-04  9:01     ` [PATCH 2/2] cvsimport: add <remote>/HEAD reference in separate remotes more Andy Whitcroft
  1 sibling, 0 replies; 7+ messages in thread
From: Andy Whitcroft @ 2007-06-04  9:01 UTC (permalink / raw)
  To: git


Document the cvsimport -r <remote> option which switches cvsimport
to using a separate remote for tracking branches.

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
diff --git a/Documentation/git-cvsimport.txt b/Documentation/git-cvsimport.txt
index e0be856..4e5f1c6 100644
--- a/Documentation/git-cvsimport.txt
+++ b/Documentation/git-cvsimport.txt
@@ -13,7 +13,7 @@ SYNOPSIS
 	      [-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]
 	      [-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
 	      [-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]
-	      [<CVS_module>]
+	      [-r <remote>] [<CVS_module>]
 
 
 DESCRIPTION
@@ -25,10 +25,12 @@ Splitting the CVS log into patch sets is done by 'cvsps'.
 At least version 2.1 is required.
 
 You should *never* do any work of your own on the branches that are
-created by git-cvsimport. The initial import will create and populate a
+created by git-cvsimport.  By default initial import will create and populate a
 "master" branch from the CVS repository's main branch which you're free
 to work with; after that, you need to 'git merge' incremental imports, or
-any CVS branches, yourself.
+any CVS branches, yourself.  It is advisable to specify a named remote via
+-r to separate and protect the incoming branches.
+
 
 OPTIONS
 -------
@@ -51,10 +53,19 @@ OPTIONS
         The git repository to import to.  If the directory doesn't
         exist, it will be created.  Default is the current directory.
 
+-r <remote>::
+	The git remote to import this CVS repository into.
+	Moves all CVS branches into remotes/<remote>/<branch>
+	akin to the git-clone --use-separate-remote option.
+
 -o <branch-for-HEAD>::
-	The 'HEAD' branch from CVS is imported to the 'origin' branch within
-	the git repository, as 'HEAD' already has a special meaning for git.
-	Use this option if you want to import into a different branch.
+	When no remote is specified (via -r) the 'HEAD' branch
+	from CVS is imported to the 'origin' branch within the git
+	repository, as 'HEAD' already has a special meaning for git.
+	When a remote is specified the 'HEAD' branch is named
+	remotes/<remote>/master mirroring git-clone behaviour.
+	Use this option if you want to import into a different
+	branch.
 +
 Use '-o master' for continuing an import that was initially done by
 the old cvs2git tool.
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index f16ac3d..7837c7b 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -40,7 +40,7 @@ Usage: ${\basename $0}     # fetch/update GIT from CVS
        [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
        [-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
        [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
-       [CVS_module]
+       [-r remote] [CVS_module]
 END
 	exit(1);
 }

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] cvsimport: add <remote>/HEAD reference in separate remotes more
  2007-06-04  8:58   ` Andy Whitcroft
  2007-06-04  9:01     ` [PATCH 1/2] cvsimport: update documentation to include separate remotes option Andy Whitcroft
@ 2007-06-04  9:01     ` Andy Whitcroft
  1 sibling, 0 replies; 7+ messages in thread
From: Andy Whitcroft @ 2007-06-04  9:01 UTC (permalink / raw)
  To: git


When in separate remote mode (via -r <remote>) we can now use
the name HEAD for the CVS HEAD.  In keeping with git-clone
remotes/<remote>/HEAD is creates as a symbolic ref to the user
specified name for the HEAD which defaults to master.

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 7837c7b..598b9c8 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -1026,6 +1026,8 @@ if ($orig_branch) {
 	print "DONE; creating $orig_branch branch\n" if $opt_v;
 	system("git-update-ref", "refs/heads/master", "$remote/$opt_o")
 		unless -f "$git_dir/refs/heads/master";
+	system("git-symbolic-ref", "$remote/HEAD", "$remote/$opt_o")
+		if ($opt_r && $opt_o ne 'HEAD');
 	system('git-update-ref', 'HEAD', "$orig_branch");
 	unless ($opt_i) {
 		system('git checkout');

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] cvsimport: add support for new style remote layout
  2007-05-30  0:56 [PATCH] cvsimport: add support for new style remote layout Andy Whitcroft
  2007-05-30 13:24 ` James Bowes
  2007-06-03 22:00 ` Junio C Hamano
@ 2007-06-06 11:52 ` Jeffrey C. Ollie
  2 siblings, 0 replies; 7+ messages in thread
From: Jeffrey C. Ollie @ 2007-06-06 11:52 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 875 bytes --]

On Wed, 2007-05-30 at 01:56 +0100, Andy Whitcroft wrote:
> 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.

I've run over 5GB of cvs imports through git-cvsimport with this patch
and it's worked very well for me...

Jeff


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-06-06 11:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-30  0:56 [PATCH] cvsimport: add support for new style remote layout Andy Whitcroft
2007-05-30 13:24 ` James Bowes
2007-06-03 22:00 ` Junio C Hamano
2007-06-04  8:58   ` Andy Whitcroft
2007-06-04  9:01     ` [PATCH 1/2] cvsimport: update documentation to include separate remotes option Andy Whitcroft
2007-06-04  9:01     ` [PATCH 2/2] cvsimport: add <remote>/HEAD reference in separate remotes more Andy Whitcroft
2007-06-06 11:52 ` [PATCH] cvsimport: add support for new style remote layout Jeffrey C. Ollie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).