X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-cvsimport.perl;h=69ccb88dde188a5a73eadf3bb8f778afce833b2f;hb=ee4fd1adfda5b6ebde93b289227986bf884babab;hp=3225a2a25dcaabbae64754e99a550f5b210f3765;hpb=75d8ff138dd640a117c6aaa625d0f6b835adbd3a;p=git.git diff --git a/git-cvsimport.perl b/git-cvsimport.perl index 3225a2a25..69ccb88dd 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(;$) { @@ -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); } @@ -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 = )) { 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,40 +770,17 @@ 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) { - my ($in, $out) = ('',''); my ($xtag) = $tag; $xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY ** $xtag =~ tr/_/\./ if ( $opt_u ); $xtag =~ s/[\/]/$opt_s/g; - my $pid = open2($in, $out, 'git-mktag'); - print $out "object $cid\n". - "type commit\n". - "tag $xtag\n". - "tagger $author_name <$author_email>\n" - or die "Cannot create tag object $xtag: $!\n"; - close($out) - or die "Cannot create tag object $xtag: $!\n"; - - my $tagobj = <$in>; - chomp $tagobj; - - if ( !close($in) or waitpid($pid, 0) != $pid or - $? != 0 or $tagobj !~ /^[0123456789abcdef]{40}$/ ) { - die "Cannot create tag object $xtag: $!\n"; - } - - - open(C,">$git_dir/refs/tags/$xtag") + system('git-tag', $xtag, $cid) == 0 or die "Cannot create tag $xtag: $!\n"; - print C "$tagobj\n" - or die "Cannot write tag $xtag: $!\n"; - close(C) - or die "Cannot write tag $xtag: $!\n"; print "Created tag '$xtag' on '$branch'\n" if $opt_v; } @@ -883,12 +868,12 @@ while () { 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 +881,7 @@ while () { } chomp(my $id = ); 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,14 +995,16 @@ 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-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');