@matheusbsbs / matheus-bagliano / commits / 9da0dabcd9
Fork 0

cvsimport: use rev-parse to support packed refs

Previously, if refs were packed, git-cvsimport would assume that particular refs did not exist. This could lead to, for example, overwriting previous 'origin' commits that were packed. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Nov 28, 2007 at 13:56 UTC 9da0dabcd9ff71083b6bbc9878c22b12002400dd
2 files changed +12 -15
git-cvsimport.perl
+10 -15
@@ -526,18 +526,12 @@ sub is_sha1 {
526 return $s =~ /^[a-f0-9]{40}$/;
527 }
528
529 -sub get_headref ($$) {
530 - my $name = shift;
531 - my $git_dir = shift;
532 -
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): $!";
537 - return $r;
538 - }
539 - die "unable to open $f: $!" unless $! == POSIX::ENOENT;
540 - return undef;
529 +sub get_headref ($) {
530 + my $name = shift;
531 + my $r = `git rev-parse --verify '$name' 2>/dev/null`;
532 + return undef unless $? == 0;
533 + chomp $r;
534 + return $r;
535 }
536
537 -d $git_tree
@@ -697,7 +691,8 @@ my (@old,@new,@skipped,%ignorebranch);
691 $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
692
693 sub commit {
700 - if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) {
694 + if ($branch eq $opt_o && !$index{branch} &&
695 + !get_headref("$remote/$branch")) {
696 # looks like an initial commit
697 # use the index primed by git-init
698 $ENV{GIT_INDEX_FILE} = "$git_dir/index";
@@ -721,7 +716,7 @@ sub commit {
716 update_index(@old, @new);
717 @old = @new = ();
718 my $tree = write_tree();
724 - my $parent = get_headref($last_branch, $git_dir);
719 + my $parent = get_headref("$remote/$last_branch");
720 print "Parent ID " . ($parent ? $parent : "(empty)") . "\n" if $opt_v;
721
722 my @commit_args;
@@ -732,7 +727,7 @@ sub commit {
727 foreach my $rx (@mergerx) {
728 next unless $logmsg =~ $rx && $1;
729 my $mparent = $1 eq 'HEAD' ? $opt_o : $1;
735 - if (my $sha1 = get_headref($mparent, $git_dir)) {
730 + if (my $sha1 = get_headref("$remote/$mparent")) {
731 push @commit_args, '-p', $mparent;
732 print "Merge parent branch: $mparent\n" if $opt_v;
733 }
t/t9600-cvsimport.sh
+2
@@ -57,6 +57,8 @@ test_expect_success 'import a trivial module' '
57
58 '
59
60 +test_expect_success 'pack refs' 'cd module-git && git gc && cd ..'
61 +
62 test_expect_success 'update cvs module' '
63
64 cd module-cvs &&