Skip to content

Commit 63e02a1

Browse files
author
Junio C Hamano
committed
gitweb: use for-each-ref to show the latest activity across branches
The project list page shows last change from the HEAD branch but often people would want to view activity on any branch. Unfortunately that is fairly expensive without the core-side support. for-each-ref was invented exactly for that. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent b2d3476 commit 63e02a1

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

gitweb/gitweb.perl

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,24 @@ sub parse_tag {
10091009
return %tag
10101010
}
10111011

1012+
sub git_get_last_activity {
1013+
my ($path) = @_;
1014+
my $fd;
1015+
1016+
$git_dir = "$projectroot/$path";
1017+
open($fd, "-|", git_cmd(), 'for-each-ref',
1018+
'--format=%(refname) %(committer)',
1019+
'--sort=-committerdate',
1020+
'refs/heads') or return;
1021+
my $most_recent = <$fd>;
1022+
close $fd or return;
1023+
if ($most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
1024+
my $timestamp = $1;
1025+
my $age = time - $timestamp;
1026+
return ($age, age_string($age));
1027+
}
1028+
}
1029+
10121030
sub parse_commit {
10131031
my $commit_id = shift;
10141032
my $commit_text = shift;
@@ -2258,16 +2276,11 @@ sub git_project_list {
22582276
die_error(undef, "No projects found");
22592277
}
22602278
foreach my $pr (@list) {
2261-
my $head = git_get_head_hash($pr->{'path'});
2262-
if (!defined $head) {
2263-
next;
2264-
}
2265-
$git_dir = "$projectroot/$pr->{'path'}";
2266-
my %co = parse_commit($head);
2267-
if (!%co) {
2279+
my (@aa) = git_get_last_activity($pr->{'path'});
2280+
unless (@aa) {
22682281
next;
22692282
}
2270-
$pr->{'commit'} = \%co;
2283+
($pr->{'age'}, $pr->{'age_string'}) = @aa;
22712284
if (!defined $pr->{'descr'}) {
22722285
my $descr = git_get_project_description($pr->{'path'}) || "";
22732286
$pr->{'descr'} = chop_str($descr, 25, 5);
@@ -2317,7 +2330,7 @@ sub git_project_list {
23172330
"</th>\n";
23182331
}
23192332
if ($order eq "age") {
2320-
@projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2333+
@projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
23212334
print "<th>Last Change</th>\n";
23222335
} else {
23232336
print "<th>" .
@@ -2339,8 +2352,8 @@ sub git_project_list {
23392352
-class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
23402353
"<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
23412354
"<td><i>" . chop_str($pr->{'owner'}, 15) . "</i></td>\n";
2342-
print "<td class=\"". age_class($pr->{'commit'}{'age'}) . "\">" .
2343-
$pr->{'commit'}{'age_string'} . "</td>\n" .
2355+
print "<td class=\"". age_class($pr->{'age'}) . "\">" .
2356+
$pr->{'age_string'} . "</td>\n" .
23442357
"<td class=\"link\">" .
23452358
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
23462359
$cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .

0 commit comments

Comments
 (0)