Skip to content

Commit 9bfe9f8

Browse files
committed
Merge branch 'aw/cvs'
* aw/cvs: cvsimport: add <remote>/HEAD reference in separate remotes more cvsimport: update documentation to include separate remotes option cvsimport: add support for new style remote layout
2 parents 0354539 + 06baffd commit 9bfe9f8

File tree

2 files changed

+42
-21
lines changed

2 files changed

+42
-21
lines changed

Documentation/git-cvsimport.txt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313
[-A <author-conv-file>] [-p <options-for-cvsps>] [-P <file>]
1414
[-C <git_repository>] [-z <fuzz>] [-i] [-k] [-u] [-s <subst>]
1515
[-a] [-m] [-M <regex>] [-S <regex>] [-L <commitlimit>]
16-
[<CVS_module>]
16+
[-r <remote>] [<CVS_module>]
1717

1818

1919
DESCRIPTION
@@ -25,10 +25,12 @@ Splitting the CVS log into patch sets is done by 'cvsps'.
2525
At least version 2.1 is required.
2626

2727
You should *never* do any work of your own on the branches that are
28-
created by git-cvsimport. The initial import will create and populate a
28+
created by git-cvsimport. By default initial import will create and populate a
2929
"master" branch from the CVS repository's main branch which you're free
3030
to work with; after that, you need to 'git merge' incremental imports, or
31-
any CVS branches, yourself.
31+
any CVS branches, yourself. It is advisable to specify a named remote via
32+
-r to separate and protect the incoming branches.
33+
3234

3335
OPTIONS
3436
-------
@@ -51,10 +53,19 @@ OPTIONS
5153
The git repository to import to. If the directory doesn't
5254
exist, it will be created. Default is the current directory.
5355

56+
-r <remote>::
57+
The git remote to import this CVS repository into.
58+
Moves all CVS branches into remotes/<remote>/<branch>
59+
akin to the git-clone --use-separate-remote option.
60+
5461
-o <branch-for-HEAD>::
55-
The 'HEAD' branch from CVS is imported to the 'origin' branch within
56-
the git repository, as 'HEAD' already has a special meaning for git.
57-
Use this option if you want to import into a different branch.
62+
When no remote is specified (via -r) the 'HEAD' branch
63+
from CVS is imported to the 'origin' branch within the git
64+
repository, as 'HEAD' already has a special meaning for git.
65+
When a remote is specified the 'HEAD' branch is named
66+
remotes/<remote>/master mirroring git-clone behaviour.
67+
Use this option if you want to import into a different
68+
branch.
5869
+
5970
Use '-o master' for continuing an import that was initially done by
6071
the old cvs2git tool.

git-cvsimport.perl

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
$SIG{'PIPE'}="IGNORE";
3030
$ENV{'TZ'}="UTC";
3131

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);
3333
my (%conv_author_name, %conv_author_email);
3434

3535
sub usage(;$) {
@@ -40,7 +40,7 @@ (;$)
4040
[-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file]
4141
[-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k]
4242
[-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit]
43-
[CVS_module]
43+
[-r remote] [CVS_module]
4444
END
4545
exit(1);
4646
}
@@ -114,7 +114,7 @@ sub read_repo_config {
114114
}
115115
}
116116

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:";
118118
read_repo_config($opts);
119119
getopts($opts) or usage();
120120
usage if $opt_h;
@@ -134,13 +134,21 @@ sub read_repo_config {
134134
} else {
135135
usage("CVSROOT needs to be set");
136136
}
137-
$opt_o ||= "origin";
138137
$opt_s ||= "-";
139138
$opt_a ||= 0;
140139

