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

Re: [PATCH] gitweb: Do not parse refs by hand, use git-peek-remote instead

From
Junio C Hamano <junkio@cox.net>
Date
Sep 14, 2006, 23:09 UTC
Message-ID
<7v8xkm2gfs.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<200609142327.23059.jnareb@gmail.com>
Jakub Narebski <jnareb@gmail.com> writes:
> Remove git_get_hash_by_ref while at it, as git_get_refs_list was the
> only place it was used.
That's a very good news.
Show 11 quoted lines
> +	open my $fd, "-|", $GIT, "peek-remote", "$projectroot/$project/"
> +		or return;
> +	while (my $line = <$fd>) {
> +		chomp $line;
> +		if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?([^\^]+)$/) {
> +			push @refs, { hash => $1, name => $2 };
> +		} elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?.*\^\{\}$/) {
> +			# assume that "peeled" ref is always after ref,
> +			# and that you "peel" (deref) tags only
> +			$refs[$#refs]->{'type'} = "tag";
> 		}

The assumption is good; we never show a ref^{} before showing ref itself. But you probably would want to safeguard yourself from future changes by not depending on "immediately after". At least you can check $refs[-1]{'name'} is the same as the unpeeled ref you are looking at, like this:

	if ($line =~ m/^([0-9a-fA-F]{40})\t$ref_dir\/?([^\^]+)$/) {
		push @refs, { hash => $1, name => $2 };
	} elsif ($line =~ m/^[0-9a-fA-F]{40}\t$ref_dir\/?(.*)\^\{\}$/ &&
                 $1 eq $refs[-1]{'name'}) {
		# most likely a tag is followed by its peeled
		# one, and when that happens we know the
		# previous one was of type 'tag'.
		$refs[$#refs]->{'type'} = "tag";
	} ...
Show 5 quoted lines
> +	foreach my $ref (@refs) {
> +		my $ref_file = $ref->{'name'};
> +		my $ref_id   = $ref->{'hash'};
> -		my $type = git_get_type($ref_id) || next;
> +		my $type = $ref->{'type'} || git_get_type($ref_id) || next;

And this is a good incremental change to reduce number of external calls.

Previous: Jakub NarebskiNext: Jakub Narebski
Message 2 of 9 in “gitweb: Do not parse refs by hand, use git-peek-remote instead”
  1. gitweb: Do not parse refs by hand, use git-peek-remote insteadJakub Narebski, Sep 14, 2006
  2. Junio C HamanoSep 14, 2006
  3. gitweb: Do not parse refs by hand, use git-peek-remote insteadJakub Narebski, Sep 15, 2006
  4. Junio C HamanoSep 15, 2006
  5. Jakub NarebskiSep 15, 2006
  6. Junio C HamanoSep 15, 2006
  7. Jakub NarebskiSep 15, 2006
  8. Junio C HamanoSep 15, 2006
  9. Jakub NarebskiSep 15, 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.