summaryrefslogtreecommitdiffabout
path: root/ui-repolist.c
authorLars Hjemli <hjemli@gmail.com>2007-05-22 21:25:25 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-05-22 21:25:25 (UTC)
commit57f6a8bf0de6c112cabc1d8e20ade2698bd886b7 (patch) (unidiff)
tree281f1b4c6716b7632efe46607fc951d888e2fb5f /ui-repolist.c
parent237ef7b06d461ddf27b21cd13bfcb50befa4a916 (diff)
downloadcgit-57f6a8bf0de6c112cabc1d8e20ade2698bd886b7.zip
cgit-57f6a8bf0de6c112cabc1d8e20ade2698bd886b7.tar.gz
cgit-57f6a8bf0de6c112cabc1d8e20ade2698bd886b7.tar.bz2
Show time since last change on index page
When creating the index page, an optional file can be scanned per repository to obtain a timestamp for last modification within the repo. If such a file cannot be found, st_mtime for repo.defbranch is used instead. This information is then printed in a new column, "Idle", using the new function cgit_print_age(). The new parameter "repo.agefile" can be used to specify (globally) a relative path to scan (default value is "info/web/last-modified"). The content of the "last-modified" file can be generated by the post-receive hook with a command like this: git-for-each-ref --format="%(committerdate)" --sort=-committerdate \ --count=1 > $GIT_DIR/info/web/last-modified Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'ui-repolist.c') (more/less context) (ignore whitespace changes)
-rw-r--r--ui-repolist.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/ui-repolist.c b/ui-repolist.c
index f5e087f..573c730 100644
--- a/ui-repolist.c
+++ b/ui-repolist.c
@@ -9,2 +9,37 @@
9#include "cgit.h" 9#include "cgit.h"
10#include <time.h>
11
12
13time_t read_agefile(char *path)
14{
15 FILE *f;
16 static char buf[64], buf2[64];
17 struct tm tm;
18
19 if (!(f = fopen(path, "r")))
20 return -1;
21 fgets(buf, sizeof(buf), f);
22 fclose(f);
23 if (parse_date(buf, buf2, sizeof(buf2)))
24 return strtoul(buf2, NULL, 10);
25 else
26 return 0;
27}
28
29static void print_modtime(struct repoinfo *repo)
30{
31 char *path;
32 struct stat s;
33
34 path = fmt("%s/%s", repo->path, cgit_agefile);
35 if (stat(path, &s) == 0) {
36 cgit_print_age(read_agefile(path), -1, NULL);
37 return;
38 }
39
40 path = fmt("%s/refs/heads/%s", repo->path, repo->defbranch);
41 if (stat(path, &s) != 0)
42 return;
43 cgit_print_age(s.st_mtime, -1, NULL);
44}
10 45
@@ -21,3 +56,3 @@ void cgit_print_repolist(struct cacheitem *item)
21 if (cgit_index_header) { 56 if (cgit_index_header) {
22 html("<tr class='nohover'><td colspan='4' class='include-block'>"); 57 html("<tr class='nohover'><td colspan='5' class='include-block'>");
23 html_include(cgit_index_header); 58 html_include(cgit_index_header);
@@ -29,2 +64,3 @@ void cgit_print_repolist(struct cacheitem *item)
29 "<th class='left'>Owner</th>" 64 "<th class='left'>Owner</th>"
65 "<th class='left'>Idle</th>"
30 "<th>Links</th></tr>\n"); 66 "<th>Links</th></tr>\n");
@@ -52,2 +88,4 @@ void cgit_print_repolist(struct cacheitem *item)
52 html("</td><td>"); 88 html("</td><td>");
89 print_modtime(repo);
90 html("</td><td>");
53 html_link_open(cgit_repourl(repo->url), 91 html_link_open(cgit_repourl(repo->url),