patches: update patches
[git-osx-installer.git] / patches / gitweb / q / gitweb-support-lastactivity-file.diff
blobb0f05e86818df2df7b2888fd59885924939e575b
1 Subject: [PATCH] gitweb: support lastactivity file
3 Provide a new gitweb configuration value for $lastactivity_file
4 which is the pathname relative to a $GIT_DIR for a file that if
5 it exists and is non-empty and contains a date in iso, iso-strict
6 or raw format will be read and used as the value returned by the
7 git_get_last_activity function.
9 This is most useful if a hooks/post-update script is present which
10 contains something like this:
12 git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
13 --count=1 refs/heads > info/lastactivity
15 And then the gitweb_config.perl configuration contains this:
17 our $lastactivity_file = "info/lastactivity";
19 Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
20 ---
21 Documentation/gitweb.conf.txt | 22 ++++++++++++++++++++++
22 gitweb/gitweb.perl | 43 ++++++++++++++++++++++++++++++++++++++++++-
23 2 files changed, 64 insertions(+), 1 deletion(-)
25 diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt
26 index fd3ca594..0784b7d2 100644
27 --- a/Documentation/gitweb.conf.txt
28 +++ b/Documentation/gitweb.conf.txt
29 @@ -530,6 +530,28 @@ $omit_age_column::
30 If true, omit the column with date of the most current commit on the
31 projects list page. It can save a bit of I/O and a fork per repository.
33 +$lastactivity_file::
34 + If this is set to a pathname (relative to `$GIT_DIR`) and the file
35 + exists and contains a date in either iso, iso-strict or raw format,
36 + it will be used to calculate the age which can save quite a bit of I/O
37 + and a fork per repository.
39 +This is most useful if a hooks/post-update script is present that contains
40 +these lines:
42 +----------------------------------------------------------------------------
43 + git for-each-ref --sort=-committerdate --format='%(committerdate:iso8601)' \
44 + --count=1 refs/heads > info/lastactivity
45 +----------------------------------------------------------------------------
47 +Then `$lastactivity_file` can be set to `"info/lastactivity"` and the age
48 +column can be used without incurring the I/O penalty.
50 +Note that if the `extra-branch-refs` feature is being used then the above
51 +script will need to be adjusted to take those additional refs into
52 +consideration otherwise they will not affect the value displayed in the age
53 +column when this feature is used.
55 $omit_owner::
56 If true prevents displaying information about repository owner.
58 diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
59 index 1ff6e9ac..73bdcee5 100755
60 --- a/gitweb/gitweb.perl
61 +++ b/gitweb/gitweb.perl
62 @@ -18,6 +18,7 @@ use Fcntl ':mode';
63 use File::Find qw();
64 use File::Basename qw(basename);
65 use Time::HiRes qw(gettimeofday tv_interval);
66 +use Time::Local;
67 binmode STDOUT, ':utf8';
69 if (!defined($CGI::VERSION) || $CGI::VERSION < 4.08) {
70 @@ -152,6 +153,10 @@ our $export_ok = "++GITWEB_EXPORT_OK++";
71 # don't generate age column on the projects list page
72 our $omit_age_column = 0;
74 +# use contents of this file (in iso, iso-strict or raw format) as
75 +# the last activity data if it exists and is a valid date
76 +our $lastactivity_file = undef;
78 # don't generate information about owners of repositories
79 our $omit_owner=0;
81 @@ -3292,11 +3297,47 @@ sub git_get_project_owner {
82 return $owner;
85 +sub parse_activity_date {
86 + my $dstr = shift;
88 + if ($dstr =~ /^\s*([-+]?\d+)(?:\s+([-+]\d{4}))?\s*$/) {
89 + # Unix timestamp
90 + return 0 + $1;
91 + }
92 + if ($dstr =~ /^\s*(\d{4})-(\d{2})-(\d{2})[Tt _](\d{1,2}):(\d{2}):(\d{2})(?:[ _]?([Zz]|(?:[-+]\d{1,2}:?\d{2})))?\s*$/) {
93 + my ($Y,$m,$d,$H,$M,$S,$z) = ($1,$2,$3,$4,$5,$6,$7||'');
94 + my $seconds = timegm(0+$S, 0+$M, 0+$H, 0+$d, $m-1, $Y-1900);
95 + defined($z) && $z ne '' or $z = 'Z';
96 + $z =~ s/://;
97 + substr($z,1,0) = '0' if length($z) == 4;
98 + my $off = 0;
99 + if (uc($z) ne 'Z') {
100 + $off = 60 * (60 * (0+substr($z,1,2)) + (0+substr($z,3,2)));
101 + $off = -$off if substr($z,0,1) eq '-';
103 + return $seconds - $off;
105 + return undef;
108 +# If $quick is true only look at $lastactivity_file
109 sub git_get_last_activity {
110 - my ($path) = @_;
111 + my ($path, $quick) = @_;
112 my $fd;
114 $git_dir = "$projectroot/$path";
115 + if ($lastactivity_file && open($fd, "<", "$git_dir/$lastactivity_file")) {
116 + my $activity = <$fd>;
117 + close $fd;
118 + return (undef, undef) unless defined $activity;
119 + chomp $activity;
120 + return (undef, undef) if $activity eq '';
121 + if (my $timestamp = parse_activity_date($activity)) {
122 + my $age = time - $timestamp;
123 + return ($age, age_string($age));
126 + return (undef, undef) if $quick;
127 open($fd, "-|", git_cmd(), 'for-each-ref',
128 '--format=%(committer)',
129 '--sort=-committerdate',