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

[PATCH (take 3)] gitweb: Use git-show-ref instead of git-peek-remote

From
Jakub Narebski <jnareb@gmail.com>
Date
Nov 25, 2006, 10:32 UTC
Message-ID
<11644507284105-git-send-email-jnareb@gmail.com>
In-Reply-To
<7vhcwoa3mx.fsf@assigned-by-dhcp.cox.net>

Use "git show-ref --dereference" instead of "git peek-remote $projectroot/project" in git_get_references. git-show-ref is faster than git-peek-remote (40ms vs 56ms user+sys for git.git repository); even faster is reading info/refs file (if it exists), but the information in info/refs can be stale; that and the fact that info/refs is meant for dumb protocol transports, not for gitweb.

git-show-ref is available since v1.4.4; the output format is slightly different than git-peek-remote output format.

While at it make git_get_references return hash in list context, and reference to hash (as it used to do) in scalar and void contexts.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This is the final version.

Once again, I'm extremly sorry for the confusion with the previous version...

 gitweb/gitweb.perl |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index f06cd3e..1cded75 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1154,14 +1154,15 @@ sub git_get_last_activity {
 sub git_get_references {
 	my $type = shift || "";
 	my %refs;
-	# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c	refs/tags/v2.6.11
-	# c39ae07f393806ccf406ef966e9a15afc43cc36a	refs/tags/v2.6.11^{}
-	open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
+	# 5dc01c595e6c6ec9ccda4f6f69c131c0dd945f8c refs/tags/v2.6.11
+	# c39ae07f393806ccf406ef966e9a15afc43cc36a refs/tags/v2.6.11^{}
+	open my $fd, "-|", git_cmd(), "show-ref", "--dereference",
+		($type ? ("--", "refs/$type") : ()) # use -- <pattern> if $type
 		or return;
 
 	while (my $line = <$fd>) {
 		chomp $line;
-		if ($line =~ m/^([0-9a-fA-F]{40})\trefs\/($type\/?[^\^]+)/) {
+		if ($line =~ m!^([0-9a-fA-F]{40})\srefs/($type/?[^^]+)!) {
 			if (defined $refs{$1}) {
 				push @{$refs{$1}}, $2;
 			} else {
@@ -1170,7 +1171,7 @@ sub git_get_references {
 		}
 	}
 	close $fd or return;
-	return \%refs;
+	return wantarray ? %refs : \%refs;
 }
 
 sub git_get_rev_name_tags {
-- 
1.4.4.1
Previous: Jakub NarebskiNext: Junio C Hamano
Message 6 of 8 in “gitweb: Use git-show-ref instead of git-peek-remote”
  1. gitweb: Use git-show-ref instead of git-peek-remoteJakub Narebski, Nov 24, 2006
  2. Junio C HamanoNov 24, 2006
  3. Jakub NarebskiNov 24, 2006
  4. gitweb: Use git-show-ref instead of git-peek-remoteJakub Narebski, Nov 25, 2006
  5. Jakub NarebskiNov 25, 2006
  6. gitweb: Use git-show-ref instead of git-peek-remoteJakub Narebski, Nov 25, 2006
  7. Junio C HamanoNov 25, 2006
  8. Jakub NarebskiNov 25, 2006

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.