1

I'm looking to add the name of the person who made the last commit to each project on the GitWeb project list, so instead of

14 min ago

it says something like

14 min ago (Someone's Name)

I've had a look through gitweb.cgi and found the point where the string is written (line 5488 in mine), but I don't really know how to proceed.

Has anyone already done this? Or can anyone offer a quick solution?

Chris
  • 981
  • 1
  • 11
  • 21
  • You know, it could be line 8854 as well; still gives nothing to solve the problem. Why don't you write this line (or this block) here instead? ) – raina77ow Jul 09 '12 at 11:19
  • 2
    Agree with @raina77ow. Once you've found some sort of version, (there's a `our $version =""` line in the code) it's easier to help. I've found a version `1.7.0.2` with a quick google and came up with the `sub git_get_last_activity` which is in line 2542. That gets the age and can be modified to also get the name. See the `git for-each-ref` manpage. I cannot test this, though, so I cannot propose a proper answer. – simbabque Jul 09 '12 at 11:25
  • The version we're using is `1.7.10.msysgit.1`. I've found `git_get_last_activity` in there, so I'll see what I can do with that. Thanks. – Chris Jul 09 '12 at 11:32

1 Answers1

2

Thanks to simbabque for pointing me to git_get_last_activity. My solution (possibly sub-optimal, let me know if it is):

Change git_get_last_activity to

sub git_get_last_activity {
my ($path) = @_;
my $fd;

$git_dir = "$projectroot/$path";
open($fd, "-|", git_cmd(), 'for-each-ref',
     '--format=%(committer)',
     '--sort=-committerdate',
     '--count=1',
     'refs/heads') or return;
my $most_recent = <$fd>;
close $fd or return;
if (defined $most_recent &&
    $most_recent =~ / (\d+) [-+][01]\d\d\d$/) {
  my $bracket_position = rindex($most_recent, "<");
  my $committer_name = substr($most_recent, 0, $bracket_position - 1);
    my $timestamp = $1;
    my $age = time - $timestamp;
    return ($age, age_string($age), $committer_name);
}
return (undef, undef, undef);
}

Then search for where that is called later (should only be once) and change

($pr->{'age'}, $pr->{'age_string'}) = @activity;

to be

($pr->{'age'}, $pr->{'age_string'}, $pr->{'committer'}) = @activity;

Then go to git_project_list_rows and change

(defined $pr->{'age_string'} ? $pr->{'age_string'} : "No commits") . "</td>\n" .

to

(defined $pr->{'age_string'} ? $pr->{'age_string'} . ' (' . $pr->{'committer'} . ')' : "No commits") . "</td>\n" .
Chris
  • 981
  • 1
  • 11
  • 21