author | Lars Hjemli <hjemli@gmail.com> | 2007-05-22 21:25:25 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-22 21:25:25 (UTC) |
commit | 57f6a8bf0de6c112cabc1d8e20ade2698bd886b7 (patch) (unidiff) | |
tree | 281f1b4c6716b7632efe46607fc951d888e2fb5f | |
parent | 237ef7b06d461ddf27b21cd13bfcb50befa4a916 (diff) | |
download | cgit-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>
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | shared.c | 3 | ||||
-rw-r--r-- | ui-repolist.c | 40 |
3 files changed, 43 insertions, 1 deletions
@@ -109,8 +109,9 @@ extern char *cgit_css; | |||
109 | extern char *cgit_logo; | 109 | extern char *cgit_logo; |
110 | extern char *cgit_index_header; | 110 | extern char *cgit_index_header; |
111 | extern char *cgit_logo_link; | 111 | extern char *cgit_logo_link; |
112 | extern char *cgit_module_link; | 112 | extern char *cgit_module_link; |
113 | extern char *cgit_agefile; | ||
113 | extern char *cgit_virtual_root; | 114 | extern char *cgit_virtual_root; |
114 | extern char *cgit_script_name; | 115 | extern char *cgit_script_name; |
115 | extern char *cgit_cache_root; | 116 | extern char *cgit_cache_root; |
116 | extern char *cgit_repo_group; | 117 | extern char *cgit_repo_group; |
@@ -17,8 +17,9 @@ char *cgit_css = "/cgit.css"; | |||
17 | char *cgit_logo = "/git-logo.png"; | 17 | char *cgit_logo = "/git-logo.png"; |
18 | char *cgit_index_header = NULL; | 18 | char *cgit_index_header = NULL; |
19 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; | 19 | char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; |
20 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; | 20 | char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; |
21 | char *cgit_agefile = "info/web/last-modified"; | ||
21 | char *cgit_virtual_root = NULL; | 22 | char *cgit_virtual_root = NULL; |
22 | char *cgit_script_name = CGIT_SCRIPT_NAME; | 23 | char *cgit_script_name = CGIT_SCRIPT_NAME; |
23 | char *cgit_cache_root = "/var/cache/cgit"; | 24 | char *cgit_cache_root = "/var/cache/cgit"; |
24 | char *cgit_repo_group = NULL; | 25 | char *cgit_repo_group = NULL; |
@@ -161,8 +162,10 @@ void cgit_global_config_cb(const char *name, const char *value) | |||
161 | else if (!strcmp(name, "max-repodesc-length")) | 162 | else if (!strcmp(name, "max-repodesc-length")) |
162 | cgit_max_repodesc_len = atoi(value); | 163 | cgit_max_repodesc_len = atoi(value); |
163 | else if (!strcmp(name, "max-commit-count")) | 164 | else if (!strcmp(name, "max-commit-count")) |
164 | cgit_max_commit_count = atoi(value); | 165 | cgit_max_commit_count = atoi(value); |
166 | else if (!strcmp(name, "agefile")) | ||
167 | cgit_agefile = xstrdup(value); | ||
165 | else if (!strcmp(name, "repo.group")) | 168 | else if (!strcmp(name, "repo.group")) |
166 | cgit_repo_group = xstrdup(value); | 169 | cgit_repo_group = xstrdup(value); |
167 | else if (!strcmp(name, "repo.url")) | 170 | else if (!strcmp(name, "repo.url")) |
168 | cgit_repo = add_repo(value); | 171 | cgit_repo = add_repo(value); |
diff --git a/ui-repolist.c b/ui-repolist.c index f5e087f..573c730 100644 --- a/ui-repolist.c +++ b/ui-repolist.c | |||
@@ -6,8 +6,43 @@ | |||
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | #include <time.h> | ||
11 | |||
12 | |||
13 | time_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 | |||
29 | static 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 | ||
11 | void cgit_print_repolist(struct cacheitem *item) | 46 | void cgit_print_repolist(struct cacheitem *item) |
12 | { | 47 | { |
13 | struct repoinfo *repo; | 48 | struct repoinfo *repo; |
@@ -18,16 +53,17 @@ void cgit_print_repolist(struct cacheitem *item) | |||
18 | cgit_print_pageheader(cgit_root_title, 0); | 53 | cgit_print_pageheader(cgit_root_title, 0); |
19 | 54 | ||
20 | html("<table class='list nowrap'>"); | 55 | html("<table class='list nowrap'>"); |
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); |
24 | html("</td></tr>"); | 59 | html("</td></tr>"); |
25 | } | 60 | } |
26 | html("<tr class='nohover'>" | 61 | html("<tr class='nohover'>" |
27 | "<th class='left'>Name</th>" | 62 | "<th class='left'>Name</th>" |
28 | "<th class='left'>Description</th>" | 63 | "<th class='left'>Description</th>" |
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"); |
31 | 67 | ||
32 | for (i=0; i<cgit_repolist.count; i++) { | 68 | for (i=0; i<cgit_repolist.count; i++) { |
33 | repo = &cgit_repolist.repos[i]; | 69 | repo = &cgit_repolist.repos[i]; |
@@ -49,8 +85,10 @@ void cgit_print_repolist(struct cacheitem *item) | |||
49 | html_ntxt(cgit_max_repodesc_len, repo->desc); | 85 | html_ntxt(cgit_max_repodesc_len, repo->desc); |
50 | html("</td><td>"); | 86 | html("</td><td>"); |
51 | html_txt(repo->owner); | 87 | html_txt(repo->owner); |
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), |
54 | "Summary", "button"); | 92 | "Summary", "button"); |
55 | html("S</a>"); | 93 | html("S</a>"); |
56 | html_link_open(cgit_pageurl(repo->name, "log", NULL), | 94 | html_link_open(cgit_pageurl(repo->name, "log", NULL), |