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

[PATCH 3/3] cvsimport: miscellaneous packed-ref fixes

From
Jeff King <peff@peff.net>
Date
Nov 28, 2007, 18:56 UTC
Message-ID
<20071128185628.GC11320@coredump.intra.peff.net>
In-Reply-To
<20071128185504.GA11236@coredump.intra.peff.net>

These were found with a grep for '$git_dir'; they all replace a direct access of "$git_dir/refs/..." with a call to git-show-ref or git-update-ref.

Signed-off-by: Jeff King <peff@peff.net>
---
 git-cvsimport.perl |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index b852f2f..1b5f187 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -864,29 +864,27 @@ while (<CVS>) {
 				print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
 				$ancestor = $opt_o;
 			}
-			if (-f "$git_dir/$remote/$branch") {
+			if (defined get_headref("$remote/$branch")) {
 				print STDERR "Branch $branch already exists!\n";
 				$state=11;
 				next;
 			}
-			unless (open(H,"$git_dir/$remote/$ancestor")) {
+			my $id = get_headref("$remote/$ancestor");
+			if (!$id) {
 				print STDERR "Branch $ancestor does not exist!\n";
 				$ignorebranch{$branch} = 1;
 				$state=11;
 				next;
 			}
-			chomp(my $id = <H>);
-			close(H);
-			unless (open(H,"> $git_dir/$remote/$branch")) {
-				print STDERR "Could not create branch $branch: $!\n";
+
+			system(qw(git update-ref -m cvsimport),
+				"$remote/$branch", $id);
+			if($? != 0) {
+				print STDERR "Could not create branch $branch\n";
 				$ignorebranch{$branch} = 1;
 				$state=11;
 				next;
 			}
-			print H "$id\n"
-				or die "Could not write branch $branch: $!";
-			close(H)
-				or die "Could not write branch $branch: $!";
 		}
 		$last_branch = $branch if $branch ne $last_branch;
 		$state = 9;
@@ -998,7 +996,7 @@ if ($orig_branch) {
 	$orig_branch = "master";
 	print "DONE; creating $orig_branch branch\n" if $opt_v;
 	system("git-update-ref", "refs/heads/master", "$remote/$opt_o")
-		unless -f "$git_dir/refs/heads/master";
+		defined get_headref('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");
-- 
1.5.3.6.2039.g0495
Previous: Jeff KingNext: Junio C Hamano
Message 13 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.