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.