@matheusbsbs / matheus-bagliano / commits / 63e02a1be3
Fork 0

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>

Junio C Hamano committed Oct 15, 2006 at 03:29 UTC 63e02a1be308aa57f3cabd7e951a94ac3b7aeb51
1 file changed +24 -11
gitweb/gitweb.perl
+24 -11
@@ -1009,6 +1009,24 @@ sub parse_tag {
1009 return %tag
1010 }
1011
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 +
1030 sub parse_commit {
1031 my $commit_id = shift;
1032 my $commit_text = shift;
@@ -2258,16 +2276,11 @@ sub git_project_list {
2276 die_error(undef, "No projects found");
2277 }
2278 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) {
2281 next;
2282 }
2270 - $pr->{'commit'} = \%co;
2283 + ($pr->{'age'}, $pr->{'age_string'}) = @aa;
2284 if (!defined $pr->{'descr'}) {
2285 my $descr = git_get_project_description($pr->{'path'}) || "";
2286 $pr->{'descr'} = chop_str($descr, 25, 5);
@@ -2317,7 +2330,7 @@ sub git_project_list {
2330 "</th>\n";
2331 }
2332 if ($order eq "age") {
2320 - @projects = sort {$a->{'commit'}{'age'} <=> $b->{'commit'}{'age'}} @projects;
2333 + @projects = sort {$a->{'age'} <=> $b->{'age'}} @projects;
2334 print "<th>Last Change</th>\n";
2335 } else {
2336 print "<th>" .
@@ -2339,8 +2352,8 @@ sub git_project_list {
2352 -class => "list"}, esc_html($pr->{'path'})) . "</td>\n" .
2353 "<td>" . esc_html($pr->{'descr'}) . "</td>\n" .
2354 "<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" .
2357 "<td class=\"link\">" .
2358 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"summary")}, "summary") . " | " .
2359 $cgi->a({-href => href(project=>$pr->{'path'}, action=>"shortlog")}, "shortlog") . " | " .