summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Makefile4
-rw-r--r--cgit.c2
m---------git0
-rw-r--r--ui-commit.c2
-rw-r--r--ui-log.c2
-rw-r--r--ui-plain.c2
-rw-r--r--ui-stats.c8
7 files changed, 10 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 3e5a38d..2a15469 100644
--- a/Makefile
+++ b/Makefile
@@ -1,32 +1,32 @@
1CGIT_VERSION = v0.8.3.3 1CGIT_VERSION = v0.8.3.3
2CGIT_SCRIPT_NAME = cgit.cgi 2CGIT_SCRIPT_NAME = cgit.cgi
3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit 3CGIT_SCRIPT_PATH = /var/www/htdocs/cgit
4CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH) 4CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)
5CGIT_CONFIG = /etc/cgitrc 5CGIT_CONFIG = /etc/cgitrc
6CACHE_ROOT = /var/cache/cgit 6CACHE_ROOT = /var/cache/cgit
7SHA1_HEADER = <openssl/sha.h> 7SHA1_HEADER = <openssl/sha.h>
8GIT_VER = 1.7.0 8GIT_VER = 1.7.2.2
9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 9GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2
10INSTALL = install 10INSTALL = install
11 11
12# Define NO_STRCASESTR if you don't have strcasestr. 12# Define NO_STRCASESTR if you don't have strcasestr.
13# 13#
14# Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1 14# Define NO_OPENSSL to disable linking with OpenSSL and use bundled SHA1
15# implementation (slower). 15# implementation (slower).
16# 16#
17# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin). 17# Define NEEDS_LIBICONV if linking with libc is not enough (eg. Darwin).
18# 18#
19 19
20#-include config.mak 20#-include config.mak
21 21
22# 22#
23# Platform specific tweaks 23# Platform specific tweaks
24# 24#
25 25
26uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') 26uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
27uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not') 27uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
28uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not') 28uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
29 29
30ifeq ($(uname_O),Cygwin) 30ifeq ($(uname_O),Cygwin)
31 NO_STRCASESTR = YesPlease 31 NO_STRCASESTR = YesPlease
32 NEEDS_LIBICONV = YesPlease 32 NEEDS_LIBICONV = YesPlease
@@ -50,49 +50,49 @@ else # "make -w"
50NO_SUBDIR = : 50NO_SUBDIR = :
51endif 51endif
52 52
53ifndef V 53ifndef V
54 QUIET_CC = @echo ' ' CC $@; 54 QUIET_CC = @echo ' ' CC $@;
55 QUIET_MM = @echo ' ' MM $@; 55 QUIET_MM = @echo ' ' MM $@;
56 QUIET_SUBDIR0 = +@subdir= 56 QUIET_SUBDIR0 = +@subdir=
57 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \ 57 QUIET_SUBDIR1 = ;$(NO_SUBDIR) echo ' ' SUBDIR $$subdir; \
58 $(MAKE) $(PRINT_DIR) -C $$subdir 58 $(MAKE) $(PRINT_DIR) -C $$subdir
59endif 59endif
60 60
61# 61#
62# Define a pattern rule for automatic dependency building 62# Define a pattern rule for automatic dependency building
63# 63#
64%.d: %.c 64%.d: %.c
65 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@ 65 $(QUIET_MM)$(CC) $(CFLAGS) -MM $< | sed -e 's/\($*\)\.o:/\1.o $@:/g' >$@
66 66
67# 67#
68# Define a pattern rule for silent object building 68# Define a pattern rule for silent object building
69# 69#
70%.o: %.c 70%.o: %.c
71 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $< 71 $(QUIET_CC)$(CC) -o $*.o -c $(CFLAGS) $<
72 72
73 73
74EXTLIBS = git/libgit.a git/xdiff/lib.a -lz 74EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lpthread
75OBJECTS = 75OBJECTS =
76OBJECTS += cache.o 76OBJECTS += cache.o
77OBJECTS += cgit.o 77OBJECTS += cgit.o
78OBJECTS += cmd.o 78OBJECTS += cmd.o
79OBJECTS += configfile.o 79OBJECTS += configfile.o
80OBJECTS += html.o 80OBJECTS += html.o
81OBJECTS += parsing.o 81OBJECTS += parsing.o
82OBJECTS += scan-tree.o 82OBJECTS += scan-tree.o
83OBJECTS += shared.o 83OBJECTS += shared.o
84OBJECTS += ui-atom.o 84OBJECTS += ui-atom.o
85OBJECTS += ui-blob.o 85OBJECTS += ui-blob.o
86OBJECTS += ui-clone.o 86OBJECTS += ui-clone.o
87OBJECTS += ui-commit.o 87OBJECTS += ui-commit.o
88OBJECTS += ui-diff.o 88OBJECTS += ui-diff.o
89OBJECTS += ui-log.o 89OBJECTS += ui-log.o
90OBJECTS += ui-patch.o 90OBJECTS += ui-patch.o
91OBJECTS += ui-plain.o 91OBJECTS += ui-plain.o
92OBJECTS += ui-refs.o 92OBJECTS += ui-refs.o
93OBJECTS += ui-repolist.o 93OBJECTS += ui-repolist.o
94OBJECTS += ui-shared.o 94OBJECTS += ui-shared.o
95OBJECTS += ui-snapshot.o 95OBJECTS += ui-snapshot.o
96OBJECTS += ui-ssdiff.o 96OBJECTS += ui-ssdiff.o
97OBJECTS += ui-stats.o 97OBJECTS += ui-stats.o
98OBJECTS += ui-summary.o 98OBJECTS += ui-summary.o
diff --git a/cgit.c b/cgit.c
index 4f2c752..d6146e2 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1,49 +1,49 @@
1/* cgit.c: cgi for the git scm 1/* cgit.c: cgi for the git scm
2 * 2 *
3 * Copyright (C) 2006 Lars Hjemli 3 * Copyright (C) 2006 Lars Hjemli
4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com> 4 * Copyright (C) 2010 Jason A. Donenfeld <Jason@zx2c4.com>
5 * 5 *
6 * Licensed under GNU General Public License v2 6 * Licensed under GNU General Public License v2
7 * (see COPYING for full license text) 7 * (see COPYING for full license text)
8 */ 8 */
9 9
10#include "cgit.h" 10#include "cgit.h"
11#include "cache.h" 11#include "cache.h"
12#include "cmd.h" 12#include "cmd.h"
13#include "configfile.h" 13#include "configfile.h"
14#include "html.h" 14#include "html.h"
15#include "ui-shared.h" 15#include "ui-shared.h"
16#include "ui-stats.h" 16#include "ui-stats.h"
17#include "scan-tree.h" 17#include "scan-tree.h"
18 18
19const char *cgit_version = CGIT_VERSION; 19const char *cgit_version = CGIT_VERSION;
20 20
21void add_mimetype(const char *name, const char *value) 21void add_mimetype(const char *name, const char *value)
22{ 22{
23 struct string_list_item *item; 23 struct string_list_item *item;
24 24
25 item = string_list_insert(xstrdup(name), &ctx.cfg.mimetypes); 25 item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name));
26 item->util = xstrdup(value); 26 item->util = xstrdup(value);
27} 27}
28 28
29struct cgit_filter *new_filter(const char *cmd, int extra_args) 29struct cgit_filter *new_filter(const char *cmd, int extra_args)
30{ 30{
31 struct cgit_filter *f; 31 struct cgit_filter *f;
32 32
33 if (!cmd || !cmd[0]) 33 if (!cmd || !cmd[0])
34 return NULL; 34 return NULL;
35 35
36 f = xmalloc(sizeof(struct cgit_filter)); 36 f = xmalloc(sizeof(struct cgit_filter));
37 f->cmd = xstrdup(cmd); 37 f->cmd = xstrdup(cmd);
38 f->argv = xmalloc((2 + extra_args) * sizeof(char *)); 38 f->argv = xmalloc((2 + extra_args) * sizeof(char *));
39 f->argv[0] = f->cmd; 39 f->argv[0] = f->cmd;
40 f->argv[1] = NULL; 40 f->argv[1] = NULL;
41 return f; 41 return f;
42} 42}
43 43
44static void process_cached_repolist(const char *path); 44static void process_cached_repolist(const char *path);
45 45
46void repo_config(struct cgit_repo *repo, const char *name, const char *value) 46void repo_config(struct cgit_repo *repo, const char *name, const char *value)
47{ 47{
48 if (!strcmp(name, "name")) 48 if (!strcmp(name, "name"))
49 repo->name = xstrdup(value); 49 repo->name = xstrdup(value);
diff --git a/git b/git
Subproject e923eaeb901ff056421b9007adcbbce271caa7b Subproject 8c67c392e1620fc3b749aa9e0b8da13bd84226f
diff --git a/ui-commit.c b/ui-commit.c
index 45af450..2b4f677 100644
--- a/ui-commit.c
+++ b/ui-commit.c
@@ -15,49 +15,49 @@
15void cgit_print_commit(char *hex, const char *prefix) 15void cgit_print_commit(char *hex, const char *prefix)
16{ 16{
17 struct commit *commit, *parent; 17 struct commit *commit, *parent;
18 struct commitinfo *info, *parent_info; 18 struct commitinfo *info, *parent_info;
19 struct commit_list *p; 19 struct commit_list *p;
20 struct strbuf notes = STRBUF_INIT; 20 struct strbuf notes = STRBUF_INIT;
21 unsigned char sha1[20]; 21 unsigned char sha1[20];
22 char *tmp, *tmp2; 22 char *tmp, *tmp2;
23 int parents = 0; 23 int parents = 0;
24 24
25 if (!hex) 25 if (!hex)
26 hex = ctx.qry.head; 26 hex = ctx.qry.head;
27 27
28 if (get_sha1(hex, sha1)) { 28 if (get_sha1(hex, sha1)) {
29 cgit_print_error(fmt("Bad object id: %s", hex)); 29 cgit_print_error(fmt("Bad object id: %s", hex));
30 return; 30 return;
31 } 31 }
32 commit = lookup_commit_reference(sha1); 32 commit = lookup_commit_reference(sha1);
33 if (!commit) { 33 if (!commit) {
34 cgit_print_error(fmt("Bad commit reference: %s", hex)); 34 cgit_print_error(fmt("Bad commit reference: %s", hex));
35 return; 35 return;
36 } 36 }
37 info = cgit_parse_commit(commit); 37 info = cgit_parse_commit(commit);
38 38
39 get_commit_notes(commit, &notes, PAGE_ENCODING, 0); 39 format_note(NULL, sha1, &notes, PAGE_ENCODING, 0);
40 40
41 load_ref_decorations(DECORATE_FULL_REFS); 41 load_ref_decorations(DECORATE_FULL_REFS);
42 42
43 html("<table summary='commit info' class='commit-info'>\n"); 43 html("<table summary='commit info' class='commit-info'>\n");
44 html("<tr><th>author</th><td>"); 44 html("<tr><th>author</th><td>");
45 html_txt(info->author); 45 html_txt(info->author);
46 if (!ctx.cfg.noplainemail) { 46 if (!ctx.cfg.noplainemail) {
47 html(" "); 47 html(" ");
48 html_txt(info->author_email); 48 html_txt(info->author_email);
49 } 49 }
50 html("</td><td class='right'>"); 50 html("</td><td class='right'>");
51 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time); 51 cgit_print_date(info->author_date, FMT_LONGDATE, ctx.cfg.local_time);
52 html("</td></tr>\n"); 52 html("</td></tr>\n");
53 html("<tr><th>committer</th><td>"); 53 html("<tr><th>committer</th><td>");
54 html_txt(info->committer); 54 html_txt(info->committer);
55 if (!ctx.cfg.noplainemail) { 55 if (!ctx.cfg.noplainemail) {
56 html(" "); 56 html(" ");
57 html_txt(info->committer_email); 57 html_txt(info->committer_email);
58 } 58 }
59 html("</td><td class='right'>"); 59 html("</td><td class='right'>");
60 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time); 60 cgit_print_date(info->committer_date, FMT_LONGDATE, ctx.cfg.local_time);
61 html("</td></tr>\n"); 61 html("</td></tr>\n");
62 html("<tr><th>commit</th><td colspan='2' class='sha1'>"); 62 html("<tr><th>commit</th><td colspan='2' class='sha1'>");
63 tmp = sha1_to_hex(commit->object.sha1); 63 tmp = sha1_to_hex(commit->object.sha1);
diff --git a/ui-log.c b/ui-log.c
index 7f38d2a..0536b23 100644
--- a/ui-log.c
+++ b/ui-log.c
@@ -91,49 +91,49 @@ void print_commit(struct commit *commit)
91 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE); 91 cgit_print_age(commit->date, TM_WEEK * 2, FMT_SHORTDATE);
92 html_link_close(); 92 html_link_close();
93 htmlf("</td><td%s>", 93 htmlf("</td><td%s>",
94 ctx.qry.showmsg ? " class='logsubject'" : ""); 94 ctx.qry.showmsg ? " class='logsubject'" : "");
95 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head, 95 cgit_commit_link(info->subject, NULL, NULL, ctx.qry.head,
96 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0); 96 sha1_to_hex(commit->object.sha1), ctx.qry.vpath, 0);
97 show_commit_decorations(commit); 97 show_commit_decorations(commit);
98 html("</td><td>"); 98 html("</td><td>");
99 html_txt(info->author); 99 html_txt(info->author);
100 if (ctx.repo->enable_log_filecount) { 100 if (ctx.repo->enable_log_filecount) {
101 files = 0; 101 files = 0;
102 add_lines = 0; 102 add_lines = 0;
103 rem_lines = 0; 103 rem_lines = 0;
104 cgit_diff_commit(commit, inspect_files); 104 cgit_diff_commit(commit, inspect_files);
105 html("</td><td>"); 105 html("</td><td>");
106 htmlf("%d", files); 106 htmlf("%d", files);
107 if (ctx.repo->enable_log_linecount) { 107 if (ctx.repo->enable_log_linecount) {
108 html("</td><td>"); 108 html("</td><td>");
109 htmlf("-%d/+%d", rem_lines, add_lines); 109 htmlf("-%d/+%d", rem_lines, add_lines);
110 } 110 }
111 } 111 }
112 html("</td></tr>\n"); 112 html("</td></tr>\n");
113 if (ctx.qry.showmsg) { 113 if (ctx.qry.showmsg) {
114 struct strbuf notes = STRBUF_INIT; 114 struct strbuf notes = STRBUF_INIT;
115 get_commit_notes(commit, &notes, PAGE_ENCODING, 0); 115 format_note(NULL, commit->object.sha1, &notes, PAGE_ENCODING, 0);
116 116
117 if (ctx.repo->enable_log_filecount) { 117 if (ctx.repo->enable_log_filecount) {
118 cols++; 118 cols++;
119 if (ctx.repo->enable_log_linecount) 119 if (ctx.repo->enable_log_linecount)
120 cols++; 120 cols++;
121 } 121 }
122 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>", 122 htmlf("<tr class='nohover'><td/><td colspan='%d' class='logmsg'>",
123 cols); 123 cols);
124 html_txt(info->msg); 124 html_txt(info->msg);
125 html("</td></tr>\n"); 125 html("</td></tr>\n");
126 if (notes.len != 0) { 126 if (notes.len != 0) {
127 html("<tr class='nohover'>"); 127 html("<tr class='nohover'>");
128 html("<td class='lognotes-label'>Notes:</td>"); 128 html("<td class='lognotes-label'>Notes:</td>");
129 htmlf("<td colspan='%d' class='lognotes'>", 129 htmlf("<td colspan='%d' class='lognotes'>",
130 cols); 130 cols);
131 html_txt(notes.buf); 131 html_txt(notes.buf);
132 html("</td></tr>\n"); 132 html("</td></tr>\n");
133 } 133 }
134 strbuf_release(&notes); 134 strbuf_release(&notes);
135 } 135 }
136 cgit_free_commitinfo(info); 136 cgit_free_commitinfo(info);
137} 137}
138 138
139static const char *disambiguate_ref(const char *ref) 139static const char *disambiguate_ref(const char *ref)
diff --git a/ui-plain.c b/ui-plain.c
index da76406..1b2b672 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -13,49 +13,49 @@
13int match_baselen; 13int match_baselen;
14int match; 14int match;
15 15
16static void print_object(const unsigned char *sha1, const char *path) 16static void print_object(const unsigned char *sha1, const char *path)
17{ 17{
18 enum object_type type; 18 enum object_type type;
19 char *buf, *ext; 19 char *buf, *ext;
20 unsigned long size; 20 unsigned long size;
21 struct string_list_item *mime; 21 struct string_list_item *mime;
22 22
23 type = sha1_object_info(sha1, &size); 23 type = sha1_object_info(sha1, &size);
24 if (type == OBJ_BAD) { 24 if (type == OBJ_BAD) {
25 html_status(404, "Not found", 0); 25 html_status(404, "Not found", 0);
26 return; 26 return;
27 } 27 }
28 28
29 buf = read_sha1_file(sha1, &type, &size); 29 buf = read_sha1_file(sha1, &type, &size);
30 if (!buf) { 30 if (!buf) {
31 html_status(404, "Not found", 0); 31 html_status(404, "Not found", 0);
32 return; 32 return;
33 } 33 }
34 ctx.page.mimetype = NULL; 34 ctx.page.mimetype = NULL;
35 ext = strrchr(path, '.'); 35 ext = strrchr(path, '.');
36 if (ext && *(++ext)) { 36 if (ext && *(++ext)) {
37 mime = string_list_lookup(ext, &ctx.cfg.mimetypes); 37 mime = string_list_lookup(&ctx.cfg.mimetypes, ext);
38 if (mime) 38 if (mime)
39 ctx.page.mimetype = (char *)mime->util; 39 ctx.page.mimetype = (char *)mime->util;
40 } 40 }
41 if (!ctx.page.mimetype) { 41 if (!ctx.page.mimetype) {
42 if (buffer_is_binary(buf, size)) 42 if (buffer_is_binary(buf, size))
43 ctx.page.mimetype = "application/octet-stream"; 43 ctx.page.mimetype = "application/octet-stream";
44 else 44 else
45 ctx.page.mimetype = "text/plain"; 45 ctx.page.mimetype = "text/plain";
46 } 46 }
47 ctx.page.filename = fmt("%s", path); 47 ctx.page.filename = fmt("%s", path);
48 ctx.page.size = size; 48 ctx.page.size = size;
49 ctx.page.etag = sha1_to_hex(sha1); 49 ctx.page.etag = sha1_to_hex(sha1);
50 cgit_print_http_headers(&ctx); 50 cgit_print_http_headers(&ctx);
51 html_raw(buf, size); 51 html_raw(buf, size);
52 match = 1; 52 match = 1;
53} 53}
54 54
55static void print_dir(const unsigned char *sha1, const char *path, 55static void print_dir(const unsigned char *sha1, const char *path,
56 const char *base) 56 const char *base)
57{ 57{
58 char *fullpath; 58 char *fullpath;
59 if (path[0] || base[0]) 59 if (path[0] || base[0])
60 fullpath = fmt("/%s%s/", base, path); 60 fullpath = fmt("/%s%s/", base, path);
61 else 61 else
diff --git a/ui-stats.c b/ui-stats.c
index bdaf9cc..50c2540 100644
--- a/ui-stats.c
+++ b/ui-stats.c
@@ -154,60 +154,60 @@ int cgit_find_stats_period(const char *expr, struct cgit_period **period)
154 return 0; 154 return 0;
155} 155}
156 156
157const char *cgit_find_stats_periodname(int idx) 157const char *cgit_find_stats_periodname(int idx)
158{ 158{
159 if (idx > 0 && idx < 4) 159 if (idx > 0 && idx < 4)
160 return periods[idx - 1].name; 160 return periods[idx - 1].name;
161 else 161 else
162 return ""; 162 return "";
163} 163}
164 164
165static void add_commit(struct string_list *authors, struct commit *commit, 165static void add_commit(struct string_list *authors, struct commit *commit,
166 struct cgit_period *period) 166 struct cgit_period *period)
167{ 167{
168 struct commitinfo *info; 168 struct commitinfo *info;
169 struct string_list_item *author, *item; 169 struct string_list_item *author, *item;
170 struct authorstat *authorstat; 170 struct authorstat *authorstat;
171 struct string_list *items; 171 struct string_list *items;
172 char *tmp; 172 char *tmp;
173 struct tm *date; 173 struct tm *date;
174 time_t t; 174 time_t t;
175 175
176 info = cgit_parse_commit(commit); 176 info = cgit_parse_commit(commit);
177 tmp = xstrdup(info->author); 177 tmp = xstrdup(info->author);
178 author = string_list_insert(tmp, authors); 178 author = string_list_insert(authors, tmp);
179 if (!author->util) 179 if (!author->util)
180 author->util = xcalloc(1, sizeof(struct authorstat)); 180 author->util = xcalloc(1, sizeof(struct authorstat));
181 else 181 else
182 free(tmp); 182 free(tmp);
183 authorstat = author->util; 183 authorstat = author->util;
184 items = &authorstat->list; 184 items = &authorstat->list;
185 t = info->committer_date; 185 t = info->committer_date;
186 date = gmtime(&t); 186 date = gmtime(&t);
187 period->trunc(date); 187 period->trunc(date);
188 tmp = xstrdup(period->pretty(date)); 188 tmp = xstrdup(period->pretty(date));
189 item = string_list_insert(tmp, items); 189 item = string_list_insert(items, tmp);
190 if (item->util) 190 if (item->util)
191 free(tmp); 191 free(tmp);
192 item->util++; 192 item->util++;
193 authorstat->total++; 193 authorstat->total++;
194 cgit_free_commitinfo(info); 194 cgit_free_commitinfo(info);
195} 195}
196 196
197static int cmp_total_commits(const void *a1, const void *a2) 197static int cmp_total_commits(const void *a1, const void *a2)
198{ 198{
199 const struct string_list_item *i1 = a1; 199 const struct string_list_item *i1 = a1;
200 const struct string_list_item *i2 = a2; 200 const struct string_list_item *i2 = a2;
201 const struct authorstat *auth1 = i1->util; 201 const struct authorstat *auth1 = i1->util;
202 const struct authorstat *auth2 = i2->util; 202 const struct authorstat *auth2 = i2->util;
203 203
204 return auth2->total - auth1->total; 204 return auth2->total - auth1->total;
205} 205}
206 206
207/* Walk the commit DAG and collect number of commits per author per 207/* Walk the commit DAG and collect number of commits per author per
208 * timeperiod into a nested string_list collection. 208 * timeperiod into a nested string_list collection.
209 */ 209 */
210struct string_list collect_stats(struct cgit_context *ctx, 210struct string_list collect_stats(struct cgit_context *ctx,
211 struct cgit_period *period) 211 struct cgit_period *period)
212{ 212{
213 struct string_list authors; 213 struct string_list authors;
@@ -258,49 +258,49 @@ void print_combined_authorrow(struct string_list *authors, int from, int to,
258 struct string_list *items; 258 struct string_list *items;
259 struct string_list_item *date; 259 struct string_list_item *date;
260 time_t now; 260 time_t now;
261 long i, j, total, subtotal; 261 long i, j, total, subtotal;
262 struct tm *tm; 262 struct tm *tm;
263 char *tmp; 263 char *tmp;
264 264
265 time(&now); 265 time(&now);
266 tm = gmtime(&now); 266 tm = gmtime(&now);
267 period->trunc(tm); 267 period->trunc(tm);
268 for (i = 1; i < period->count; i++) 268 for (i = 1; i < period->count; i++)
269 period->dec(tm); 269 period->dec(tm);
270 270
271 total = 0; 271 total = 0;
272 htmlf("<tr><td class='%s'>%s</td>", leftclass, 272 htmlf("<tr><td class='%s'>%s</td>", leftclass,
273 fmt(name, to - from + 1)); 273 fmt(name, to - from + 1));
274 for (j = 0; j < period->count; j++) { 274 for (j = 0; j < period->count; j++) {
275 tmp = period->pretty(tm); 275 tmp = period->pretty(tm);
276 period->inc(tm); 276 period->inc(tm);
277 subtotal = 0; 277 subtotal = 0;
278 for (i = from; i <= to; i++) { 278 for (i = from; i <= to; i++) {
279 author = &authors->items[i]; 279 author = &authors->items[i];
280 authorstat = author->util; 280 authorstat = author->util;
281 items = &authorstat->list; 281 items = &authorstat->list;
282 date = string_list_lookup(tmp, items); 282 date = string_list_lookup(items, tmp);
283 if (date) 283 if (date)
284 subtotal += (size_t)date->util; 284 subtotal += (size_t)date->util;
285 } 285 }
286 htmlf("<td class='%s'>%d</td>", centerclass, subtotal); 286 htmlf("<td class='%s'>%d</td>", centerclass, subtotal);
287 total += subtotal; 287 total += subtotal;
288 } 288 }
289 htmlf("<td class='%s'>%d</td></tr>", rightclass, total); 289 htmlf("<td class='%s'>%d</td></tr>", rightclass, total);
290} 290}
291 291
292void print_authors(struct string_list *authors, int top, 292void print_authors(struct string_list *authors, int top,
293 struct cgit_period *period) 293 struct cgit_period *period)
294{ 294{
295 struct string_list_item *author; 295 struct string_list_item *author;
296 struct authorstat *authorstat; 296 struct authorstat *authorstat;
297 struct string_list *items; 297 struct string_list *items;
298 struct string_list_item *date; 298 struct string_list_item *date;
299 time_t now; 299 time_t now;
300 long i, j, total; 300 long i, j, total;
301 struct tm *tm; 301 struct tm *tm;
302 char *tmp; 302 char *tmp;
303 303
304 time(&now); 304 time(&now);
305 tm = gmtime(&now); 305 tm = gmtime(&now);
306 period->trunc(tm); 306 period->trunc(tm);
@@ -310,49 +310,49 @@ void print_authors(struct string_list *authors, int top,
310 html("<table class='stats'><tr><th>Author</th>"); 310 html("<table class='stats'><tr><th>Author</th>");
311 for (j = 0; j < period->count; j++) { 311 for (j = 0; j < period->count; j++) {
312 tmp = period->pretty(tm); 312 tmp = period->pretty(tm);
313 htmlf("<th>%s</th>", tmp); 313 htmlf("<th>%s</th>", tmp);
314 period->inc(tm); 314 period->inc(tm);
315 } 315 }
316 html("<th>Total</th></tr>\n"); 316 html("<th>Total</th></tr>\n");
317 317
318 if (top <= 0 || top > authors->nr) 318 if (top <= 0 || top > authors->nr)
319 top = authors->nr; 319 top = authors->nr;
320 320
321 for (i = 0; i < top; i++) { 321 for (i = 0; i < top; i++) {
322 author = &authors->items[i]; 322 author = &authors->items[i];
323 html("<tr><td class='left'>"); 323 html("<tr><td class='left'>");
324 html_txt(author->string); 324 html_txt(author->string);
325 html("</td>"); 325 html("</td>");
326 authorstat = author->util; 326 authorstat = author->util;
327 items = &authorstat->list; 327 items = &authorstat->list;
328 total = 0; 328 total = 0;
329 for (j = 0; j < period->count; j++) 329 for (j = 0; j < period->count; j++)
330 period->dec(tm); 330 period->dec(tm);
331 for (j = 0; j < period->count; j++) { 331 for (j = 0; j < period->count; j++) {
332 tmp = period->pretty(tm); 332 tmp = period->pretty(tm);
333 period->inc(tm); 333 period->inc(tm);
334 date = string_list_lookup(tmp, items); 334 date = string_list_lookup(items, tmp);
335 if (!date) 335 if (!date)
336 html("<td>0</td>"); 336 html("<td>0</td>");
337 else { 337 else {
338 htmlf("<td>%d</td>", date->util); 338 htmlf("<td>%d</td>", date->util);
339 total += (size_t)date->util; 339 total += (size_t)date->util;
340 } 340 }
341 } 341 }
342 htmlf("<td class='sum'>%d</td></tr>", total); 342 htmlf("<td class='sum'>%d</td></tr>", total);
343 } 343 }
344 344
345 if (top < authors->nr) 345 if (top < authors->nr)
346 print_combined_authorrow(authors, top, authors->nr - 1, 346 print_combined_authorrow(authors, top, authors->nr - 1,
347 "Others (%d)", "left", "", "sum", period); 347 "Others (%d)", "left", "", "sum", period);
348 348
349 print_combined_authorrow(authors, 0, authors->nr - 1, "Total", 349 print_combined_authorrow(authors, 0, authors->nr - 1, "Total",
350 "total", "sum", "sum", period); 350 "total", "sum", "sum", period);
351 html("</table>"); 351 html("</table>");
352} 352}
353 353
354/* Create a sorted string_list with one entry per author. The util-field 354/* Create a sorted string_list with one entry per author. The util-field
355 * for each author is another string_list which is used to calculate the 355 * for each author is another string_list which is used to calculate the
356 * number of commits per time-interval. 356 * number of commits per time-interval.
357 */ 357 */
358void cgit_show_stats(struct cgit_context *ctx) 358void cgit_show_stats(struct cgit_context *ctx)