git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/3] cvsimport: use show-ref to support packed refs

From
Jeff King <peff@peff.net>
Date
Nov 28, 2007, 19:44 UTC
Message-ID
<20071128194423.GB11396@coredump.intra.peff.net>
In-Reply-To
<Pine.LNX.4.64.0711281916140.27959@racer.site>
On Wed, Nov 28, 2007 at 07:16:36PM +0000, Johannes Schindelin wrote:
Show 21 quoted lines
> > -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;
> >  }
> 
> Where has $remote gone?

Gah, thank you. Obviously I deleted it without looking when I removed the now-unnecessary $git_dir. However, let me put a curse on whoever is responsible for randomly using "$remote" as a global in this function, when all of the other parameters (including the obvious-candidate-for-a-global $git_dir) are passed in.

Since get_headref is useful in contexts where "$remote" is not always prepended (see patch 3/3), I think the best solution is:

diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 1b5f187..bbf9799 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -692,7 +692,8 @@ my (@old,@new,@skipped,%ignorebranch);
 $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
 
 sub commit {
-	if ($branch eq $opt_o && !$index{branch} && !get_headref($branch)) {
+	if ($branch eq $opt_o && !$index{branch} &&
+		!get_headref("$remote/$branch")) {
 	    # looks like an initial commit
 	    # use the index primed by git-init
 	    $ENV{GIT_INDEX_FILE} = "$git_dir/index";
@@ -716,7 +717,7 @@ sub commit {
 	update_index(@old, @new);
 	@old = @new = ();
 	my $tree = write_tree();
-	my $parent = get_headref($last_branch);
+	my $parent = get_headref("$remote/$last_branch");
 	print "Parent ID " . ($parent ? $parent : "(empty)") . "\n" if $opt_v;
 
 	my @commit_args;
@@ -727,7 +728,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)) {
+		if (my $sha1 = get_headref("$remote/$mparent")) {
 			push @commit_args, '-p', $mparent;
 			print "Merge parent branch: $mparent\n" if $opt_v;
 		}
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 8 of 16 in “Re: git-cvsimport bug”
  1. Jeff KingNov 28, 2007
  2. 1/3 Add basic cvsimport testsJeff King, Nov 28, 2007
  3. Junio C HamanoNov 28, 2007
  4. David KastrupNov 28, 2007
  5. Andreas EricssonNov 29, 2007
  6. 2/3 cvsimport: use show-ref to support packed refsJeff King, Nov 28, 2007
  7. Johannes SchindelinNov 28, 2007
  8. Jeff KingNov 28, 2007
  9. Johannes SchindelinNov 28, 2007
  10. Junio C HamanoNov 28, 2007
  11. Jeff KingNov 28, 2007
  12. Jeff KingNov 28, 2007
  13. 3/3 cvsimport: miscellaneous packed-ref fixesJeff King, Nov 28, 2007
  14. Junio C HamanoNov 29, 2007
  15. Jeff KingNov 29, 2007
  16. Emanuele GiaquintaNov 30, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.