141140
my $git_tree = $opt_C;
142141
$git_tree ||= ".";
143142

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+
144152
my $cvs_tree;
145153
if ($#ARGV == 0) {
146154
$cvs_tree = $ARGV[0];
@@ -522,7 +530,7 @@ ($$)
522530
my $name = shift;
523531
my $git_dir = shift;
524532

525-
my $f = "$git_dir/refs/heads/$name";
533+
my $f = "$git_dir/$remote/$name";
526534
if (open(my $fh, $f)) {
527535
chomp(my $r = <$fh>);
528536
is_sha1($r) or die "Cannot get head id for $name ($r): $!";
@@ -573,12 +581,12 @@ ($$)
573581

574582
# Get the last import timestamps
575583
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
577585
die "Cannot run git-for-each-ref: $!\n";
578586
while (defined(my $entry = <H>)) {
579587
my ($ref, $author);
580588
eval($entry) || die "cannot eval refs list: $@";
581-
my ($head) = ($ref =~ m|^refs/heads/(.*)|);
589+
my ($head) = ($ref =~ m|^$remote/(.*)|);
582590
$author =~ /^.*\s(\d+)\s[-+]\d{4}$/;
583591
$branch_date{$head} = $1;
584592
}
@@ -701,9 +709,9 @@ sub commit {
701709
$index{$branch} = tmpnam();
702710
$ENV{GIT_INDEX_FILE} = $index{$branch};
703711
if ($ancestor) {
704-
system("git-read-tree", $ancestor);
712+
system("git-read-tree", "$remote/$ancestor");
705713
} else {
706-
system("git-read-tree", $branch);
714+
system("git-read-tree", "$remote/$branch");
707715
}
708716
die "read-tree failed: $?\n" if $?;
709717
}
@@ -762,7 +770,7 @@ sub commit {
762770
waitpid($pid,0);
763771
die "Error running git-commit-tree: $?\n" if $?;
764772

765-
system("git-update-ref refs/heads/$branch $cid") == 0
773+
system("git-update-ref $remote/$branch $cid") == 0
766774
or die "Cannot write branch $branch for update: $!\n";
767775

768776
if ($tag) {
@@ -861,20 +869,20 @@ sub commit {
861869
print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
862870
$ancestor = $opt_o;
863871
}
864-
if (-f "$git_dir/refs/heads/$branch") {
872+
if (-f "$git_dir/$remote/$branch") {
865873
print STDERR "Branch $branch already exists!\n";
866874
$state=11;
867875
next;
868876
}
869-
unless (open(H,"$git_dir/refs/heads/$ancestor")) {
877+
unless (open(H,"$git_dir/$remote/$ancestor")) {
870878
print STDERR "Branch $ancestor does not exist!\n";
871879
$ignorebranch{$branch} = 1;
872880
$state=11;
873881
next;
874882
}
875883
chomp(my $id = <H>);
876884
close(H);
877-
unless (open(H,"> $git_dir/refs/heads/$branch")) {
885+
unless (open(H,"> $git_dir/$remote/$branch")) {
878886
print STDERR "Could not create branch $branch: $!\n";
879887
$ignorebranch{$branch} = 1;
880888
$state=11;
@@ -988,14 +996,16 @@ sub commit {
988996
die "Fast-forward update failed: $?\n" if $?;
989997
}
990998
else {
991-
system(qw(git-merge cvsimport HEAD), "refs/heads/$opt_o");
999+
system(qw(git-merge cvsimport HEAD), "$remote/$opt_o");
9921000
die "Could not merge $opt_o into the current branch.\n" if $?;
9931001
}
9941002
} else {
9951003
$orig_branch = "master";
9961004
print "DONE; creating $orig_branch branch\n" if $opt_v;
997-
system("git-update-ref", "refs/heads/master", "refs/heads/$opt_o")
1005+
system("git-update-ref", "refs/heads/master", "$remote/$opt_o")
9981006
unless -f "$git_dir/refs/heads/master";
1007+
system("git-symbolic-ref", "$remote/HEAD", "$remote/$opt_o")
1008+
if ($opt_r && $opt_o ne 'HEAD');
9991009
system('git-update-ref', 'HEAD', "$orig_branch");
10001010
unless ($opt_i) {
10011011
system('git checkout');

0 commit comments

Comments
 (0)