git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cvsimport move over to using git for each ref to read refs
@ 2006-09-20  8:52 Andy Whitcroft
  2006-09-20  9:23 ` Jakub Narebski
  0 siblings, 1 reply; 15+ messages in thread
From: Andy Whitcroft @ 2006-09-20  8:52 UTC (permalink / raw)
  To: git

cvsimport: move over to using git-for-each-ref to read refs

cvsimport opens all of the files in $GIT_DIR/refs/heads and reads
out the sha1's in order to work out what time the last commit on
that branch was made (in CVS) thus allowing incremental updates.
However, this takes no account of hierachical refs naming producing
the following error for each directory in $GIT_DIR/refs:

  Use of uninitialized value in chomp at /usr/bin/git-cvsimport line 503.
  Use of uninitialized value in concatenation (.) or string at
					/usr/bin/git-cvsimport line 505.
  usage: git-cat-file [-t|-s|-e|-p|<type>] <sha1>

Take advantage of the new packed refs work to use the new
for-each-ref iterator to get this information.  Use the format
specifier to ensure we are neutral to changes in default.

[Junio: although although for-each-ref offers a --perl quoting mode
this patch does not use it as it seems only to make parsing the
output harder in perl.  If there is a neat trick for handling this
'perl' form please educate me.  Here, rely on sha1's to contain
no spaces.]

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
---
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index e5a00a1..1a62afa 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -495,13 +495,14 @@ unless(-d $git_dir) {
 	$tip_at_start = `git-rev-parse --verify HEAD`;
 
 	# Get the last import timestamps
-	opendir(D,"$git_dir/refs/heads");
-	while(defined(my $head = readdir(D))) {
-		next if $head =~ /^\./;
-		open(F,"$git_dir/refs/heads/$head")
-			or die "Bad head branch: $head: $!\n";
-		chomp(my $ftag = <F>);
-		close(F);
+	open(H, "git-for-each-ref --format='%(objectname) %(refname)'|") or
+		die "Cannot run git-for-each-ref: $!\n";
+	while(defined(my $entry = <H>)) {
+		chomp($entry);
+		my ($ftag, $name) = split(' ', $entry, 2);
+		next if ($name !~ m@^refs/heads/(.*)$@);
+		my ($head) = ($1);
+
 		open(F,"git-cat-file commit $ftag |");
 		while(<F>) {
 			next unless /^author\s.*\s(\d+)\s[-+]\d{4}$/;
@@ -510,7 +511,7 @@ unless(-d $git_dir) {
 		}
 		close(F);
 	}
-	closedir(D);
+	close(H);
 }
 
 -d $git_dir

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2006-09-22  4:58 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-20  8:52 [PATCH] cvsimport move over to using git for each ref to read refs Andy Whitcroft
2006-09-20  9:23 ` Jakub Narebski
2006-09-20 10:26   ` Andy Whitcroft
2006-09-20 10:31     ` [PATCH 1/2] for each ref add a raw timestamp field type Andy Whitcroft
2006-09-20 10:31     ` [PATCH 2/2] cvsimport move over to using git for each ref to read refs V2 Andy Whitcroft
2006-09-20 11:00     ` [PATCH] cvsimport move over to using git for each ref to read refs Jakub Narebski
2006-09-20 15:53     ` Junio C Hamano
2006-09-20 16:12       ` Andy Whitcroft
2006-09-20 16:37         ` [PATCH] cvsimport move over to using git for each ref to read refs V3 Andy Whitcroft
2006-09-20 16:55           ` Junio C Hamano
2006-09-20 17:00             ` Andy Whitcroft
2006-09-20 17:17               ` Junio C Hamano
2006-09-20 16:45         ` [PATCH] cvsimport move over to using git for each ref to read refs Junio C Hamano
2006-09-21 12:06           ` Andy Whitcroft
2006-09-22  4:57             ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).