gitweb: Ref refactoring - use git_get_referencing for marking tagged/head commits
Use git_get_referencing to get HTML code for markers showing which refs (tags and heads) point to current commit. It would be much easier to change format of markers in one or two places than thorough the gitweb.cgi file. Added comment about read_info_ref subroutine: for $type == "" (empty argument) it saves only last path part of ref name e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'. Some reordering. Added $ref in one place. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jakub Narebski committed
Jul 31, 2006 at 02:21 UTC
594e212bc849039a204deef1d16c2eddcc451532
1 file changed
+22
-31
gitweb/gitweb.cgi
+22
-31
@@ -1024,6 +1024,8 @@ sub read_info_ref {
1024
open my $fd, "$projectroot/$project/info/refs" or return;
1025
while (my $line = <$fd>) {
1026
chomp $line;
1027
+ # attention: for $type == "" it saves only last path part of ref name
1028
+ # e.g. from 'refs/heads/jn/gitweb' it would leave only 'gitweb'
1029
if ($line =~ m/^([0-9a-fA-F]{40})\t.*$type\/([^\^]+)/) {
1030
if (defined $refs{$1}) {
1031
$refs{$1} .= " / $2";
@@ -1036,6 +1038,16 @@ sub read_info_ref {
1038
return \%refs;
1039
}
1040
1041
+sub git_get_referencing {
1042
+ my ($refs, $id) = @_;
1043
+
1044
+ if (defined $refs->{$id}) {
1045
+ return ' <span class="tag">' . esc_html($refs->{$id}) . '</span>';
1046
+ } else {
1047
+ return "";
1048
+ }
1049
+}
1050
+
1051
sub git_read_refs {
1052
my $ref_dir = shift;
1053
my @reflist;
@@ -1151,10 +1163,7 @@ sub git_summary {
1163
}
1164
$alternate ^= 1;
1165
if ($i-- > 0) {
1154
- my $ref = "";
1155
- if (defined $refs->{$commit}) {
1156
- $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1157
- }
1166
+ my $ref = git_get_referencing($refs, $commit);
1167
print "<td><i>$co{'age_string'}</i></td>\n" .
1168
"<td><i>" . esc_html(chop_str($co{'author_name'}, 10)) . "</i></td>\n" .
1169
"<td>";
@@ -1728,10 +1737,7 @@ sub git_tree {
1737
$/ = "\n";
1738
1739
my $refs = read_info_ref();
1731
- my $ref = "";
1732
- if (defined $refs->{$hash_base}) {
1733
- $ref = " <span class=\"tag\">" . esc_html($refs->{$hash_base}) . "</span>";
1734
- }
1740
+ my $ref = git_get_referencing($refs, $hash_base);
1741
git_header_html();
1742
my $base_key = "";
1743
my $base = "";
@@ -1912,10 +1918,7 @@ sub git_log {
1918
}
1919
for (my $i = ($page * 100); $i <= $#revlist; $i++) {
1920
my $commit = $revlist[$i];
1915
- my $ref = "";
1916
- if (defined $refs->{$commit}) {
1917
- $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
1918
- }
1921
+ my $ref = git_get_referencing($refs, $commit);
1922
my %co = git_read_commit($commit);
1923
next if !%co;
1924
my %ad = date_str($co{'author_epoch'});
@@ -1979,16 +1982,13 @@ sub git_commit {
1982
$expires = "+1d";
1983
}
1984
my $refs = read_info_ref();
1982
- my $ref = "";
1983
- if (defined $refs->{$co{'id'}}) {
1984
- $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
1985
- }
1986
- git_header_html(undef, $expires);
1985
+ my $ref = git_get_referencing($refs, $co{'id'});
1986
my $formats_nav = '';
1987
if (defined $file_name && defined $co{'parent'}) {
1988
my $parent = $co{'parent'};
1989
$formats_nav .= $cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=blame;hb=$parent;f=$file_name")}, "blame");
1990
}
1991
+ git_header_html(undef, $expires);
1992
git_page_nav('commit', defined $co{'parent'} ? '' : 'commitdiff',
1993
$hash, $co{'tree'}, $hash,
1994
$formats_nav);
@@ -1996,7 +1996,7 @@ sub git_commit {
1996
if (defined $co{'parent'}) {
1997
git_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash);
1998
} else {
1999
- git_header_div('tree', esc_html($co{'title'}), $co{'tree'}, $hash);
1999
+ git_header_div('tree', esc_html($co{'title'}) . $ref, $co{'tree'}, $hash);
2000
}
2001
print "<div class=\"title_text\">\n" .
2002
"<table cellspacing=\"0\">\n";
@@ -2206,13 +2206,10 @@ sub git_commitdiff {
2206
$expires = "+1d";
2207
}
2208
my $refs = read_info_ref();
2209
- my $ref = "";
2210
- if (defined $refs->{$co{'id'}}) {
2211
- $ref = " <span class=\"tag\">" . esc_html($refs->{$co{'id'}}) . "</span>";
2212
- }
2213
- git_header_html(undef, $expires);
2209
+ my $ref = git_get_referencing($refs, $co{'id'});
2210
my $formats_nav =
2211
$cgi->a({-href => "$my_uri?" . esc_param("p=$project;a=commitdiff_plain;h=$hash;hp=$hash_parent")}, "plain");
2212
+ git_header_html(undef, $expires);
2213
git_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav);
2214
git_header_div('commit', esc_html($co{'title'}) . $ref, $hash);
2215
print "<div class=\"page_body\">\n";
@@ -2364,10 +2361,7 @@ sub git_history {
2361
if (!%co) {
2362
next;
2363
}
2367
- my $ref = "";
2368
- if (defined $refs->{$commit}) {
2369
- $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2370
- }
2364
+ my $ref = git_get_referencing($refs, $commit);
2365
if ($alternate) {
2366
print "<tr class=\"dark\">\n";
2367
} else {
@@ -2559,10 +2553,7 @@ sub git_shortlog {
2553
my $alternate = 0;
2554
for (my $i = ($page * 100); $i <= $#revlist; $i++) {
2555
my $commit = $revlist[$i];
2562
- my $ref = "";
2563
- if (defined $refs->{$commit}) {
2564
- $ref = " <span class=\"tag\">" . esc_html($refs->{$commit}) . "</span>";
2565
- }
2556
+ my $ref = git_get_referencing($refs, $commit);
2557
my %co = git_read_commit($commit);
2558
my %ad = date_str($co{'author_epoch'});
2559
if ($alternate) {