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@xxxxxxxx> --- git-cvsimport.perl | 24 +++++++++--------------- t/t9600-cvsimport.sh | 2 ++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/git-cvsimport.perl b/git-cvsimport.perl index efa6a0c..b852f2f 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -527,18 +527,12 @@ sub is_sha1 { return $s =~ /^[a-f0-9]{40}$/; } -sub get_headref ($$) { - my $name = shift; - my $git_dir = shift; - - 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): $!"; - return $r; - } - die "unable to open $f: $!" unless $! == POSIX::ENOENT; - return undef; +sub get_headref ($) { + my $name = shift; + my $r = `git show-ref -s '$name'`; + return undef unless $? == 0; + chomp $r; + return $r; } -d $git_tree @@ -698,7 +692,7 @@ my (@old,@new,@skipped,%ignorebranch); $ignorebranch{'#CVSPS_NO_BRANCH'} = 1; sub commit { - if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) { + if ($branch eq $opt_o && !$index{branch} && !get_headref($branch)) { # looks like an initial commit # use the index primed by git-init $ENV{GIT_INDEX_FILE} = "$git_dir/index"; @@ -722,7 +716,7 @@ sub commit { update_index(@old, @new); @old = @new = (); my $tree = write_tree(); - my $parent = get_headref($last_branch, $git_dir); + my $parent = get_headref($last_branch); print "Parent ID " . ($parent ? $parent : "(empty)") . "\n" if $opt_v; my @commit_args; @@ -733,7 +727,7 @@ sub commit { foreach my $rx (@mergerx) { next unless $logmsg =~ $rx && $1; my $mparent = $1 eq 'HEAD' ? $opt_o : $1; - if (my $sha1 = get_headref($mparent, $git_dir)) { + if (my $sha1 = get_headref($mparent)) { push @commit_args, '-p', $mparent; print "Merge parent branch: $mparent\n" if $opt_v; } diff --git a/t/t9600-cvsimport.sh b/t/t9600-cvsimport.sh index 1ee06bb..3338d44 100755 --- a/t/t9600-cvsimport.sh +++ b/t/t9600-cvsimport.sh @@ -57,6 +57,8 @@ test_expect_success 'import a trivial module' ' ' +test_expect_success 'pack refs' 'cd module-git && git gc && cd ..' + test_expect_success 'update cvs module' ' cd module-cvs && -- 1.5.3.6.2039.g0495 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html