Skip to content

Commit cf5c725

Browse files
avargitster
authored andcommitted
gitweb: link to "git describe"'d commits in log messages
Change the log formatting function to know about "git describe" output such as "v2.8.0-4-g867ad08", in addition to just plain "867ad08". There are still many valid refnames that we don't link to e.g. v2.10.0-rc1~2^2~1 is also a valid way to refer to v2.8.0-4-g867ad08, but I'm not supporting that with this commit, similarly it's trivially possible to create some refnames like "æ/var-gf6727b0" or which won't be picked up by this regex. There's surely room for improvement here, but I just wanted to address the very common case of sticking "git describe" output into commit messages without trying to link to all possible refnames, that's going to be a rather futile exercise given that this is free text, and it would be prohibitively expensive to look up whether the references in question exist in our repository. There was on-list discussion about how we could do better than this patch. Junio suggested to update parse_commits() to call a new "gitweb--helper" command which would pass each of the revision candidates through "rev-parse --verify --quiet". That would cut down on our false positives (e.g. we'll link to "deadbeef"), and also allow us to be more aggressive in selecting candidate revisions. That may be too expensive to work in practice, or it may not. Investigating that would be a good follow-up to this patch. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Jakub Narębski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8059966 commit cf5c725

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

gitweb/gitweb.perl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,10 +2036,24 @@ sub format_log_line_html {
20362036
my $line = shift;
20372037

20382038
$line = esc_html($line, -nbsp=>1);
2039-
$line =~ s{\b([0-9a-fA-F]{7,40})\b}{
2039+
$line =~ s{
2040+
\b
2041+
(
2042+
# The output of "git describe", e.g. v2.10.0-297-gf6727b0
2043+
# or hadoop-20160921-113441-20-g094fb7d
2044+
(?<!-) # see strbuf_check_tag_ref(). Tags can't start with -
2045+
[A-Za-z0-9.-]+
2046+
(?!\.) # refs can't end with ".", see check_refname_format()
2047+
-g[0-9a-fA-F]{7,40}
2048+
|
2049+
# Just a normal looking Git SHA1
2050+
[0-9a-fA-F]{7,40}
2051+
)
2052+
\b
2053+
}{
20402054
$cgi->a({-href => href(action=>"object", hash=>$1),
20412055
-class => "text"}, $1);
2042-
}eg;
2056+
}egx;
20432057

20442058
return $line;
20452059
}

0 commit comments

Comments
 (0)