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

[PATCH v2] gitweb: use Git.pm, and use its parse_rev method for git_get_head_hash

From
LWLea Wiemann <lewiemann@gmail.com>
Date
May 31, 2008, 14:19 UTC
Message-ID
<1212243564-30109-1-git-send-email-LeWiemann@gmail.com>
In-Reply-To
<20080531130450.GI18781@machine.or.cz>

This simplifies git_get_head_hash a lot; the method might eventually even go away.

I haven't checked whether this causes an IO performance regression by instantiating a new Git repository instance, but in the end Git->repository will be as fast as possible and do no eager disk accesses. No benchmarking yet at this stage.

Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---

Per your request without the cleanup. I won't submit the cleanup patch separately, but I assume it will get cleaned up eventually when someone touches that function.

 gitweb/gitweb.perl |   20 ++++++--------------
 1 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 57a1905..0ed3d6e 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -16,6 +16,7 @@ use Encode;
 use Fcntl ':mode';
 use File::Find qw();
 use File::Basename qw(basename);
+use Git;
 binmode STDOUT, ':utf8';
 
 BEGIN {
@@ -1508,20 +1509,11 @@ sub git_cmd_str {
 # get HEAD ref of given project as hash
 sub git_get_head_hash {
 	my $project = shift;
-	my $o_git_dir = $git_dir;
-	my $retval = undef;
-	$git_dir = "$projectroot/$project";
-	if (open my $fd, "-|", git_cmd(), "rev-parse", "--verify", "HEAD") {
-		my $head = <$fd>;
-		close $fd;
-		if (defined $head && $head =~ /^([0-9a-fA-F]{40})$/) {
-			$retval = $1;
-		}
-	}
-	if (defined $o_git_dir) {
-		$git_dir = $o_git_dir;
-	}
-	return $retval;
+	my $directory = "$projectroot/$project";
+	# Legacy side effect on $git_dir.  This will eventually go
+	# away as the global $git_dir is eliminated.
+	$git_dir = $directory if (!defined $git_dir);
+	Git->repository(Directory => $directory)->parse_rev("HEAD");
 }
 
 # get type of given object
-- 
1.5.5.GIT
Previous: Petr BaudisNext: Lea Wiemann
Message 11 of 23 in “gitweb: use Git.pm, and use its parse_rev method for git_get_head_hash”
  1. gitweb: use Git.pm, and use its parse_rev method for git_get_head_hashLea Wiemann, May 30, 2008
  2. Lea WiemannMay 30, 2008
  3. Jakub NarebskiMay 31, 2008
  4. Lea WiemannMay 31, 2008
  5. Jakub NarebskiJun 1, 2008
  6. Junio C HamanoJun 2, 2008
  7. Petr BaudisJun 2, 2008
  8. Jakub NarebskiJun 2, 2008
  9. Lea WiemannJun 2, 2008
  10. Petr BaudisMay 31, 2008
  11. gitweb: use Git.pm, and use its parse_rev method for git_get_head_hashLea Wiemann, May 31, 2008
  12. Lea WiemannMay 31, 2008
  13. Junio C HamanoJun 1, 2008
  14. Lea WiemannJun 1, 2008
  15. Junio C HamanoJun 1, 2008
  16. test-lib.sh: set PERL5LIB instead of GITPERLLIBLea Wiemann, Jun 1, 2008
  17. Junio C HamanoJun 2, 2008
  18. Lea WiemannJun 2, 2008
  19. test-lib.sh: set PERL5LIB instead of GITPERLLIBLea Wiemann, Jun 2, 2008
  20. Junio C HamanoJun 2, 2008
  21. Lea WiemannJun 2, 2008
  22. Lea WiemannJun 3, 2008
  23. Lea WiemannJun 1, 2008

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.