author | Lars Hjemli <hjemli@gmail.com> | 2008-12-07 12:17:21 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-12-07 12:17:21 (UTC) |
commit | fb2f3f6c29bad733723152893c5246a756e4cada (patch) (unidiff) | |
tree | 5b2953c0c116f276ca48beee676a6662b6329d95 | |
parent | c6a6aa2186daf39814baa0e71378c2e9e1041002 (diff) | |
download | cgit-fb2f3f6c29bad733723152893c5246a756e4cada.zip cgit-fb2f3f6c29bad733723152893c5246a756e4cada.tar.gz cgit-fb2f3f6c29bad733723152893c5246a756e4cada.tar.bz2 |
ui-stats: replace 'enable-stats' setting with 'max-stats'
The new 'max-stats' and 'repo.max-stats' settings makes it possible to
define the maximum statistics period, both globally and per repo. Hence,
it is now feasible to allow statistics on repositories with a high commit
frequency, like linux-2.6, by setting repo.max-stats to e.g. 'month'.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 10 | ||||
-rw-r--r-- | cgit.h | 4 | ||||
-rw-r--r-- | cgitrc.5.txt | 23 | ||||
-rw-r--r-- | cmd.c | 5 | ||||
-rw-r--r-- | shared.c | 2 | ||||
-rw-r--r-- | ui-shared.c | 2 | ||||
-rw-r--r-- | ui-stats.c | 97 | ||||
-rw-r--r-- | ui-stats.h | 19 |
8 files changed, 104 insertions, 58 deletions
@@ -1,377 +1,379 @@ | |||
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 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
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 "cache.h" | 10 | #include "cache.h" |
11 | #include "cmd.h" | 11 | #include "cmd.h" |
12 | #include "configfile.h" | 12 | #include "configfile.h" |
13 | #include "html.h" | 13 | #include "html.h" |
14 | #include "ui-shared.h" | 14 | #include "ui-shared.h" |
15 | #include "ui-stats.h" | ||
15 | #include "scan-tree.h" | 16 | #include "scan-tree.h" |
16 | 17 | ||
17 | const char *cgit_version = CGIT_VERSION; | 18 | const char *cgit_version = CGIT_VERSION; |
18 | 19 | ||
19 | void config_cb(const char *name, const char *value) | 20 | void config_cb(const char *name, const char *value) |
20 | { | 21 | { |
21 | if (!strcmp(name, "root-title")) | 22 | if (!strcmp(name, "root-title")) |
22 | ctx.cfg.root_title = xstrdup(value); | 23 | ctx.cfg.root_title = xstrdup(value); |
23 | else if (!strcmp(name, "root-desc")) | 24 | else if (!strcmp(name, "root-desc")) |
24 | ctx.cfg.root_desc = xstrdup(value); | 25 | ctx.cfg.root_desc = xstrdup(value); |
25 | else if (!strcmp(name, "root-readme")) | 26 | else if (!strcmp(name, "root-readme")) |
26 | ctx.cfg.root_readme = xstrdup(value); | 27 | ctx.cfg.root_readme = xstrdup(value); |
27 | else if (!strcmp(name, "css")) | 28 | else if (!strcmp(name, "css")) |
28 | ctx.cfg.css = xstrdup(value); | 29 | ctx.cfg.css = xstrdup(value); |
29 | else if (!strcmp(name, "favicon")) | 30 | else if (!strcmp(name, "favicon")) |
30 | ctx.cfg.favicon = xstrdup(value); | 31 | ctx.cfg.favicon = xstrdup(value); |
31 | else if (!strcmp(name, "footer")) | 32 | else if (!strcmp(name, "footer")) |
32 | ctx.cfg.footer = xstrdup(value); | 33 | ctx.cfg.footer = xstrdup(value); |
33 | else if (!strcmp(name, "logo")) | 34 | else if (!strcmp(name, "logo")) |
34 | ctx.cfg.logo = xstrdup(value); | 35 | ctx.cfg.logo = xstrdup(value); |
35 | else if (!strcmp(name, "index-header")) | 36 | else if (!strcmp(name, "index-header")) |
36 | ctx.cfg.index_header = xstrdup(value); | 37 | ctx.cfg.index_header = xstrdup(value); |
37 | else if (!strcmp(name, "index-info")) | 38 | else if (!strcmp(name, "index-info")) |
38 | ctx.cfg.index_info = xstrdup(value); | 39 | ctx.cfg.index_info = xstrdup(value); |
39 | else if (!strcmp(name, "logo-link")) | 40 | else if (!strcmp(name, "logo-link")) |
40 | ctx.cfg.logo_link = xstrdup(value); | 41 | ctx.cfg.logo_link = xstrdup(value); |
41 | else if (!strcmp(name, "module-link")) | 42 | else if (!strcmp(name, "module-link")) |
42 | ctx.cfg.module_link = xstrdup(value); | 43 | ctx.cfg.module_link = xstrdup(value); |
43 | else if (!strcmp(name, "virtual-root")) { | 44 | else if (!strcmp(name, "virtual-root")) { |
44 | ctx.cfg.virtual_root = trim_end(value, '/'); | 45 | ctx.cfg.virtual_root = trim_end(value, '/'); |
45 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) | 46 | if (!ctx.cfg.virtual_root && (!strcmp(value, "/"))) |
46 | ctx.cfg.virtual_root = ""; | 47 | ctx.cfg.virtual_root = ""; |
47 | } else if (!strcmp(name, "nocache")) | 48 | } else if (!strcmp(name, "nocache")) |
48 | ctx.cfg.nocache = atoi(value); | 49 | ctx.cfg.nocache = atoi(value); |
49 | else if (!strcmp(name, "snapshots")) | 50 | else if (!strcmp(name, "snapshots")) |
50 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); | 51 | ctx.cfg.snapshots = cgit_parse_snapshots_mask(value); |
51 | else if (!strcmp(name, "enable-index-links")) | 52 | else if (!strcmp(name, "enable-index-links")) |
52 | ctx.cfg.enable_index_links = atoi(value); | 53 | ctx.cfg.enable_index_links = atoi(value); |
53 | else if (!strcmp(name, "enable-log-filecount")) | 54 | else if (!strcmp(name, "enable-log-filecount")) |
54 | ctx.cfg.enable_log_filecount = atoi(value); | 55 | ctx.cfg.enable_log_filecount = atoi(value); |
55 | else if (!strcmp(name, "enable-log-linecount")) | 56 | else if (!strcmp(name, "enable-log-linecount")) |
56 | ctx.cfg.enable_log_linecount = atoi(value); | 57 | ctx.cfg.enable_log_linecount = atoi(value); |
57 | else if (!strcmp(name, "enable-stats")) | 58 | else if (!strcmp(name, "max-stats")) |
58 | ctx.cfg.enable_stats = atoi(value); | 59 | ctx.cfg.max_stats = cgit_find_stats_period(value, NULL); |
59 | else if (!strcmp(name, "cache-size")) | 60 | else if (!strcmp(name, "cache-size")) |
60 | ctx.cfg.cache_size = atoi(value); | 61 | ctx.cfg.cache_size = atoi(value); |
61 | else if (!strcmp(name, "cache-root")) | 62 | else if (!strcmp(name, "cache-root")) |
62 | ctx.cfg.cache_root = xstrdup(value); | 63 | ctx.cfg.cache_root = xstrdup(value); |
63 | else if (!strcmp(name, "cache-root-ttl")) | 64 | else if (!strcmp(name, "cache-root-ttl")) |
64 | ctx.cfg.cache_root_ttl = atoi(value); | 65 | ctx.cfg.cache_root_ttl = atoi(value); |
65 | else if (!strcmp(name, "cache-repo-ttl")) | 66 | else if (!strcmp(name, "cache-repo-ttl")) |
66 | ctx.cfg.cache_repo_ttl = atoi(value); | 67 | ctx.cfg.cache_repo_ttl = atoi(value); |
67 | else if (!strcmp(name, "cache-static-ttl")) | 68 | else if (!strcmp(name, "cache-static-ttl")) |
68 | ctx.cfg.cache_static_ttl = atoi(value); | 69 | ctx.cfg.cache_static_ttl = atoi(value); |
69 | else if (!strcmp(name, "cache-dynamic-ttl")) | 70 | else if (!strcmp(name, "cache-dynamic-ttl")) |
70 | ctx.cfg.cache_dynamic_ttl = atoi(value); | 71 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
71 | else if (!strcmp(name, "max-message-length")) | 72 | else if (!strcmp(name, "max-message-length")) |
72 | ctx.cfg.max_msg_len = atoi(value); | 73 | ctx.cfg.max_msg_len = atoi(value); |
73 | else if (!strcmp(name, "max-repodesc-length")) | 74 | else if (!strcmp(name, "max-repodesc-length")) |
74 | ctx.cfg.max_repodesc_len = atoi(value); | 75 | ctx.cfg.max_repodesc_len = atoi(value); |
75 | else if (!strcmp(name, "max-repo-count")) | 76 | else if (!strcmp(name, "max-repo-count")) |
76 | ctx.cfg.max_repo_count = atoi(value); | 77 | ctx.cfg.max_repo_count = atoi(value); |
77 | else if (!strcmp(name, "max-commit-count")) | 78 | else if (!strcmp(name, "max-commit-count")) |
78 | ctx.cfg.max_commit_count = atoi(value); | 79 | ctx.cfg.max_commit_count = atoi(value); |
79 | else if (!strcmp(name, "summary-log")) | 80 | else if (!strcmp(name, "summary-log")) |
80 | ctx.cfg.summary_log = atoi(value); | 81 | ctx.cfg.summary_log = atoi(value); |
81 | else if (!strcmp(name, "summary-branches")) | 82 | else if (!strcmp(name, "summary-branches")) |
82 | ctx.cfg.summary_branches = atoi(value); | 83 | ctx.cfg.summary_branches = atoi(value); |
83 | else if (!strcmp(name, "summary-tags")) | 84 | else if (!strcmp(name, "summary-tags")) |
84 | ctx.cfg.summary_tags = atoi(value); | 85 | ctx.cfg.summary_tags = atoi(value); |
85 | else if (!strcmp(name, "agefile")) | 86 | else if (!strcmp(name, "agefile")) |
86 | ctx.cfg.agefile = xstrdup(value); | 87 | ctx.cfg.agefile = xstrdup(value); |
87 | else if (!strcmp(name, "renamelimit")) | 88 | else if (!strcmp(name, "renamelimit")) |
88 | ctx.cfg.renamelimit = atoi(value); | 89 | ctx.cfg.renamelimit = atoi(value); |
89 | else if (!strcmp(name, "robots")) | 90 | else if (!strcmp(name, "robots")) |
90 | ctx.cfg.robots = xstrdup(value); | 91 | ctx.cfg.robots = xstrdup(value); |
91 | else if (!strcmp(name, "clone-prefix")) | 92 | else if (!strcmp(name, "clone-prefix")) |
92 | ctx.cfg.clone_prefix = xstrdup(value); | 93 | ctx.cfg.clone_prefix = xstrdup(value); |
93 | else if (!strcmp(name, "local-time")) | 94 | else if (!strcmp(name, "local-time")) |
94 | ctx.cfg.local_time = atoi(value); | 95 | ctx.cfg.local_time = atoi(value); |
95 | else if (!strcmp(name, "repo.group")) | 96 | else if (!strcmp(name, "repo.group")) |
96 | ctx.cfg.repo_group = xstrdup(value); | 97 | ctx.cfg.repo_group = xstrdup(value); |
97 | else if (!strcmp(name, "repo.url")) | 98 | else if (!strcmp(name, "repo.url")) |
98 | ctx.repo = cgit_add_repo(value); | 99 | ctx.repo = cgit_add_repo(value); |
99 | else if (!strcmp(name, "repo.name")) | 100 | else if (!strcmp(name, "repo.name")) |
100 | ctx.repo->name = xstrdup(value); | 101 | ctx.repo->name = xstrdup(value); |
101 | else if (ctx.repo && !strcmp(name, "repo.path")) | 102 | else if (ctx.repo && !strcmp(name, "repo.path")) |
102 | ctx.repo->path = trim_end(value, '/'); | 103 | ctx.repo->path = trim_end(value, '/'); |
103 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) | 104 | else if (ctx.repo && !strcmp(name, "repo.clone-url")) |
104 | ctx.repo->clone_url = xstrdup(value); | 105 | ctx.repo->clone_url = xstrdup(value); |
105 | else if (ctx.repo && !strcmp(name, "repo.desc")) | 106 | else if (ctx.repo && !strcmp(name, "repo.desc")) |
106 | ctx.repo->desc = xstrdup(value); | 107 | ctx.repo->desc = xstrdup(value); |
107 | else if (ctx.repo && !strcmp(name, "repo.owner")) | 108 | else if (ctx.repo && !strcmp(name, "repo.owner")) |
108 | ctx.repo->owner = xstrdup(value); | 109 | ctx.repo->owner = xstrdup(value); |
109 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) | 110 | else if (ctx.repo && !strcmp(name, "repo.defbranch")) |
110 | ctx.repo->defbranch = xstrdup(value); | 111 | ctx.repo->defbranch = xstrdup(value); |
111 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) | 112 | else if (ctx.repo && !strcmp(name, "repo.snapshots")) |
112 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ | 113 | ctx.repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ |
113 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) | 114 | else if (ctx.repo && !strcmp(name, "repo.enable-log-filecount")) |
114 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); | 115 | ctx.repo->enable_log_filecount = ctx.cfg.enable_log_filecount * atoi(value); |
115 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) | 116 | else if (ctx.repo && !strcmp(name, "repo.enable-log-linecount")) |
116 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); | 117 | ctx.repo->enable_log_linecount = ctx.cfg.enable_log_linecount * atoi(value); |
117 | else if (ctx.repo && !strcmp(name, "repo.enable-stats")) | 118 | else if (ctx.repo && !strcmp(name, "repo.max-stats")) |
118 | ctx.repo->enable_stats = ctx.cfg.enable_stats && atoi(value); | 119 | ctx.repo->max_stats = cgit_find_stats_period(value, NULL); |
119 | else if (ctx.repo && !strcmp(name, "repo.module-link")) | 120 | else if (ctx.repo && !strcmp(name, "repo.module-link")) |
120 | ctx.repo->module_link= xstrdup(value); | 121 | ctx.repo->module_link= xstrdup(value); |
121 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { | 122 | else if (ctx.repo && !strcmp(name, "repo.readme") && value != NULL) { |
122 | if (*value == '/') | 123 | if (*value == '/') |
123 | ctx.repo->readme = xstrdup(value); | 124 | ctx.repo->readme = xstrdup(value); |
124 | else | 125 | else |
125 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); | 126 | ctx.repo->readme = xstrdup(fmt("%s/%s", ctx.repo->path, value)); |
126 | } else if (!strcmp(name, "include")) | 127 | } else if (!strcmp(name, "include")) |
127 | parse_configfile(value, config_cb); | 128 | parse_configfile(value, config_cb); |
128 | } | 129 | } |
129 | 130 | ||
130 | static void querystring_cb(const char *name, const char *value) | 131 | static void querystring_cb(const char *name, const char *value) |
131 | { | 132 | { |
132 | if (!strcmp(name,"r")) { | 133 | if (!strcmp(name,"r")) { |
133 | ctx.qry.repo = xstrdup(value); | 134 | ctx.qry.repo = xstrdup(value); |
134 | ctx.repo = cgit_get_repoinfo(value); | 135 | ctx.repo = cgit_get_repoinfo(value); |
135 | } else if (!strcmp(name, "p")) { | 136 | } else if (!strcmp(name, "p")) { |
136 | ctx.qry.page = xstrdup(value); | 137 | ctx.qry.page = xstrdup(value); |
137 | } else if (!strcmp(name, "url")) { | 138 | } else if (!strcmp(name, "url")) { |
138 | ctx.qry.url = xstrdup(value); | 139 | ctx.qry.url = xstrdup(value); |
139 | cgit_parse_url(value); | 140 | cgit_parse_url(value); |
140 | } else if (!strcmp(name, "qt")) { | 141 | } else if (!strcmp(name, "qt")) { |
141 | ctx.qry.grep = xstrdup(value); | 142 | ctx.qry.grep = xstrdup(value); |
142 | } else if (!strcmp(name, "q")) { | 143 | } else if (!strcmp(name, "q")) { |
143 | ctx.qry.search = xstrdup(value); | 144 | ctx.qry.search = xstrdup(value); |
144 | } else if (!strcmp(name, "h")) { | 145 | } else if (!strcmp(name, "h")) { |
145 | ctx.qry.head = xstrdup(value); | 146 | ctx.qry.head = xstrdup(value); |
146 | ctx.qry.has_symref = 1; | 147 | ctx.qry.has_symref = 1; |
147 | } else if (!strcmp(name, "id")) { | 148 | } else if (!strcmp(name, "id")) { |
148 | ctx.qry.sha1 = xstrdup(value); | 149 | ctx.qry.sha1 = xstrdup(value); |
149 | ctx.qry.has_sha1 = 1; | 150 | ctx.qry.has_sha1 = 1; |
150 | } else if (!strcmp(name, "id2")) { | 151 | } else if (!strcmp(name, "id2")) { |
151 | ctx.qry.sha2 = xstrdup(value); | 152 | ctx.qry.sha2 = xstrdup(value); |
152 | ctx.qry.has_sha1 = 1; | 153 | ctx.qry.has_sha1 = 1; |
153 | } else if (!strcmp(name, "ofs")) { | 154 | } else if (!strcmp(name, "ofs")) { |
154 | ctx.qry.ofs = atoi(value); | 155 | ctx.qry.ofs = atoi(value); |
155 | } else if (!strcmp(name, "path")) { | 156 | } else if (!strcmp(name, "path")) { |
156 | ctx.qry.path = trim_end(value, '/'); | 157 | ctx.qry.path = trim_end(value, '/'); |
157 | } else if (!strcmp(name, "name")) { | 158 | } else if (!strcmp(name, "name")) { |
158 | ctx.qry.name = xstrdup(value); | 159 | ctx.qry.name = xstrdup(value); |
159 | } else if (!strcmp(name, "mimetype")) { | 160 | } else if (!strcmp(name, "mimetype")) { |
160 | ctx.qry.mimetype = xstrdup(value); | 161 | ctx.qry.mimetype = xstrdup(value); |
161 | } else if (!strcmp(name, "period")) { | 162 | } else if (!strcmp(name, "period")) { |
162 | ctx.qry.period = xstrdup(value); | 163 | ctx.qry.period = xstrdup(value); |
163 | } | 164 | } |
164 | } | 165 | } |
165 | 166 | ||
166 | static void prepare_context(struct cgit_context *ctx) | 167 | static void prepare_context(struct cgit_context *ctx) |
167 | { | 168 | { |
168 | memset(ctx, 0, sizeof(ctx)); | 169 | memset(ctx, 0, sizeof(ctx)); |
169 | ctx->cfg.agefile = "info/web/last-modified"; | 170 | ctx->cfg.agefile = "info/web/last-modified"; |
170 | ctx->cfg.nocache = 0; | 171 | ctx->cfg.nocache = 0; |
171 | ctx->cfg.cache_size = 0; | 172 | ctx->cfg.cache_size = 0; |
172 | ctx->cfg.cache_dynamic_ttl = 5; | 173 | ctx->cfg.cache_dynamic_ttl = 5; |
173 | ctx->cfg.cache_max_create_time = 5; | 174 | ctx->cfg.cache_max_create_time = 5; |
174 | ctx->cfg.cache_repo_ttl = 5; | 175 | ctx->cfg.cache_repo_ttl = 5; |
175 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 176 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
176 | ctx->cfg.cache_root_ttl = 5; | 177 | ctx->cfg.cache_root_ttl = 5; |
177 | ctx->cfg.cache_static_ttl = -1; | 178 | ctx->cfg.cache_static_ttl = -1; |
178 | ctx->cfg.css = "/cgit.css"; | 179 | ctx->cfg.css = "/cgit.css"; |
179 | ctx->cfg.logo = "/git-logo.png"; | 180 | ctx->cfg.logo = "/git-logo.png"; |
180 | ctx->cfg.local_time = 0; | 181 | ctx->cfg.local_time = 0; |
181 | ctx->cfg.max_repo_count = 50; | 182 | ctx->cfg.max_repo_count = 50; |
182 | ctx->cfg.max_commit_count = 50; | 183 | ctx->cfg.max_commit_count = 50; |
183 | ctx->cfg.max_lock_attempts = 5; | 184 | ctx->cfg.max_lock_attempts = 5; |
184 | ctx->cfg.max_msg_len = 80; | 185 | ctx->cfg.max_msg_len = 80; |
185 | ctx->cfg.max_repodesc_len = 80; | 186 | ctx->cfg.max_repodesc_len = 80; |
187 | ctx->cfg.max_stats = 0; | ||
186 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; | 188 | ctx->cfg.module_link = "./?repo=%s&page=commit&id=%s"; |
187 | ctx->cfg.renamelimit = -1; | 189 | ctx->cfg.renamelimit = -1; |
188 | ctx->cfg.robots = "index, nofollow"; | 190 | ctx->cfg.robots = "index, nofollow"; |
189 | ctx->cfg.root_title = "Git repository browser"; | 191 | ctx->cfg.root_title = "Git repository browser"; |
190 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; | 192 | ctx->cfg.root_desc = "a fast webinterface for the git dscm"; |
191 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; | 193 | ctx->cfg.script_name = CGIT_SCRIPT_NAME; |
192 | ctx->cfg.summary_branches = 10; | 194 | ctx->cfg.summary_branches = 10; |
193 | ctx->cfg.summary_log = 10; | 195 | ctx->cfg.summary_log = 10; |
194 | ctx->cfg.summary_tags = 10; | 196 | ctx->cfg.summary_tags = 10; |
195 | ctx->page.mimetype = "text/html"; | 197 | ctx->page.mimetype = "text/html"; |
196 | ctx->page.charset = PAGE_ENCODING; | 198 | ctx->page.charset = PAGE_ENCODING; |
197 | ctx->page.filename = NULL; | 199 | ctx->page.filename = NULL; |
198 | ctx->page.size = 0; | 200 | ctx->page.size = 0; |
199 | ctx->page.modified = time(NULL); | 201 | ctx->page.modified = time(NULL); |
200 | ctx->page.expires = ctx->page.modified; | 202 | ctx->page.expires = ctx->page.modified; |
201 | } | 203 | } |
202 | 204 | ||
203 | struct refmatch { | 205 | struct refmatch { |
204 | char *req_ref; | 206 | char *req_ref; |
205 | char *first_ref; | 207 | char *first_ref; |
206 | int match; | 208 | int match; |
207 | }; | 209 | }; |
208 | 210 | ||
209 | int find_current_ref(const char *refname, const unsigned char *sha1, | 211 | int find_current_ref(const char *refname, const unsigned char *sha1, |
210 | int flags, void *cb_data) | 212 | int flags, void *cb_data) |
211 | { | 213 | { |
212 | struct refmatch *info; | 214 | struct refmatch *info; |
213 | 215 | ||
214 | info = (struct refmatch *)cb_data; | 216 | info = (struct refmatch *)cb_data; |
215 | if (!strcmp(refname, info->req_ref)) | 217 | if (!strcmp(refname, info->req_ref)) |
216 | info->match = 1; | 218 | info->match = 1; |
217 | if (!info->first_ref) | 219 | if (!info->first_ref) |
218 | info->first_ref = xstrdup(refname); | 220 | info->first_ref = xstrdup(refname); |
219 | return info->match; | 221 | return info->match; |
220 | } | 222 | } |
221 | 223 | ||
222 | char *find_default_branch(struct cgit_repo *repo) | 224 | char *find_default_branch(struct cgit_repo *repo) |
223 | { | 225 | { |
224 | struct refmatch info; | 226 | struct refmatch info; |
225 | char *ref; | 227 | char *ref; |
226 | 228 | ||
227 | info.req_ref = repo->defbranch; | 229 | info.req_ref = repo->defbranch; |
228 | info.first_ref = NULL; | 230 | info.first_ref = NULL; |
229 | info.match = 0; | 231 | info.match = 0; |
230 | for_each_branch_ref(find_current_ref, &info); | 232 | for_each_branch_ref(find_current_ref, &info); |
231 | if (info.match) | 233 | if (info.match) |
232 | ref = info.req_ref; | 234 | ref = info.req_ref; |
233 | else | 235 | else |
234 | ref = info.first_ref; | 236 | ref = info.first_ref; |
235 | if (ref) | 237 | if (ref) |
236 | ref = xstrdup(ref); | 238 | ref = xstrdup(ref); |
237 | return ref; | 239 | return ref; |
238 | } | 240 | } |
239 | 241 | ||
240 | static int prepare_repo_cmd(struct cgit_context *ctx) | 242 | static int prepare_repo_cmd(struct cgit_context *ctx) |
241 | { | 243 | { |
242 | char *tmp; | 244 | char *tmp; |
243 | unsigned char sha1[20]; | 245 | unsigned char sha1[20]; |
244 | int nongit = 0; | 246 | int nongit = 0; |
245 | 247 | ||
246 | setenv("GIT_DIR", ctx->repo->path, 1); | 248 | setenv("GIT_DIR", ctx->repo->path, 1); |
247 | setup_git_directory_gently(&nongit); | 249 | setup_git_directory_gently(&nongit); |
248 | if (nongit) { | 250 | if (nongit) { |
249 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, | 251 | ctx->page.title = fmt("%s - %s", ctx->cfg.root_title, |
250 | "config error"); | 252 | "config error"); |
251 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); | 253 | tmp = fmt("Not a git repository: '%s'", ctx->repo->path); |
252 | ctx->repo = NULL; | 254 | ctx->repo = NULL; |
253 | cgit_print_http_headers(ctx); | 255 | cgit_print_http_headers(ctx); |
254 | cgit_print_docstart(ctx); | 256 | cgit_print_docstart(ctx); |
255 | cgit_print_pageheader(ctx); | 257 | cgit_print_pageheader(ctx); |
256 | cgit_print_error(tmp); | 258 | cgit_print_error(tmp); |
257 | cgit_print_docend(); | 259 | cgit_print_docend(); |
258 | return 1; | 260 | return 1; |
259 | } | 261 | } |
260 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); | 262 | ctx->page.title = fmt("%s - %s", ctx->repo->name, ctx->repo->desc); |
261 | 263 | ||
262 | if (!ctx->qry.head) { | 264 | if (!ctx->qry.head) { |
263 | ctx->qry.nohead = 1; | 265 | ctx->qry.nohead = 1; |
264 | ctx->qry.head = find_default_branch(ctx->repo); | 266 | ctx->qry.head = find_default_branch(ctx->repo); |
265 | ctx->repo->defbranch = ctx->qry.head; | 267 | ctx->repo->defbranch = ctx->qry.head; |
266 | } | 268 | } |
267 | 269 | ||
268 | if (!ctx->qry.head) { | 270 | if (!ctx->qry.head) { |
269 | cgit_print_http_headers(ctx); | 271 | cgit_print_http_headers(ctx); |
270 | cgit_print_docstart(ctx); | 272 | cgit_print_docstart(ctx); |
271 | cgit_print_pageheader(ctx); | 273 | cgit_print_pageheader(ctx); |
272 | cgit_print_error("Repository seems to be empty"); | 274 | cgit_print_error("Repository seems to be empty"); |
273 | cgit_print_docend(); | 275 | cgit_print_docend(); |
274 | return 1; | 276 | return 1; |
275 | } | 277 | } |
276 | 278 | ||
277 | if (get_sha1(ctx->qry.head, sha1)) { | 279 | if (get_sha1(ctx->qry.head, sha1)) { |
278 | tmp = xstrdup(ctx->qry.head); | 280 | tmp = xstrdup(ctx->qry.head); |
279 | ctx->qry.head = ctx->repo->defbranch; | 281 | ctx->qry.head = ctx->repo->defbranch; |
280 | cgit_print_http_headers(ctx); | 282 | cgit_print_http_headers(ctx); |
281 | cgit_print_docstart(ctx); | 283 | cgit_print_docstart(ctx); |
282 | cgit_print_pageheader(ctx); | 284 | cgit_print_pageheader(ctx); |
283 | cgit_print_error(fmt("Invalid branch: %s", tmp)); | 285 | cgit_print_error(fmt("Invalid branch: %s", tmp)); |
284 | cgit_print_docend(); | 286 | cgit_print_docend(); |
285 | return 1; | 287 | return 1; |
286 | } | 288 | } |
287 | return 0; | 289 | return 0; |
288 | } | 290 | } |
289 | 291 | ||
290 | static void process_request(void *cbdata) | 292 | static void process_request(void *cbdata) |
291 | { | 293 | { |
292 | struct cgit_context *ctx = cbdata; | 294 | struct cgit_context *ctx = cbdata; |
293 | struct cgit_cmd *cmd; | 295 | struct cgit_cmd *cmd; |
294 | 296 | ||
295 | cmd = cgit_get_cmd(ctx); | 297 | cmd = cgit_get_cmd(ctx); |
296 | if (!cmd) { | 298 | if (!cmd) { |
297 | ctx->page.title = "cgit error"; | 299 | ctx->page.title = "cgit error"; |
298 | ctx->repo = NULL; | 300 | ctx->repo = NULL; |
299 | cgit_print_http_headers(ctx); | 301 | cgit_print_http_headers(ctx); |
300 | cgit_print_docstart(ctx); | 302 | cgit_print_docstart(ctx); |
301 | cgit_print_pageheader(ctx); | 303 | cgit_print_pageheader(ctx); |
302 | cgit_print_error("Invalid request"); | 304 | cgit_print_error("Invalid request"); |
303 | cgit_print_docend(); | 305 | cgit_print_docend(); |
304 | return; | 306 | return; |
305 | } | 307 | } |
306 | 308 | ||
307 | if (cmd->want_repo && !ctx->repo) { | 309 | if (cmd->want_repo && !ctx->repo) { |
308 | cgit_print_http_headers(ctx); | 310 | cgit_print_http_headers(ctx); |
309 | cgit_print_docstart(ctx); | 311 | cgit_print_docstart(ctx); |
310 | cgit_print_pageheader(ctx); | 312 | cgit_print_pageheader(ctx); |
311 | cgit_print_error(fmt("No repository selected")); | 313 | cgit_print_error(fmt("No repository selected")); |
312 | cgit_print_docend(); | 314 | cgit_print_docend(); |
313 | return; | 315 | return; |
314 | } | 316 | } |
315 | 317 | ||
316 | if (ctx->repo && prepare_repo_cmd(ctx)) | 318 | if (ctx->repo && prepare_repo_cmd(ctx)) |
317 | return; | 319 | return; |
318 | 320 | ||
319 | if (cmd->want_layout) { | 321 | if (cmd->want_layout) { |
320 | cgit_print_http_headers(ctx); | 322 | cgit_print_http_headers(ctx); |
321 | cgit_print_docstart(ctx); | 323 | cgit_print_docstart(ctx); |
322 | cgit_print_pageheader(ctx); | 324 | cgit_print_pageheader(ctx); |
323 | } | 325 | } |
324 | 326 | ||
325 | cmd->fn(ctx); | 327 | cmd->fn(ctx); |
326 | 328 | ||
327 | if (cmd->want_layout) | 329 | if (cmd->want_layout) |
328 | cgit_print_docend(); | 330 | cgit_print_docend(); |
329 | } | 331 | } |
330 | 332 | ||
331 | int cmp_repos(const void *a, const void *b) | 333 | int cmp_repos(const void *a, const void *b) |
332 | { | 334 | { |
333 | const struct cgit_repo *ra = a, *rb = b; | 335 | const struct cgit_repo *ra = a, *rb = b; |
334 | return strcmp(ra->url, rb->url); | 336 | return strcmp(ra->url, rb->url); |
335 | } | 337 | } |
336 | 338 | ||
337 | void print_repo(struct cgit_repo *repo) | 339 | void print_repo(struct cgit_repo *repo) |
338 | { | 340 | { |
339 | printf("repo.url=%s\n", repo->url); | 341 | printf("repo.url=%s\n", repo->url); |
340 | printf("repo.name=%s\n", repo->name); | 342 | printf("repo.name=%s\n", repo->name); |
341 | printf("repo.path=%s\n", repo->path); | 343 | printf("repo.path=%s\n", repo->path); |
342 | if (repo->owner) | 344 | if (repo->owner) |
343 | printf("repo.owner=%s\n", repo->owner); | 345 | printf("repo.owner=%s\n", repo->owner); |
344 | if (repo->desc) | 346 | if (repo->desc) |
345 | printf("repo.desc=%s\n", repo->desc); | 347 | printf("repo.desc=%s\n", repo->desc); |
346 | if (repo->readme) | 348 | if (repo->readme) |
347 | printf("repo.readme=%s\n", repo->readme); | 349 | printf("repo.readme=%s\n", repo->readme); |
348 | printf("\n"); | 350 | printf("\n"); |
349 | } | 351 | } |
350 | 352 | ||
351 | void print_repolist(struct cgit_repolist *list) | 353 | void print_repolist(struct cgit_repolist *list) |
352 | { | 354 | { |
353 | int i; | 355 | int i; |
354 | 356 | ||
355 | for(i = 0; i < list->count; i++) | 357 | for(i = 0; i < list->count; i++) |
356 | print_repo(&list->repos[i]); | 358 | print_repo(&list->repos[i]); |
357 | } | 359 | } |
358 | 360 | ||
359 | 361 | ||
360 | static void cgit_parse_args(int argc, const char **argv) | 362 | static void cgit_parse_args(int argc, const char **argv) |
361 | { | 363 | { |
362 | int i; | 364 | int i; |
363 | int scan = 0; | 365 | int scan = 0; |
364 | 366 | ||
365 | for (i = 1; i < argc; i++) { | 367 | for (i = 1; i < argc; i++) { |
366 | if (!strncmp(argv[i], "--cache=", 8)) { | 368 | if (!strncmp(argv[i], "--cache=", 8)) { |
367 | ctx.cfg.cache_root = xstrdup(argv[i]+8); | 369 | ctx.cfg.cache_root = xstrdup(argv[i]+8); |
368 | } | 370 | } |
369 | if (!strcmp(argv[i], "--nocache")) { | 371 | if (!strcmp(argv[i], "--nocache")) { |
370 | ctx.cfg.nocache = 1; | 372 | ctx.cfg.nocache = 1; |
371 | } | 373 | } |
372 | if (!strncmp(argv[i], "--query=", 8)) { | 374 | if (!strncmp(argv[i], "--query=", 8)) { |
373 | ctx.qry.raw = xstrdup(argv[i]+8); | 375 | ctx.qry.raw = xstrdup(argv[i]+8); |
374 | } | 376 | } |
375 | if (!strncmp(argv[i], "--repo=", 7)) { | 377 | if (!strncmp(argv[i], "--repo=", 7)) { |
376 | ctx.qry.repo = xstrdup(argv[i]+7); | 378 | ctx.qry.repo = xstrdup(argv[i]+7); |
377 | } | 379 | } |
@@ -1,246 +1,246 @@ | |||
1 | #ifndef CGIT_H | 1 | #ifndef CGIT_H |
2 | #define CGIT_H | 2 | #define CGIT_H |
3 | 3 | ||
4 | 4 | ||
5 | #include <git-compat-util.h> | 5 | #include <git-compat-util.h> |
6 | #include <cache.h> | 6 | #include <cache.h> |
7 | #include <grep.h> | 7 | #include <grep.h> |
8 | #include <object.h> | 8 | #include <object.h> |
9 | #include <tree.h> | 9 | #include <tree.h> |
10 | #include <commit.h> | 10 | #include <commit.h> |
11 | #include <tag.h> | 11 | #include <tag.h> |
12 | #include <diff.h> | 12 | #include <diff.h> |
13 | #include <diffcore.h> | 13 | #include <diffcore.h> |
14 | #include <refs.h> | 14 | #include <refs.h> |
15 | #include <revision.h> | 15 | #include <revision.h> |
16 | #include <log-tree.h> | 16 | #include <log-tree.h> |
17 | #include <archive.h> | 17 | #include <archive.h> |
18 | #include <xdiff/xdiff.h> | 18 | #include <xdiff/xdiff.h> |
19 | #include <utf8.h> | 19 | #include <utf8.h> |
20 | 20 | ||
21 | 21 | ||
22 | /* | 22 | /* |
23 | * Dateformats used on misc. pages | 23 | * Dateformats used on misc. pages |
24 | */ | 24 | */ |
25 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" | 25 | #define FMT_LONGDATE "%Y-%m-%d %H:%M:%S (%Z)" |
26 | #define FMT_SHORTDATE "%Y-%m-%d" | 26 | #define FMT_SHORTDATE "%Y-%m-%d" |
27 | #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" | 27 | #define FMT_ATOMDATE "%Y-%m-%dT%H:%M:%SZ" |
28 | 28 | ||
29 | 29 | ||
30 | /* | 30 | /* |
31 | * Limits used for relative dates | 31 | * Limits used for relative dates |
32 | */ | 32 | */ |
33 | #define TM_MIN 60 | 33 | #define TM_MIN 60 |
34 | #define TM_HOUR (TM_MIN * 60) | 34 | #define TM_HOUR (TM_MIN * 60) |
35 | #define TM_DAY (TM_HOUR * 24) | 35 | #define TM_DAY (TM_HOUR * 24) |
36 | #define TM_WEEK (TM_DAY * 7) | 36 | #define TM_WEEK (TM_DAY * 7) |
37 | #define TM_YEAR (TM_DAY * 365) | 37 | #define TM_YEAR (TM_DAY * 365) |
38 | #define TM_MONTH (TM_YEAR / 12.0) | 38 | #define TM_MONTH (TM_YEAR / 12.0) |
39 | 39 | ||
40 | 40 | ||
41 | /* | 41 | /* |
42 | * Default encoding | 42 | * Default encoding |
43 | */ | 43 | */ |
44 | #define PAGE_ENCODING "UTF-8" | 44 | #define PAGE_ENCODING "UTF-8" |
45 | 45 | ||
46 | typedef void (*configfn)(const char *name, const char *value); | 46 | typedef void (*configfn)(const char *name, const char *value); |
47 | typedef void (*filepair_fn)(struct diff_filepair *pair); | 47 | typedef void (*filepair_fn)(struct diff_filepair *pair); |
48 | typedef void (*linediff_fn)(char *line, int len); | 48 | typedef void (*linediff_fn)(char *line, int len); |
49 | 49 | ||
50 | struct cgit_repo { | 50 | struct cgit_repo { |
51 | char *url; | 51 | char *url; |
52 | char *name; | 52 | char *name; |
53 | char *path; | 53 | char *path; |
54 | char *desc; | 54 | char *desc; |
55 | char *owner; | 55 | char *owner; |
56 | char *defbranch; | 56 | char *defbranch; |
57 | char *group; | 57 | char *group; |
58 | char *module_link; | 58 | char *module_link; |
59 | char *readme; | 59 | char *readme; |
60 | char *clone_url; | 60 | char *clone_url; |
61 | int snapshots; | 61 | int snapshots; |
62 | int enable_log_filecount; | 62 | int enable_log_filecount; |
63 | int enable_log_linecount; | 63 | int enable_log_linecount; |
64 | int enable_stats; | 64 | int max_stats; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | struct cgit_repolist { | 67 | struct cgit_repolist { |
68 | int length; | 68 | int length; |
69 | int count; | 69 | int count; |
70 | struct cgit_repo *repos; | 70 | struct cgit_repo *repos; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | struct commitinfo { | 73 | struct commitinfo { |
74 | struct commit *commit; | 74 | struct commit *commit; |
75 | char *author; | 75 | char *author; |
76 | char *author_email; | 76 | char *author_email; |
77 | unsigned long author_date; | 77 | unsigned long author_date; |
78 | char *committer; | 78 | char *committer; |
79 | char *committer_email; | 79 | char *committer_email; |
80 | unsigned long committer_date; | 80 | unsigned long committer_date; |
81 | char *subject; | 81 | char *subject; |
82 | char *msg; | 82 | char *msg; |
83 | char *msg_encoding; | 83 | char *msg_encoding; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | struct taginfo { | 86 | struct taginfo { |
87 | char *tagger; | 87 | char *tagger; |
88 | char *tagger_email; | 88 | char *tagger_email; |
89 | unsigned long tagger_date; | 89 | unsigned long tagger_date; |
90 | char *msg; | 90 | char *msg; |
91 | }; | 91 | }; |
92 | 92 | ||
93 | struct refinfo { | 93 | struct refinfo { |
94 | const char *refname; | 94 | const char *refname; |
95 | struct object *object; | 95 | struct object *object; |
96 | union { | 96 | union { |
97 | struct taginfo *tag; | 97 | struct taginfo *tag; |
98 | struct commitinfo *commit; | 98 | struct commitinfo *commit; |
99 | }; | 99 | }; |
100 | }; | 100 | }; |
101 | 101 | ||
102 | struct reflist { | 102 | struct reflist { |
103 | struct refinfo **refs; | 103 | struct refinfo **refs; |
104 | int alloc; | 104 | int alloc; |
105 | int count; | 105 | int count; |
106 | }; | 106 | }; |
107 | 107 | ||
108 | struct cgit_query { | 108 | struct cgit_query { |
109 | int has_symref; | 109 | int has_symref; |
110 | int has_sha1; | 110 | int has_sha1; |
111 | char *raw; | 111 | char *raw; |
112 | char *repo; | 112 | char *repo; |
113 | char *page; | 113 | char *page; |
114 | char *search; | 114 | char *search; |
115 | char *grep; | 115 | char *grep; |
116 | char *head; | 116 | char *head; |
117 | char *sha1; | 117 | char *sha1; |
118 | char *sha2; | 118 | char *sha2; |
119 | char *path; | 119 | char *path; |
120 | char *name; | 120 | char *name; |
121 | char *mimetype; | 121 | char *mimetype; |
122 | char *url; | 122 | char *url; |
123 | char *period; | 123 | char *period; |
124 | int ofs; | 124 | int ofs; |
125 | int nohead; | 125 | int nohead; |
126 | }; | 126 | }; |
127 | 127 | ||
128 | struct cgit_config { | 128 | struct cgit_config { |
129 | char *agefile; | 129 | char *agefile; |
130 | char *cache_root; | 130 | char *cache_root; |
131 | char *clone_prefix; | 131 | char *clone_prefix; |
132 | char *css; | 132 | char *css; |
133 | char *favicon; | 133 | char *favicon; |
134 | char *footer; | 134 | char *footer; |
135 | char *index_header; | 135 | char *index_header; |
136 | char *index_info; | 136 | char *index_info; |
137 | char *logo; | 137 | char *logo; |
138 | char *logo_link; | 138 | char *logo_link; |
139 | char *module_link; | 139 | char *module_link; |
140 | char *repo_group; | 140 | char *repo_group; |
141 | char *robots; | 141 | char *robots; |
142 | char *root_title; | 142 | char *root_title; |
143 | char *root_desc; | 143 | char *root_desc; |
144 | char *root_readme; | 144 | char *root_readme; |
145 | char *script_name; | 145 | char *script_name; |
146 | char *virtual_root; | 146 | char *virtual_root; |
147 | int cache_size; | 147 | int cache_size; |
148 | int cache_dynamic_ttl; | 148 | int cache_dynamic_ttl; |
149 | int cache_max_create_time; | 149 | int cache_max_create_time; |
150 | int cache_repo_ttl; | 150 | int cache_repo_ttl; |
151 | int cache_root_ttl; | 151 | int cache_root_ttl; |
152 | int cache_static_ttl; | 152 | int cache_static_ttl; |
153 | int enable_index_links; | 153 | int enable_index_links; |
154 | int enable_log_filecount; | 154 | int enable_log_filecount; |
155 | int enable_log_linecount; | 155 | int enable_log_linecount; |
156 | int enable_stats; | ||
157 | int local_time; | 156 | int local_time; |
158 | int max_repo_count; | 157 | int max_repo_count; |
159 | int max_commit_count; | 158 | int max_commit_count; |
160 | int max_lock_attempts; | 159 | int max_lock_attempts; |
161 | int max_msg_len; | 160 | int max_msg_len; |
162 | int max_repodesc_len; | 161 | int max_repodesc_len; |
162 | int max_stats; | ||
163 | int nocache; | 163 | int nocache; |
164 | int renamelimit; | 164 | int renamelimit; |
165 | int snapshots; | 165 | int snapshots; |
166 | int summary_branches; | 166 | int summary_branches; |
167 | int summary_log; | 167 | int summary_log; |
168 | int summary_tags; | 168 | int summary_tags; |
169 | }; | 169 | }; |
170 | 170 | ||
171 | struct cgit_page { | 171 | struct cgit_page { |
172 | time_t modified; | 172 | time_t modified; |
173 | time_t expires; | 173 | time_t expires; |
174 | size_t size; | 174 | size_t size; |
175 | char *mimetype; | 175 | char *mimetype; |
176 | char *charset; | 176 | char *charset; |
177 | char *filename; | 177 | char *filename; |
178 | char *title; | 178 | char *title; |
179 | }; | 179 | }; |
180 | 180 | ||
181 | struct cgit_context { | 181 | struct cgit_context { |
182 | struct cgit_query qry; | 182 | struct cgit_query qry; |
183 | struct cgit_config cfg; | 183 | struct cgit_config cfg; |
184 | struct cgit_repo *repo; | 184 | struct cgit_repo *repo; |
185 | struct cgit_page page; | 185 | struct cgit_page page; |
186 | }; | 186 | }; |
187 | 187 | ||
188 | struct cgit_snapshot_format { | 188 | struct cgit_snapshot_format { |
189 | const char *suffix; | 189 | const char *suffix; |
190 | const char *mimetype; | 190 | const char *mimetype; |
191 | write_archive_fn_t write_func; | 191 | write_archive_fn_t write_func; |
192 | int bit; | 192 | int bit; |
193 | }; | 193 | }; |
194 | 194 | ||
195 | extern const char *cgit_version; | 195 | extern const char *cgit_version; |
196 | 196 | ||
197 | extern struct cgit_repolist cgit_repolist; | 197 | extern struct cgit_repolist cgit_repolist; |
198 | extern struct cgit_context ctx; | 198 | extern struct cgit_context ctx; |
199 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; | 199 | extern const struct cgit_snapshot_format cgit_snapshot_formats[]; |
200 | 200 | ||
201 | extern struct cgit_repo *cgit_add_repo(const char *url); | 201 | extern struct cgit_repo *cgit_add_repo(const char *url); |
202 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); | 202 | extern struct cgit_repo *cgit_get_repoinfo(const char *url); |
203 | extern void cgit_repo_config_cb(const char *name, const char *value); | 203 | extern void cgit_repo_config_cb(const char *name, const char *value); |
204 | 204 | ||
205 | extern int chk_zero(int result, char *msg); | 205 | extern int chk_zero(int result, char *msg); |
206 | extern int chk_positive(int result, char *msg); | 206 | extern int chk_positive(int result, char *msg); |
207 | extern int chk_non_negative(int result, char *msg); | 207 | extern int chk_non_negative(int result, char *msg); |
208 | 208 | ||
209 | extern char *trim_end(const char *str, char c); | 209 | extern char *trim_end(const char *str, char c); |
210 | extern char *strlpart(char *txt, int maxlen); | 210 | extern char *strlpart(char *txt, int maxlen); |
211 | extern char *strrpart(char *txt, int maxlen); | 211 | extern char *strrpart(char *txt, int maxlen); |
212 | 212 | ||
213 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); | 213 | extern void cgit_add_ref(struct reflist *list, struct refinfo *ref); |
214 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, | 214 | extern int cgit_refs_cb(const char *refname, const unsigned char *sha1, |
215 | int flags, void *cb_data); | 215 | int flags, void *cb_data); |
216 | 216 | ||
217 | extern void *cgit_free_commitinfo(struct commitinfo *info); | 217 | extern void *cgit_free_commitinfo(struct commitinfo *info); |
218 | 218 | ||
219 | extern int cgit_diff_files(const unsigned char *old_sha1, | 219 | extern int cgit_diff_files(const unsigned char *old_sha1, |
220 | const unsigned char *new_sha1, | 220 | const unsigned char *new_sha1, |
221 | linediff_fn fn); | 221 | linediff_fn fn); |
222 | 222 | ||
223 | extern void cgit_diff_tree(const unsigned char *old_sha1, | 223 | extern void cgit_diff_tree(const unsigned char *old_sha1, |
224 | const unsigned char *new_sha1, | 224 | const unsigned char *new_sha1, |
225 | filepair_fn fn, const char *prefix); | 225 | filepair_fn fn, const char *prefix); |
226 | 226 | ||
227 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); | 227 | extern void cgit_diff_commit(struct commit *commit, filepair_fn fn); |
228 | 228 | ||
229 | extern char *fmt(const char *format,...); | 229 | extern char *fmt(const char *format,...); |
230 | 230 | ||
231 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); | 231 | extern struct commitinfo *cgit_parse_commit(struct commit *commit); |
232 | extern struct taginfo *cgit_parse_tag(struct tag *tag); | 232 | extern struct taginfo *cgit_parse_tag(struct tag *tag); |
233 | extern void cgit_parse_url(const char *url); | 233 | extern void cgit_parse_url(const char *url); |
234 | 234 | ||
235 | extern const char *cgit_repobasename(const char *reponame); | 235 | extern const char *cgit_repobasename(const char *reponame); |
236 | 236 | ||
237 | extern int cgit_parse_snapshots_mask(const char *str); | 237 | extern int cgit_parse_snapshots_mask(const char *str); |
238 | 238 | ||
239 | /* libgit.a either links against or compiles its own implementation of | 239 | /* libgit.a either links against or compiles its own implementation of |
240 | * strcasestr(), and we'd like to reuse it. Simply re-declaring it | 240 | * strcasestr(), and we'd like to reuse it. Simply re-declaring it |
241 | * seems to do the trick. | 241 | * seems to do the trick. |
242 | */ | 242 | */ |
243 | extern char *strcasestr(const char *haystack, const char *needle); | 243 | extern char *strcasestr(const char *haystack, const char *needle); |
244 | 244 | ||
245 | 245 | ||
246 | #endif /* CGIT_H */ | 246 | #endif /* CGIT_H */ |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 60d3ea4..0bbbea3 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -1,375 +1,384 @@ | |||
1 | CGITRC | 1 | CGITRC |
2 | ====== | 2 | ====== |
3 | 3 | ||
4 | 4 | ||
5 | NAME | 5 | NAME |
6 | ---- | 6 | ---- |
7 | cgitrc - runtime configuration for cgit | 7 | cgitrc - runtime configuration for cgit |
8 | 8 | ||
9 | 9 | ||
10 | DESCRIPTION | 10 | DESCRIPTION |
11 | ----------- | 11 | ----------- |
12 | Cgitrc contains all runtime settings for cgit, including the list of git | 12 | Cgitrc contains all runtime settings for cgit, including the list of git |
13 | repositories, formatted as a line-separated list of NAME=VALUE pairs. Blank | 13 | repositories, formatted as a line-separated list of NAME=VALUE pairs. Blank |
14 | lines, and lines starting with '#', are ignored. | 14 | lines, and lines starting with '#', are ignored. |
15 | 15 | ||
16 | 16 | ||
17 | GLOBAL SETTINGS | 17 | GLOBAL SETTINGS |
18 | --------------- | 18 | --------------- |
19 | agefile | 19 | agefile |
20 | Specifies a path, relative to each repository path, which can be used | 20 | Specifies a path, relative to each repository path, which can be used |
21 | to specify the date and time of the youngest commit in the repository. | 21 | to specify the date and time of the youngest commit in the repository. |
22 | The first line in the file is used as input to the "parse_date" | 22 | The first line in the file is used as input to the "parse_date" |
23 | function in libgit. Recommended timestamp-format is "yyyy-mm-dd | 23 | function in libgit. Recommended timestamp-format is "yyyy-mm-dd |
24 | hh:mm:ss". Default value: "info/web/last-modified". | 24 | hh:mm:ss". Default value: "info/web/last-modified". |
25 | 25 | ||
26 | cache-root | 26 | cache-root |
27 | Path used to store the cgit cache entries. Default value: | 27 | Path used to store the cgit cache entries. Default value: |
28 | "/var/cache/cgit". | 28 | "/var/cache/cgit". |
29 | 29 | ||
30 | cache-dynamic-ttl | 30 | cache-dynamic-ttl |
31 | Number which specifies the time-to-live, in minutes, for the cached | 31 | Number which specifies the time-to-live, in minutes, for the cached |
32 | version of repository pages accessed without a fixed SHA1. Default | 32 | version of repository pages accessed without a fixed SHA1. Default |
33 | value: "5". | 33 | value: "5". |
34 | 34 | ||
35 | cache-repo-ttl | 35 | cache-repo-ttl |
36 | Number which specifies the time-to-live, in minutes, for the cached | 36 | Number which specifies the time-to-live, in minutes, for the cached |
37 | version of the repository summary page. Default value: "5". | 37 | version of the repository summary page. Default value: "5". |
38 | 38 | ||
39 | cache-root-ttl | 39 | cache-root-ttl |
40 | Number which specifies the time-to-live, in minutes, for the cached | 40 | Number which specifies the time-to-live, in minutes, for the cached |
41 | version of the repository index page. Default value: "5". | 41 | version of the repository index page. Default value: "5". |
42 | 42 | ||
43 | cache-size | 43 | cache-size |
44 | The maximum number of entries in the cgit cache. Default value: "0" | 44 | The maximum number of entries in the cgit cache. Default value: "0" |
45 | (i.e. caching is disabled). | 45 | (i.e. caching is disabled). |
46 | 46 | ||
47 | cache-static-ttl | 47 | cache-static-ttl |
48 | Number which specifies the time-to-live, in minutes, for the cached | 48 | Number which specifies the time-to-live, in minutes, for the cached |
49 | version of repository pages accessed with a fixed SHA1. Default value: | 49 | version of repository pages accessed with a fixed SHA1. Default value: |
50 | "5". | 50 | "5". |
51 | 51 | ||
52 | clone-prefix | 52 | clone-prefix |
53 | Space-separated list of common prefixes which, when combined with a | 53 | Space-separated list of common prefixes which, when combined with a |
54 | repository url, generates valid clone urls for the repository. This | 54 | repository url, generates valid clone urls for the repository. This |
55 | setting is only used if `repo.clone-url` is unspecified. Default value: | 55 | setting is only used if `repo.clone-url` is unspecified. Default value: |
56 | none. | 56 | none. |
57 | 57 | ||
58 | css | 58 | css |
59 | Url which specifies the css document to include in all cgit pages. | 59 | Url which specifies the css document to include in all cgit pages. |
60 | Default value: "/cgit.css". | 60 | Default value: "/cgit.css". |
61 | 61 | ||
62 | enable-index-links | 62 | enable-index-links |
63 | Flag which, when set to "1", will make cgit generate extra links for | 63 | Flag which, when set to "1", will make cgit generate extra links for |
64 | each repo in the repository index (specifically, to the "summary", | 64 | each repo in the repository index (specifically, to the "summary", |
65 | "commit" and "tree" pages). Default value: "0". | 65 | "commit" and "tree" pages). Default value: "0". |
66 | 66 | ||
67 | enable-log-filecount | 67 | enable-log-filecount |
68 | Flag which, when set to "1", will make cgit print the number of | 68 | Flag which, when set to "1", will make cgit print the number of |
69 | modified files for each commit on the repository log page. Default | 69 | modified files for each commit on the repository log page. Default |
70 | value: "0". | 70 | value: "0". |
71 | 71 | ||
72 | enable-log-linecount | 72 | enable-log-linecount |
73 | Flag which, when set to "1", will make cgit print the number of added | 73 | Flag which, when set to "1", will make cgit print the number of added |
74 | and removed lines for each commit on the repository log page. Default | 74 | and removed lines for each commit on the repository log page. Default |
75 | value: "0". | 75 | value: "0". |
76 | 76 | ||
77 | enable-stats | ||
78 | Globally enable/disable statistics for each repository. Default | ||
79 | value: "0". | ||
80 | |||
81 | favicon | 77 | favicon |
82 | Url used as link to a shortcut icon for cgit. If specified, it is | 78 | Url used as link to a shortcut icon for cgit. If specified, it is |
83 | suggested to use the value "/favicon.ico" since certain browsers will | 79 | suggested to use the value "/favicon.ico" since certain browsers will |
84 | ignore other values. Default value: none. | 80 | ignore other values. Default value: none. |
85 | 81 | ||
86 | footer | 82 | footer |
87 | The content of the file specified with this option will be included | 83 | The content of the file specified with this option will be included |
88 | verbatim at the bottom of all pages (i.e. it replaces the standard | 84 | verbatim at the bottom of all pages (i.e. it replaces the standard |
89 | "generated by..." message. Default value: none. | 85 | "generated by..." message. Default value: none. |
90 | 86 | ||
91 | include | 87 | include |
92 | Name of a configfile to include before the rest of the current config- | 88 | Name of a configfile to include before the rest of the current config- |
93 | file is parsed. Default value: none. | 89 | file is parsed. Default value: none. |
94 | 90 | ||
95 | index-header | 91 | index-header |
96 | The content of the file specified with this option will be included | 92 | The content of the file specified with this option will be included |
97 | verbatim above the repository index. This setting is deprecated, and | 93 | verbatim above the repository index. This setting is deprecated, and |
98 | will not be supported by cgit-1.0 (use root-readme instead). Default | 94 | will not be supported by cgit-1.0 (use root-readme instead). Default |
99 | value: none. | 95 | value: none. |
100 | 96 | ||
101 | index-info | 97 | index-info |
102 | The content of the file specified with this option will be included | 98 | The content of the file specified with this option will be included |
103 | verbatim below the heading on the repository index page. This setting | 99 | verbatim below the heading on the repository index page. This setting |
104 | is deprecated, and will not be supported by cgit-1.0 (use root-desc | 100 | is deprecated, and will not be supported by cgit-1.0 (use root-desc |
105 | instead). Default value: none. | 101 | instead). Default value: none. |
106 | 102 | ||
107 | local-time | 103 | local-time |
108 | Flag which, if set to "1", makes cgit print commit and tag times in the | 104 | Flag which, if set to "1", makes cgit print commit and tag times in the |
109 | servers timezone. Default value: "0". | 105 | servers timezone. Default value: "0". |
110 | 106 | ||
111 | logo | 107 | logo |
112 | Url which specifies the source of an image which will be used as a logo | 108 | Url which specifies the source of an image which will be used as a logo |
113 | on all cgit pages. | 109 | on all cgit pages. |
114 | 110 | ||
115 | logo-link | 111 | logo-link |
116 | Url loaded when clicking on the cgit logo image. If unspecified the | 112 | Url loaded when clicking on the cgit logo image. If unspecified the |
117 | calculated url of the repository index page will be used. Default | 113 | calculated url of the repository index page will be used. Default |
118 | value: none. | 114 | value: none. |
119 | 115 | ||
120 | max-commit-count | 116 | max-commit-count |
121 | Specifies the number of entries to list per page in "log" view. Default | 117 | Specifies the number of entries to list per page in "log" view. Default |
122 | value: "50". | 118 | value: "50". |
123 | 119 | ||
124 | max-message-length | 120 | max-message-length |
125 | Specifies the maximum number of commit message characters to display in | 121 | Specifies the maximum number of commit message characters to display in |
126 | "log" view. Default value: "80". | 122 | "log" view. Default value: "80". |
127 | 123 | ||
128 | max-repo-count | 124 | max-repo-count |
129 | Specifies the number of entries to list per page on therepository | 125 | Specifies the number of entries to list per page on therepository |
130 | index page. Default value: "50". | 126 | index page. Default value: "50". |
131 | 127 | ||
132 | max-repodesc-length | 128 | max-repodesc-length |
133 | Specifies the maximum number of repo description characters to display | 129 | Specifies the maximum number of repo description characters to display |
134 | on the repository index page. Default value: "80". | 130 | on the repository index page. Default value: "80". |
135 | 131 | ||
132 | max-stats | ||
133 | Set the default maximum statistics period. Valid values are "week", | ||
134 | "month", "quarter" and "year". If unspecified, statistics are | ||
135 | disabled. Default value: none. See also: "repo.max-stats". | ||
136 | |||
136 | module-link | 137 | module-link |
137 | Text which will be used as the formatstring for a hyperlink when a | 138 | Text which will be used as the formatstring for a hyperlink when a |
138 | submodule is printed in a directory listing. The arguments for the | 139 | submodule is printed in a directory listing. The arguments for the |
139 | formatstring are the path and SHA1 of the submodule commit. Default | 140 | formatstring are the path and SHA1 of the submodule commit. Default |
140 | value: "./?repo=%s&page=commit&id=%s" | 141 | value: "./?repo=%s&page=commit&id=%s" |
141 | 142 | ||
142 | nocache | 143 | nocache |
143 | If set to the value "1" caching will be disabled. This settings is | 144 | If set to the value "1" caching will be disabled. This settings is |
144 | deprecated, and will not be honored starting with cgit-1.0. Default | 145 | deprecated, and will not be honored starting with cgit-1.0. Default |
145 | value: "0". | 146 | value: "0". |
146 | 147 | ||
147 | renamelimit | 148 | renamelimit |
148 | Maximum number of files to consider when detecting renames. The value | 149 | Maximum number of files to consider when detecting renames. The value |
149 | "-1" uses the compiletime value in git (for further info, look at | 150 | "-1" uses the compiletime value in git (for further info, look at |
150 | `man git-diff`). Default value: "-1". | 151 | `man git-diff`). Default value: "-1". |
151 | 152 | ||
152 | repo.group | 153 | repo.group |
153 | A value for the current repository group, which all repositories | 154 | A value for the current repository group, which all repositories |
154 | specified after this setting will inherit. Default value: none. | 155 | specified after this setting will inherit. Default value: none. |
155 | 156 | ||
156 | robots | 157 | robots |
157 | Text used as content for the "robots" meta-tag. Default value: | 158 | Text used as content for the "robots" meta-tag. Default value: |
158 | "index, nofollow". | 159 | "index, nofollow". |
159 | 160 | ||
160 | root-desc | 161 | root-desc |
161 | Text printed below the heading on the repository index page. Default | 162 | Text printed below the heading on the repository index page. Default |
162 | value: "a fast webinterface for the git dscm". | 163 | value: "a fast webinterface for the git dscm". |
163 | 164 | ||
164 | root-readme: | 165 | root-readme: |
165 | The content of the file specified with this option will be included | 166 | The content of the file specified with this option will be included |
166 | verbatim below the "about" link on the repository index page. Default | 167 | verbatim below the "about" link on the repository index page. Default |
167 | value: none. | 168 | value: none. |
168 | 169 | ||
169 | root-title | 170 | root-title |
170 | Text printed as heading on the repository index page. Default value: | 171 | Text printed as heading on the repository index page. Default value: |
171 | "Git Repository Browser". | 172 | "Git Repository Browser". |
172 | 173 | ||
173 | snapshots | 174 | snapshots |
174 | Text which specifies the default (and allowed) set of snapshot formats | 175 | Text which specifies the default (and allowed) set of snapshot formats |
175 | supported by cgit. The value is a space-separated list of zero or more | 176 | supported by cgit. The value is a space-separated list of zero or more |
176 | of the following values: | 177 | of the following values: |
177 | "tar" uncompressed tar-file | 178 | "tar" uncompressed tar-file |
178 | "tar.gz"gzip-compressed tar-file | 179 | "tar.gz"gzip-compressed tar-file |
179 | "tar.bz2"bzip-compressed tar-file | 180 | "tar.bz2"bzip-compressed tar-file |
180 | "zip" zip-file | 181 | "zip" zip-file |
181 | Default value: none. | 182 | Default value: none. |
182 | 183 | ||
183 | summary-branches | 184 | summary-branches |
184 | Specifies the number of branches to display in the repository "summary" | 185 | Specifies the number of branches to display in the repository "summary" |
185 | view. Default value: "10". | 186 | view. Default value: "10". |
186 | 187 | ||
187 | summary-log | 188 | summary-log |
188 | Specifies the number of log entries to display in the repository | 189 | Specifies the number of log entries to display in the repository |
189 | "summary" view. Default value: "10". | 190 | "summary" view. Default value: "10". |
190 | 191 | ||
191 | summary-tags | 192 | summary-tags |
192 | Specifies the number of tags to display in the repository "summary" | 193 | Specifies the number of tags to display in the repository "summary" |
193 | view. Default value: "10". | 194 | view. Default value: "10". |
194 | 195 | ||
195 | virtual-root | 196 | virtual-root |
196 | Url which, if specified, will be used as root for all cgit links. It | 197 | Url which, if specified, will be used as root for all cgit links. It |
197 | will also cause cgit to generate 'virtual urls', i.e. urls like | 198 | will also cause cgit to generate 'virtual urls', i.e. urls like |
198 | '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default | 199 | '/cgit/tree/README' as opposed to '?r=cgit&p=tree&path=README'. Default |
199 | value: none. | 200 | value: none. |
200 | NOTE: cgit has recently learned how to use PATH_INFO to achieve the | 201 | NOTE: cgit has recently learned how to use PATH_INFO to achieve the |
201 | same kind of virtual urls, so this option will probably be deprecated. | 202 | same kind of virtual urls, so this option will probably be deprecated. |
202 | 203 | ||
203 | REPOSITORY SETTINGS | 204 | REPOSITORY SETTINGS |
204 | ------------------- | 205 | ------------------- |
205 | repo.clone-url | 206 | repo.clone-url |
206 | A list of space-separated urls which can be used to clone this repo. | 207 | A list of space-separated urls which can be used to clone this repo. |
207 | Default value: none. | 208 | Default value: none. |
208 | 209 | ||
209 | repo.defbranch | 210 | repo.defbranch |
210 | The name of the default branch for this repository. If no such branch | 211 | The name of the default branch for this repository. If no such branch |
211 | exists in the repository, the first branch name (when sorted) is used | 212 | exists in the repository, the first branch name (when sorted) is used |
212 | as default instead. Default value: "master". | 213 | as default instead. Default value: "master". |
213 | 214 | ||
214 | repo.desc | 215 | repo.desc |
215 | The value to show as repository description. Default value: none. | 216 | The value to show as repository description. Default value: none. |
216 | 217 | ||
217 | repo.enable-log-filecount | 218 | repo.enable-log-filecount |
218 | A flag which can be used to disable the global setting | 219 | A flag which can be used to disable the global setting |
219 | `enable-log-filecount'. Default value: none. | 220 | `enable-log-filecount'. Default value: none. |
220 | 221 | ||
221 | repo.enable-log-linecount | 222 | repo.enable-log-linecount |
222 | A flag which can be used to disable the global setting | 223 | A flag which can be used to disable the global setting |
223 | `enable-log-linecount'. Default value: none. | 224 | `enable-log-linecount'. Default value: none. |
224 | 225 | ||
225 | repo.enable-stats | 226 | repo.max-stats |
226 | A flag which can be used to disable the global setting | 227 | Override the default maximum statistics period. Valid values are equal |
227 | `enable-stats'. Default value: none. | 228 | to the values specified for the global "max-stats" setting. Default |
229 | value: none. | ||
228 | 230 | ||
229 | repo.name | 231 | repo.name |
230 | The value to show as repository name. Default value: <repo.url>. | 232 | The value to show as repository name. Default value: <repo.url>. |
231 | 233 | ||
232 | repo.owner | 234 | repo.owner |
233 | A value used to identify the owner of the repository. Default value: | 235 | A value used to identify the owner of the repository. Default value: |
234 | none. | 236 | none. |
235 | 237 | ||
236 | repo.path | 238 | repo.path |
237 | An absolute path to the repository directory. For non-bare repositories | 239 | An absolute path to the repository directory. For non-bare repositories |
238 | this is the .git-directory. Default value: none. | 240 | this is the .git-directory. Default value: none. |
239 | 241 | ||
240 | repo.readme | 242 | repo.readme |
241 | A path (relative to <repo.path>) which specifies a file to include | 243 | A path (relative to <repo.path>) which specifies a file to include |
242 | verbatim as the "About" page for this repo. Default value: none. | 244 | verbatim as the "About" page for this repo. Default value: none. |
243 | 245 | ||
244 | repo.snapshots | 246 | repo.snapshots |
245 | A mask of allowed snapshot-formats for this repo, restricted by the | 247 | A mask of allowed snapshot-formats for this repo, restricted by the |
246 | "snapshots" global setting. Default value: <snapshots>. | 248 | "snapshots" global setting. Default value: <snapshots>. |
247 | 249 | ||
248 | repo.url | 250 | repo.url |
249 | The relative url used to access the repository. This must be the first | 251 | The relative url used to access the repository. This must be the first |
250 | setting specified for each repo. Default value: none. | 252 | setting specified for each repo. Default value: none. |
251 | 253 | ||
252 | 254 | ||
253 | EXAMPLE CGITRC FILE | 255 | EXAMPLE CGITRC FILE |
254 | ------------------- | 256 | ------------------- |
255 | 257 | ||
256 | # Enable caching of up to 1000 output entriess | 258 | # Enable caching of up to 1000 output entriess |
257 | cache-size=1000 | 259 | cache-size=1000 |
258 | 260 | ||
259 | 261 | ||
260 | # Specify some default clone prefixes | 262 | # Specify some default clone prefixes |
261 | clone-prefix=git://foobar.com ssh://foobar.com/pub/git http://foobar.com/git | 263 | clone-prefix=git://foobar.com ssh://foobar.com/pub/git http://foobar.com/git |
262 | 264 | ||
263 | # Specify the css url | 265 | # Specify the css url |
264 | css=/css/cgit.css | 266 | css=/css/cgit.css |
265 | 267 | ||
266 | 268 | ||
267 | # Show extra links for each repository on the index page | 269 | # Show extra links for each repository on the index page |
268 | enable-index-links=1 | 270 | enable-index-links=1 |
269 | 271 | ||
270 | 272 | ||
271 | # Show number of affected files per commit on the log pages | 273 | # Show number of affected files per commit on the log pages |
272 | enable-log-filecount=1 | 274 | enable-log-filecount=1 |
273 | 275 | ||
274 | 276 | ||
275 | # Show number of added/removed lines per commit on the log pages | 277 | # Show number of added/removed lines per commit on the log pages |
276 | enable-log-linecount=1 | 278 | enable-log-linecount=1 |
277 | 279 | ||
278 | 280 | ||
279 | # Add a cgit favicon | 281 | # Add a cgit favicon |
280 | favicon=/favicon.ico | 282 | favicon=/favicon.ico |
281 | 283 | ||
282 | 284 | ||
283 | # Use a custom logo | 285 | # Use a custom logo |
284 | logo=/img/mylogo.png | 286 | logo=/img/mylogo.png |
285 | 287 | ||
286 | 288 | ||
289 | # Enable statistics per week, month and quarter | ||
290 | max-stats=quarter | ||
291 | |||
292 | |||
287 | # Set the title and heading of the repository index page | 293 | # Set the title and heading of the repository index page |
288 | root-title=foobar.com git repositories | 294 | root-title=foobar.com git repositories |
289 | 295 | ||
290 | 296 | ||
291 | # Set a subheading for the repository index page | 297 | # Set a subheading for the repository index page |
292 | root-desc=tracking the foobar development | 298 | root-desc=tracking the foobar development |
293 | 299 | ||
294 | 300 | ||
295 | # Include some more info about foobar.com on the index page | 301 | # Include some more info about foobar.com on the index page |
296 | root-readme=/var/www/htdocs/about.html | 302 | root-readme=/var/www/htdocs/about.html |
297 | 303 | ||
298 | 304 | ||
299 | # Allow download of tar.gz, tar.bz and zip-files | 305 | # Allow download of tar.gz, tar.bz and zip-files |
300 | snapshots=tar.gz tar.bz zip | 306 | snapshots=tar.gz tar.bz zip |
301 | 307 | ||
302 | 308 | ||
303 | ## | 309 | ## |
304 | ## List of repositories. | 310 | ## List of repositories. |
305 | ## PS: Any repositories listed when repo.group is unset will not be | 311 | ## PS: Any repositories listed when repo.group is unset will not be |
306 | ## displayed under a group heading | 312 | ## displayed under a group heading |
307 | ## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') | 313 | ## PPS: This list could be kept in a different file (e.g. '/etc/cgitrepos') |
308 | ## and included like this: | 314 | ## and included like this: |
309 | ## include=/etc/cgitrepos | 315 | ## include=/etc/cgitrepos |
310 | ## | 316 | ## |
311 | 317 | ||
312 | 318 | ||
313 | repo.url=foo | 319 | repo.url=foo |
314 | repo.path=/pub/git/foo.git | 320 | repo.path=/pub/git/foo.git |
315 | repo.desc=the master foo repository | 321 | repo.desc=the master foo repository |
316 | repo.owner=fooman@foobar.com | 322 | repo.owner=fooman@foobar.com |
317 | repo.readme=info/web/about.html | 323 | repo.readme=info/web/about.html |
318 | 324 | ||
319 | 325 | ||
320 | repo.url=bar | 326 | repo.url=bar |
321 | repo.path=/pub/git/bar.git | 327 | repo.path=/pub/git/bar.git |
322 | repo.desc=the bars for your foo | 328 | repo.desc=the bars for your foo |
323 | repo.owner=barman@foobar.com | 329 | repo.owner=barman@foobar.com |
324 | repo.readme=info/web/about.html | 330 | repo.readme=info/web/about.html |
325 | 331 | ||
326 | 332 | ||
327 | # The next repositories will be displayed under the 'extras' heading | 333 | # The next repositories will be displayed under the 'extras' heading |
328 | repo.group=extras | 334 | repo.group=extras |
329 | 335 | ||
330 | 336 | ||
331 | repo.url=baz | 337 | repo.url=baz |
332 | repo.path=/pub/git/baz.git | 338 | repo.path=/pub/git/baz.git |
333 | repo.desc=a set of extensions for bar users | 339 | repo.desc=a set of extensions for bar users |
334 | 340 | ||
335 | repo.url=wiz | 341 | repo.url=wiz |
336 | repo.path=/pub/git/wiz.git | 342 | repo.path=/pub/git/wiz.git |
337 | repo.desc=the wizard of foo | 343 | repo.desc=the wizard of foo |
338 | 344 | ||
339 | 345 | ||
340 | # Add some mirrored repositories | 346 | # Add some mirrored repositories |
341 | repo.group=mirrors | 347 | repo.group=mirrors |
342 | 348 | ||
343 | 349 | ||
344 | repo.url=git | 350 | repo.url=git |
345 | repo.path=/pub/git/git.git | 351 | repo.path=/pub/git/git.git |
346 | repo.desc=the dscm | 352 | repo.desc=the dscm |
347 | 353 | ||
348 | 354 | ||
349 | repo.url=linux | 355 | repo.url=linux |
350 | repo.path=/pub/git/linux.git | 356 | repo.path=/pub/git/linux.git |
351 | repo.desc=the kernel | 357 | repo.desc=the kernel |
352 | 358 | ||
353 | # Disable adhoc downloads of this repo | 359 | # Disable adhoc downloads of this repo |
354 | repo.snapshots=0 | 360 | repo.snapshots=0 |
355 | 361 | ||
356 | # Disable line-counts for this repo | 362 | # Disable line-counts for this repo |
357 | repo.enable-log-linecount=0 | 363 | repo.enable-log-linecount=0 |
358 | 364 | ||
365 | # Restrict the max statistics period for this repo | ||
366 | repo.max-stats=month | ||
367 | |||
359 | 368 | ||
360 | BUGS | 369 | BUGS |
361 | ---- | 370 | ---- |
362 | Comments currently cannot appear on the same line as a setting; the comment | 371 | Comments currently cannot appear on the same line as a setting; the comment |
363 | will be included as part of the value. E.g. this line: | 372 | will be included as part of the value. E.g. this line: |
364 | 373 | ||
365 | robots=index # allow indexing | 374 | robots=index # allow indexing |
366 | 375 | ||
367 | will generate the following html element: | 376 | will generate the following html element: |
368 | 377 | ||
369 | <meta name='robots' content='index # allow indexing'/> | 378 | <meta name='robots' content='index # allow indexing'/> |
370 | 379 | ||
371 | 380 | ||
372 | 381 | ||
373 | AUTHOR | 382 | AUTHOR |
374 | ------ | 383 | ------ |
375 | Lars Hjemli <hjemli@gmail.com> | 384 | Lars Hjemli <hjemli@gmail.com> |
@@ -1,175 +1,172 @@ | |||
1 | /* cmd.c: the cgit command dispatcher | 1 | /* cmd.c: the cgit command dispatcher |
2 | * | 2 | * |
3 | * Copyright (C) 2008 Lars Hjemli | 3 | * Copyright (C) 2008 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
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 "cmd.h" | 10 | #include "cmd.h" |
11 | #include "cache.h" | 11 | #include "cache.h" |
12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
13 | #include "ui-atom.h" | 13 | #include "ui-atom.h" |
14 | #include "ui-blob.h" | 14 | #include "ui-blob.h" |
15 | #include "ui-clone.h" | 15 | #include "ui-clone.h" |
16 | #include "ui-commit.h" | 16 | #include "ui-commit.h" |
17 | #include "ui-diff.h" | 17 | #include "ui-diff.h" |
18 | #include "ui-log.h" | 18 | #include "ui-log.h" |
19 | #include "ui-patch.h" | 19 | #include "ui-patch.h" |
20 | #include "ui-plain.h" | 20 | #include "ui-plain.h" |
21 | #include "ui-refs.h" | 21 | #include "ui-refs.h" |
22 | #include "ui-repolist.h" | 22 | #include "ui-repolist.h" |
23 | #include "ui-snapshot.h" | 23 | #include "ui-snapshot.h" |
24 | #include "ui-stats.h" | 24 | #include "ui-stats.h" |
25 | #include "ui-summary.h" | 25 | #include "ui-summary.h" |
26 | #include "ui-tag.h" | 26 | #include "ui-tag.h" |
27 | #include "ui-tree.h" | 27 | #include "ui-tree.h" |
28 | 28 | ||
29 | static void HEAD_fn(struct cgit_context *ctx) | 29 | static void HEAD_fn(struct cgit_context *ctx) |
30 | { | 30 | { |
31 | cgit_clone_head(ctx); | 31 | cgit_clone_head(ctx); |
32 | } | 32 | } |
33 | 33 | ||
34 | static void atom_fn(struct cgit_context *ctx) | 34 | static void atom_fn(struct cgit_context *ctx) |
35 | { | 35 | { |
36 | cgit_print_atom(ctx->qry.head, ctx->qry.path, 10); | 36 | cgit_print_atom(ctx->qry.head, ctx->qry.path, 10); |
37 | } | 37 | } |
38 | 38 | ||
39 | static void about_fn(struct cgit_context *ctx) | 39 | static void about_fn(struct cgit_context *ctx) |
40 | { | 40 | { |
41 | if (ctx->repo) | 41 | if (ctx->repo) |
42 | cgit_print_repo_readme(); | 42 | cgit_print_repo_readme(); |
43 | else | 43 | else |
44 | cgit_print_site_readme(); | 44 | cgit_print_site_readme(); |
45 | } | 45 | } |
46 | 46 | ||
47 | static void blob_fn(struct cgit_context *ctx) | 47 | static void blob_fn(struct cgit_context *ctx) |
48 | { | 48 | { |
49 | cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head); | 49 | cgit_print_blob(ctx->qry.sha1, ctx->qry.path, ctx->qry.head); |
50 | } | 50 | } |
51 | 51 | ||
52 | static void commit_fn(struct cgit_context *ctx) | 52 | static void commit_fn(struct cgit_context *ctx) |
53 | { | 53 | { |
54 | cgit_print_commit(ctx->qry.sha1); | 54 | cgit_print_commit(ctx->qry.sha1); |
55 | } | 55 | } |
56 | 56 | ||
57 | static void diff_fn(struct cgit_context *ctx) | 57 | static void diff_fn(struct cgit_context *ctx) |
58 | { | 58 | { |
59 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); | 59 | cgit_print_diff(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); |
60 | } | 60 | } |
61 | 61 | ||
62 | static void info_fn(struct cgit_context *ctx) | 62 | static void info_fn(struct cgit_context *ctx) |
63 | { | 63 | { |
64 | cgit_clone_info(ctx); | 64 | cgit_clone_info(ctx); |
65 | } | 65 | } |
66 | 66 | ||
67 | static void log_fn(struct cgit_context *ctx) | 67 | static void log_fn(struct cgit_context *ctx) |
68 | { | 68 | { |
69 | cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, | 69 | cgit_print_log(ctx->qry.sha1, ctx->qry.ofs, ctx->cfg.max_commit_count, |
70 | ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1); | 70 | ctx->qry.grep, ctx->qry.search, ctx->qry.path, 1); |
71 | } | 71 | } |
72 | 72 | ||
73 | static void ls_cache_fn(struct cgit_context *ctx) | 73 | static void ls_cache_fn(struct cgit_context *ctx) |
74 | { | 74 | { |
75 | ctx->page.mimetype = "text/plain"; | 75 | ctx->page.mimetype = "text/plain"; |
76 | ctx->page.filename = "ls-cache.txt"; | 76 | ctx->page.filename = "ls-cache.txt"; |
77 | cgit_print_http_headers(ctx); | 77 | cgit_print_http_headers(ctx); |
78 | cache_ls(ctx->cfg.cache_root); | 78 | cache_ls(ctx->cfg.cache_root); |
79 | } | 79 | } |
80 | 80 | ||
81 | static void objects_fn(struct cgit_context *ctx) | 81 | static void objects_fn(struct cgit_context *ctx) |
82 | { | 82 | { |
83 | cgit_clone_objects(ctx); | 83 | cgit_clone_objects(ctx); |
84 | } | 84 | } |
85 | 85 | ||
86 | static void repolist_fn(struct cgit_context *ctx) | 86 | static void repolist_fn(struct cgit_context *ctx) |
87 | { | 87 | { |
88 | cgit_print_repolist(); | 88 | cgit_print_repolist(); |
89 | } | 89 | } |
90 | 90 | ||
91 | static void patch_fn(struct cgit_context *ctx) | 91 | static void patch_fn(struct cgit_context *ctx) |
92 | { | 92 | { |
93 | cgit_print_patch(ctx->qry.sha1); | 93 | cgit_print_patch(ctx->qry.sha1); |
94 | } | 94 | } |
95 | 95 | ||
96 | static void plain_fn(struct cgit_context *ctx) | 96 | static void plain_fn(struct cgit_context *ctx) |
97 | { | 97 | { |
98 | cgit_print_plain(ctx); | 98 | cgit_print_plain(ctx); |
99 | } | 99 | } |
100 | 100 | ||
101 | static void refs_fn(struct cgit_context *ctx) | 101 | static void refs_fn(struct cgit_context *ctx) |
102 | { | 102 | { |
103 | cgit_print_refs(); | 103 | cgit_print_refs(); |
104 | } | 104 | } |
105 | 105 | ||
106 | static void snapshot_fn(struct cgit_context *ctx) | 106 | static void snapshot_fn(struct cgit_context *ctx) |
107 | { | 107 | { |
108 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, | 108 | cgit_print_snapshot(ctx->qry.head, ctx->qry.sha1, |
109 | cgit_repobasename(ctx->repo->url), ctx->qry.path, | 109 | cgit_repobasename(ctx->repo->url), ctx->qry.path, |
110 | ctx->repo->snapshots, ctx->qry.nohead); | 110 | ctx->repo->snapshots, ctx->qry.nohead); |
111 | } | 111 | } |
112 | 112 | ||
113 | static void stats_fn(struct cgit_context *ctx) | 113 | static void stats_fn(struct cgit_context *ctx) |
114 | { | 114 | { |
115 | if (ctx->repo->enable_stats) | 115 | cgit_show_stats(ctx); |
116 | cgit_show_stats(ctx); | ||
117 | else | ||
118 | cgit_print_error("Stats disabled for this repo"); | ||
119 | } | 116 | } |
120 | 117 | ||
121 | static void summary_fn(struct cgit_context *ctx) | 118 | static void summary_fn(struct cgit_context *ctx) |
122 | { | 119 | { |
123 | cgit_print_summary(); | 120 | cgit_print_summary(); |
124 | } | 121 | } |
125 | 122 | ||
126 | static void tag_fn(struct cgit_context *ctx) | 123 | static void tag_fn(struct cgit_context *ctx) |
127 | { | 124 | { |
128 | cgit_print_tag(ctx->qry.sha1); | 125 | cgit_print_tag(ctx->qry.sha1); |
129 | } | 126 | } |
130 | 127 | ||
131 | static void tree_fn(struct cgit_context *ctx) | 128 | static void tree_fn(struct cgit_context *ctx) |
132 | { | 129 | { |
133 | cgit_print_tree(ctx->qry.sha1, ctx->qry.path); | 130 | cgit_print_tree(ctx->qry.sha1, ctx->qry.path); |
134 | } | 131 | } |
135 | 132 | ||
136 | #define def_cmd(name, want_repo, want_layout) \ | 133 | #define def_cmd(name, want_repo, want_layout) \ |
137 | {#name, name##_fn, want_repo, want_layout} | 134 | {#name, name##_fn, want_repo, want_layout} |
138 | 135 | ||
139 | struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) | 136 | struct cgit_cmd *cgit_get_cmd(struct cgit_context *ctx) |
140 | { | 137 | { |
141 | static struct cgit_cmd cmds[] = { | 138 | static struct cgit_cmd cmds[] = { |
142 | def_cmd(HEAD, 1, 0), | 139 | def_cmd(HEAD, 1, 0), |
143 | def_cmd(atom, 1, 0), | 140 | def_cmd(atom, 1, 0), |
144 | def_cmd(about, 0, 1), | 141 | def_cmd(about, 0, 1), |
145 | def_cmd(blob, 1, 0), | 142 | def_cmd(blob, 1, 0), |
146 | def_cmd(commit, 1, 1), | 143 | def_cmd(commit, 1, 1), |
147 | def_cmd(diff, 1, 1), | 144 | def_cmd(diff, 1, 1), |
148 | def_cmd(info, 1, 0), | 145 | def_cmd(info, 1, 0), |
149 | def_cmd(log, 1, 1), | 146 | def_cmd(log, 1, 1), |
150 | def_cmd(ls_cache, 0, 0), | 147 | def_cmd(ls_cache, 0, 0), |
151 | def_cmd(objects, 1, 0), | 148 | def_cmd(objects, 1, 0), |
152 | def_cmd(patch, 1, 0), | 149 | def_cmd(patch, 1, 0), |
153 | def_cmd(plain, 1, 0), | 150 | def_cmd(plain, 1, 0), |
154 | def_cmd(refs, 1, 1), | 151 | def_cmd(refs, 1, 1), |
155 | def_cmd(repolist, 0, 0), | 152 | def_cmd(repolist, 0, 0), |
156 | def_cmd(snapshot, 1, 0), | 153 | def_cmd(snapshot, 1, 0), |
157 | def_cmd(stats, 1, 1), | 154 | def_cmd(stats, 1, 1), |
158 | def_cmd(summary, 1, 1), | 155 | def_cmd(summary, 1, 1), |
159 | def_cmd(tag, 1, 1), | 156 | def_cmd(tag, 1, 1), |
160 | def_cmd(tree, 1, 1), | 157 | def_cmd(tree, 1, 1), |
161 | }; | 158 | }; |
162 | int i; | 159 | int i; |
163 | 160 | ||
164 | if (ctx->qry.page == NULL) { | 161 | if (ctx->qry.page == NULL) { |
165 | if (ctx->repo) | 162 | if (ctx->repo) |
166 | ctx->qry.page = "summary"; | 163 | ctx->qry.page = "summary"; |
167 | else | 164 | else |
168 | ctx->qry.page = "repolist"; | 165 | ctx->qry.page = "repolist"; |
169 | } | 166 | } |
170 | 167 | ||
171 | for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) | 168 | for(i = 0; i < sizeof(cmds)/sizeof(*cmds); i++) |
172 | if (!strcmp(ctx->qry.page, cmds[i].name)) | 169 | if (!strcmp(ctx->qry.page, cmds[i].name)) |
173 | return &cmds[i]; | 170 | return &cmds[i]; |
174 | return NULL; | 171 | return NULL; |
175 | } | 172 | } |
@@ -1,253 +1,253 @@ | |||
1 | /* shared.c: global vars + some callback functions | 1 | /* shared.c: global vars + some callback functions |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
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 | 10 | ||
11 | struct cgit_repolist cgit_repolist; | 11 | struct cgit_repolist cgit_repolist; |
12 | struct cgit_context ctx; | 12 | struct cgit_context ctx; |
13 | int cgit_cmd; | 13 | int cgit_cmd; |
14 | 14 | ||
15 | int chk_zero(int result, char *msg) | 15 | int chk_zero(int result, char *msg) |
16 | { | 16 | { |
17 | if (result != 0) | 17 | if (result != 0) |
18 | die("%s: %s", msg, strerror(errno)); | 18 | die("%s: %s", msg, strerror(errno)); |
19 | return result; | 19 | return result; |
20 | } | 20 | } |
21 | 21 | ||
22 | int chk_positive(int result, char *msg) | 22 | int chk_positive(int result, char *msg) |
23 | { | 23 | { |
24 | if (result <= 0) | 24 | if (result <= 0) |
25 | die("%s: %s", msg, strerror(errno)); | 25 | die("%s: %s", msg, strerror(errno)); |
26 | return result; | 26 | return result; |
27 | } | 27 | } |
28 | 28 | ||
29 | int chk_non_negative(int result, char *msg) | 29 | int chk_non_negative(int result, char *msg) |
30 | { | 30 | { |
31 | if (result < 0) | 31 | if (result < 0) |
32 | die("%s: %s",msg, strerror(errno)); | 32 | die("%s: %s",msg, strerror(errno)); |
33 | return result; | 33 | return result; |
34 | } | 34 | } |
35 | 35 | ||
36 | struct cgit_repo *cgit_add_repo(const char *url) | 36 | struct cgit_repo *cgit_add_repo(const char *url) |
37 | { | 37 | { |
38 | struct cgit_repo *ret; | 38 | struct cgit_repo *ret; |
39 | 39 | ||
40 | if (++cgit_repolist.count > cgit_repolist.length) { | 40 | if (++cgit_repolist.count > cgit_repolist.length) { |
41 | if (cgit_repolist.length == 0) | 41 | if (cgit_repolist.length == 0) |
42 | cgit_repolist.length = 8; | 42 | cgit_repolist.length = 8; |
43 | else | 43 | else |
44 | cgit_repolist.length *= 2; | 44 | cgit_repolist.length *= 2; |
45 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, | 45 | cgit_repolist.repos = xrealloc(cgit_repolist.repos, |
46 | cgit_repolist.length * | 46 | cgit_repolist.length * |
47 | sizeof(struct cgit_repo)); | 47 | sizeof(struct cgit_repo)); |
48 | } | 48 | } |
49 | 49 | ||
50 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; | 50 | ret = &cgit_repolist.repos[cgit_repolist.count-1]; |
51 | ret->url = trim_end(url, '/'); | 51 | ret->url = trim_end(url, '/'); |
52 | ret->name = ret->url; | 52 | ret->name = ret->url; |
53 | ret->path = NULL; | 53 | ret->path = NULL; |
54 | ret->desc = "[no description]"; | 54 | ret->desc = "[no description]"; |
55 | ret->owner = NULL; | 55 | ret->owner = NULL; |
56 | ret->group = ctx.cfg.repo_group; | 56 | ret->group = ctx.cfg.repo_group; |
57 | ret->defbranch = "master"; | 57 | ret->defbranch = "master"; |
58 | ret->snapshots = ctx.cfg.snapshots; | 58 | ret->snapshots = ctx.cfg.snapshots; |
59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; | 59 | ret->enable_log_filecount = ctx.cfg.enable_log_filecount; |
60 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; | 60 | ret->enable_log_linecount = ctx.cfg.enable_log_linecount; |
61 | ret->enable_stats = ctx.cfg.enable_stats; | 61 | ret->max_stats = ctx.cfg.max_stats; |
62 | ret->module_link = ctx.cfg.module_link; | 62 | ret->module_link = ctx.cfg.module_link; |
63 | ret->readme = NULL; | 63 | ret->readme = NULL; |
64 | return ret; | 64 | return ret; |
65 | } | 65 | } |
66 | 66 | ||
67 | struct cgit_repo *cgit_get_repoinfo(const char *url) | 67 | struct cgit_repo *cgit_get_repoinfo(const char *url) |
68 | { | 68 | { |
69 | int i; | 69 | int i; |
70 | struct cgit_repo *repo; | 70 | struct cgit_repo *repo; |
71 | 71 | ||
72 | for (i=0; i<cgit_repolist.count; i++) { | 72 | for (i=0; i<cgit_repolist.count; i++) { |
73 | repo = &cgit_repolist.repos[i]; | 73 | repo = &cgit_repolist.repos[i]; |
74 | if (!strcmp(repo->url, url)) | 74 | if (!strcmp(repo->url, url)) |
75 | return repo; | 75 | return repo; |
76 | } | 76 | } |
77 | return NULL; | 77 | return NULL; |
78 | } | 78 | } |
79 | 79 | ||
80 | void *cgit_free_commitinfo(struct commitinfo *info) | 80 | void *cgit_free_commitinfo(struct commitinfo *info) |
81 | { | 81 | { |
82 | free(info->author); | 82 | free(info->author); |
83 | free(info->author_email); | 83 | free(info->author_email); |
84 | free(info->committer); | 84 | free(info->committer); |
85 | free(info->committer_email); | 85 | free(info->committer_email); |
86 | free(info->subject); | 86 | free(info->subject); |
87 | free(info->msg); | 87 | free(info->msg); |
88 | free(info->msg_encoding); | 88 | free(info->msg_encoding); |
89 | free(info); | 89 | free(info); |
90 | return NULL; | 90 | return NULL; |
91 | } | 91 | } |
92 | 92 | ||
93 | char *trim_end(const char *str, char c) | 93 | char *trim_end(const char *str, char c) |
94 | { | 94 | { |
95 | int len; | 95 | int len; |
96 | char *s, *t; | 96 | char *s, *t; |
97 | 97 | ||
98 | if (str == NULL) | 98 | if (str == NULL) |
99 | return NULL; | 99 | return NULL; |
100 | t = (char *)str; | 100 | t = (char *)str; |
101 | len = strlen(t); | 101 | len = strlen(t); |
102 | while(len > 0 && t[len - 1] == c) | 102 | while(len > 0 && t[len - 1] == c) |
103 | len--; | 103 | len--; |
104 | 104 | ||
105 | if (len == 0) | 105 | if (len == 0) |
106 | return NULL; | 106 | return NULL; |
107 | 107 | ||
108 | c = t[len]; | 108 | c = t[len]; |
109 | t[len] = '\0'; | 109 | t[len] = '\0'; |
110 | s = xstrdup(t); | 110 | s = xstrdup(t); |
111 | t[len] = c; | 111 | t[len] = c; |
112 | return s; | 112 | return s; |
113 | } | 113 | } |
114 | 114 | ||
115 | char *strlpart(char *txt, int maxlen) | 115 | char *strlpart(char *txt, int maxlen) |
116 | { | 116 | { |
117 | char *result; | 117 | char *result; |
118 | 118 | ||
119 | if (!txt) | 119 | if (!txt) |
120 | return txt; | 120 | return txt; |
121 | 121 | ||
122 | if (strlen(txt) <= maxlen) | 122 | if (strlen(txt) <= maxlen) |
123 | return txt; | 123 | return txt; |
124 | result = xmalloc(maxlen + 1); | 124 | result = xmalloc(maxlen + 1); |
125 | memcpy(result, txt, maxlen - 3); | 125 | memcpy(result, txt, maxlen - 3); |
126 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; | 126 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; |
127 | result[maxlen] = '\0'; | 127 | result[maxlen] = '\0'; |
128 | return result; | 128 | return result; |
129 | } | 129 | } |
130 | 130 | ||
131 | char *strrpart(char *txt, int maxlen) | 131 | char *strrpart(char *txt, int maxlen) |
132 | { | 132 | { |
133 | char *result; | 133 | char *result; |
134 | 134 | ||
135 | if (!txt) | 135 | if (!txt) |
136 | return txt; | 136 | return txt; |
137 | 137 | ||
138 | if (strlen(txt) <= maxlen) | 138 | if (strlen(txt) <= maxlen) |
139 | return txt; | 139 | return txt; |
140 | result = xmalloc(maxlen + 1); | 140 | result = xmalloc(maxlen + 1); |
141 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); | 141 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); |
142 | result[0] = result[1] = result[2] = '.'; | 142 | result[0] = result[1] = result[2] = '.'; |
143 | return result; | 143 | return result; |
144 | } | 144 | } |
145 | 145 | ||
146 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) | 146 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) |
147 | { | 147 | { |
148 | size_t size; | 148 | size_t size; |
149 | 149 | ||
150 | if (list->count >= list->alloc) { | 150 | if (list->count >= list->alloc) { |
151 | list->alloc += (list->alloc ? list->alloc : 4); | 151 | list->alloc += (list->alloc ? list->alloc : 4); |
152 | size = list->alloc * sizeof(struct refinfo *); | 152 | size = list->alloc * sizeof(struct refinfo *); |
153 | list->refs = xrealloc(list->refs, size); | 153 | list->refs = xrealloc(list->refs, size); |
154 | } | 154 | } |
155 | list->refs[list->count++] = ref; | 155 | list->refs[list->count++] = ref; |
156 | } | 156 | } |
157 | 157 | ||
158 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) | 158 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) |
159 | { | 159 | { |
160 | struct refinfo *ref; | 160 | struct refinfo *ref; |
161 | 161 | ||
162 | ref = xmalloc(sizeof (struct refinfo)); | 162 | ref = xmalloc(sizeof (struct refinfo)); |
163 | ref->refname = xstrdup(refname); | 163 | ref->refname = xstrdup(refname); |
164 | ref->object = parse_object(sha1); | 164 | ref->object = parse_object(sha1); |
165 | switch (ref->object->type) { | 165 | switch (ref->object->type) { |
166 | case OBJ_TAG: | 166 | case OBJ_TAG: |
167 | ref->tag = cgit_parse_tag((struct tag *)ref->object); | 167 | ref->tag = cgit_parse_tag((struct tag *)ref->object); |
168 | break; | 168 | break; |
169 | case OBJ_COMMIT: | 169 | case OBJ_COMMIT: |
170 | ref->commit = cgit_parse_commit((struct commit *)ref->object); | 170 | ref->commit = cgit_parse_commit((struct commit *)ref->object); |
171 | break; | 171 | break; |
172 | } | 172 | } |
173 | return ref; | 173 | return ref; |
174 | } | 174 | } |
175 | 175 | ||
176 | int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, | 176 | int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, |
177 | void *cb_data) | 177 | void *cb_data) |
178 | { | 178 | { |
179 | struct reflist *list = (struct reflist *)cb_data; | 179 | struct reflist *list = (struct reflist *)cb_data; |
180 | struct refinfo *info = cgit_mk_refinfo(refname, sha1); | 180 | struct refinfo *info = cgit_mk_refinfo(refname, sha1); |
181 | 181 | ||
182 | if (info) | 182 | if (info) |
183 | cgit_add_ref(list, info); | 183 | cgit_add_ref(list, info); |
184 | return 0; | 184 | return 0; |
185 | } | 185 | } |
186 | 186 | ||
187 | void cgit_diff_tree_cb(struct diff_queue_struct *q, | 187 | void cgit_diff_tree_cb(struct diff_queue_struct *q, |
188 | struct diff_options *options, void *data) | 188 | struct diff_options *options, void *data) |
189 | { | 189 | { |
190 | int i; | 190 | int i; |
191 | 191 | ||
192 | for (i = 0; i < q->nr; i++) { | 192 | for (i = 0; i < q->nr; i++) { |
193 | if (q->queue[i]->status == 'U') | 193 | if (q->queue[i]->status == 'U') |
194 | continue; | 194 | continue; |
195 | ((filepair_fn)data)(q->queue[i]); | 195 | ((filepair_fn)data)(q->queue[i]); |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) | 199 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) |
200 | { | 200 | { |
201 | enum object_type type; | 201 | enum object_type type; |
202 | 202 | ||
203 | if (is_null_sha1(sha1)) { | 203 | if (is_null_sha1(sha1)) { |
204 | file->ptr = (char *)""; | 204 | file->ptr = (char *)""; |
205 | file->size = 0; | 205 | file->size = 0; |
206 | } else { | 206 | } else { |
207 | file->ptr = read_sha1_file(sha1, &type, | 207 | file->ptr = read_sha1_file(sha1, &type, |
208 | (unsigned long *)&file->size); | 208 | (unsigned long *)&file->size); |
209 | } | 209 | } |
210 | return 1; | 210 | return 1; |
211 | } | 211 | } |
212 | 212 | ||
213 | /* | 213 | /* |
214 | * Receive diff-buffers from xdiff and concatenate them as | 214 | * Receive diff-buffers from xdiff and concatenate them as |
215 | * needed across multiple callbacks. | 215 | * needed across multiple callbacks. |
216 | * | 216 | * |
217 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), | 217 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), |
218 | * ripped from git and modified to use globals instead of | 218 | * ripped from git and modified to use globals instead of |
219 | * a special callback-struct. | 219 | * a special callback-struct. |
220 | */ | 220 | */ |
221 | char *diffbuf = NULL; | 221 | char *diffbuf = NULL; |
222 | int buflen = 0; | 222 | int buflen = 0; |
223 | 223 | ||
224 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) | 224 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) |
225 | { | 225 | { |
226 | int i; | 226 | int i; |
227 | 227 | ||
228 | for (i = 0; i < nbuf; i++) { | 228 | for (i = 0; i < nbuf; i++) { |
229 | if (mb[i].ptr[mb[i].size-1] != '\n') { | 229 | if (mb[i].ptr[mb[i].size-1] != '\n') { |
230 | /* Incomplete line */ | 230 | /* Incomplete line */ |
231 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); | 231 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
232 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); | 232 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
233 | buflen += mb[i].size; | 233 | buflen += mb[i].size; |
234 | continue; | 234 | continue; |
235 | } | 235 | } |
236 | 236 | ||
237 | /* we have a complete line */ | 237 | /* we have a complete line */ |
238 | if (!diffbuf) { | 238 | if (!diffbuf) { |
239 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); | 239 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); |
240 | continue; | 240 | continue; |
241 | } | 241 | } |
242 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); | 242 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
243 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); | 243 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
244 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); | 244 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); |
245 | free(diffbuf); | 245 | free(diffbuf); |
246 | diffbuf = NULL; | 246 | diffbuf = NULL; |
247 | buflen = 0; | 247 | buflen = 0; |
248 | } | 248 | } |
249 | if (diffbuf) { | 249 | if (diffbuf) { |
250 | ((linediff_fn)priv)(diffbuf, buflen); | 250 | ((linediff_fn)priv)(diffbuf, buflen); |
251 | free(diffbuf); | 251 | free(diffbuf); |
252 | diffbuf = NULL; | 252 | diffbuf = NULL; |
253 | buflen = 0; | 253 | buflen = 0; |
diff --git a/ui-shared.c b/ui-shared.c index 0e688a0..97b9d46 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -452,266 +452,266 @@ void cgit_print_http_headers(struct cgit_context *ctx) | |||
452 | if (ctx->page.filename) | 452 | if (ctx->page.filename) |
453 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", | 453 | htmlf("Content-Disposition: inline; filename=\"%s\"\n", |
454 | ctx->page.filename); | 454 | ctx->page.filename); |
455 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); | 455 | htmlf("Last-Modified: %s\n", http_date(ctx->page.modified)); |
456 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); | 456 | htmlf("Expires: %s\n", http_date(ctx->page.expires)); |
457 | html("\n"); | 457 | html("\n"); |
458 | } | 458 | } |
459 | 459 | ||
460 | void cgit_print_docstart(struct cgit_context *ctx) | 460 | void cgit_print_docstart(struct cgit_context *ctx) |
461 | { | 461 | { |
462 | char *host = cgit_hosturl(); | 462 | char *host = cgit_hosturl(); |
463 | html(cgit_doctype); | 463 | html(cgit_doctype); |
464 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); | 464 | html("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>\n"); |
465 | html("<head>\n"); | 465 | html("<head>\n"); |
466 | html("<title>"); | 466 | html("<title>"); |
467 | html_txt(ctx->page.title); | 467 | html_txt(ctx->page.title); |
468 | html("</title>\n"); | 468 | html("</title>\n"); |
469 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); | 469 | htmlf("<meta name='generator' content='cgit %s'/>\n", cgit_version); |
470 | if (ctx->cfg.robots && *ctx->cfg.robots) | 470 | if (ctx->cfg.robots && *ctx->cfg.robots) |
471 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); | 471 | htmlf("<meta name='robots' content='%s'/>\n", ctx->cfg.robots); |
472 | html("<link rel='stylesheet' type='text/css' href='"); | 472 | html("<link rel='stylesheet' type='text/css' href='"); |
473 | html_attr(ctx->cfg.css); | 473 | html_attr(ctx->cfg.css); |
474 | html("'/>\n"); | 474 | html("'/>\n"); |
475 | if (ctx->cfg.favicon) { | 475 | if (ctx->cfg.favicon) { |
476 | html("<link rel='shortcut icon' href='"); | 476 | html("<link rel='shortcut icon' href='"); |
477 | html_attr(ctx->cfg.favicon); | 477 | html_attr(ctx->cfg.favicon); |
478 | html("'/>\n"); | 478 | html("'/>\n"); |
479 | } | 479 | } |
480 | if (host && ctx->repo) { | 480 | if (host && ctx->repo) { |
481 | html("<link rel='alternate' title='Atom feed' href='http://"); | 481 | html("<link rel='alternate' title='Atom feed' href='http://"); |
482 | html_attr(cgit_hosturl()); | 482 | html_attr(cgit_hosturl()); |
483 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, | 483 | html_attr(cgit_fileurl(ctx->repo->url, "atom", ctx->qry.path, |
484 | fmt("h=%s", ctx->qry.head))); | 484 | fmt("h=%s", ctx->qry.head))); |
485 | html("' type='application/atom+xml'/>"); | 485 | html("' type='application/atom+xml'/>"); |
486 | } | 486 | } |
487 | html("</head>\n"); | 487 | html("</head>\n"); |
488 | html("<body>\n"); | 488 | html("<body>\n"); |
489 | } | 489 | } |
490 | 490 | ||
491 | void cgit_print_docend() | 491 | void cgit_print_docend() |
492 | { | 492 | { |
493 | html("</div>"); | 493 | html("</div>"); |
494 | if (ctx.cfg.footer) | 494 | if (ctx.cfg.footer) |
495 | html_include(ctx.cfg.footer); | 495 | html_include(ctx.cfg.footer); |
496 | else { | 496 | else { |
497 | htmlf("<div class='footer'>generated by cgit %s at ", | 497 | htmlf("<div class='footer'>generated by cgit %s at ", |
498 | cgit_version); | 498 | cgit_version); |
499 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); | 499 | cgit_print_date(time(NULL), FMT_LONGDATE, ctx.cfg.local_time); |
500 | html("</div>\n"); | 500 | html("</div>\n"); |
501 | } | 501 | } |
502 | html("</body>\n</html>\n"); | 502 | html("</body>\n</html>\n"); |
503 | } | 503 | } |
504 | 504 | ||
505 | int print_branch_option(const char *refname, const unsigned char *sha1, | 505 | int print_branch_option(const char *refname, const unsigned char *sha1, |
506 | int flags, void *cb_data) | 506 | int flags, void *cb_data) |
507 | { | 507 | { |
508 | char *name = (char *)refname; | 508 | char *name = (char *)refname; |
509 | html_option(name, name, ctx.qry.head); | 509 | html_option(name, name, ctx.qry.head); |
510 | return 0; | 510 | return 0; |
511 | } | 511 | } |
512 | 512 | ||
513 | int print_archive_ref(const char *refname, const unsigned char *sha1, | 513 | int print_archive_ref(const char *refname, const unsigned char *sha1, |
514 | int flags, void *cb_data) | 514 | int flags, void *cb_data) |
515 | { | 515 | { |
516 | struct tag *tag; | 516 | struct tag *tag; |
517 | struct taginfo *info; | 517 | struct taginfo *info; |
518 | struct object *obj; | 518 | struct object *obj; |
519 | char buf[256], *url; | 519 | char buf[256], *url; |
520 | unsigned char fileid[20]; | 520 | unsigned char fileid[20]; |
521 | int *header = (int *)cb_data; | 521 | int *header = (int *)cb_data; |
522 | 522 | ||
523 | if (prefixcmp(refname, "refs/archives")) | 523 | if (prefixcmp(refname, "refs/archives")) |
524 | return 0; | 524 | return 0; |
525 | strncpy(buf, refname+14, sizeof(buf)); | 525 | strncpy(buf, refname+14, sizeof(buf)); |
526 | obj = parse_object(sha1); | 526 | obj = parse_object(sha1); |
527 | if (!obj) | 527 | if (!obj) |
528 | return 1; | 528 | return 1; |
529 | if (obj->type == OBJ_TAG) { | 529 | if (obj->type == OBJ_TAG) { |
530 | tag = lookup_tag(sha1); | 530 | tag = lookup_tag(sha1); |
531 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) | 531 | if (!tag || parse_tag(tag) || !(info = cgit_parse_tag(tag))) |
532 | return 0; | 532 | return 0; |
533 | hashcpy(fileid, tag->tagged->sha1); | 533 | hashcpy(fileid, tag->tagged->sha1); |
534 | } else if (obj->type != OBJ_BLOB) { | 534 | } else if (obj->type != OBJ_BLOB) { |
535 | return 0; | 535 | return 0; |
536 | } else { | 536 | } else { |
537 | hashcpy(fileid, sha1); | 537 | hashcpy(fileid, sha1); |
538 | } | 538 | } |
539 | if (!*header) { | 539 | if (!*header) { |
540 | html("<h1>download</h1>\n"); | 540 | html("<h1>download</h1>\n"); |
541 | *header = 1; | 541 | *header = 1; |
542 | } | 542 | } |
543 | url = cgit_pageurl(ctx.qry.repo, "blob", | 543 | url = cgit_pageurl(ctx.qry.repo, "blob", |
544 | fmt("id=%s&path=%s", sha1_to_hex(fileid), | 544 | fmt("id=%s&path=%s", sha1_to_hex(fileid), |
545 | buf)); | 545 | buf)); |
546 | html_link_open(url, NULL, "menu"); | 546 | html_link_open(url, NULL, "menu"); |
547 | html_txt(strlpart(buf, 20)); | 547 | html_txt(strlpart(buf, 20)); |
548 | html_link_close(); | 548 | html_link_close(); |
549 | return 0; | 549 | return 0; |
550 | } | 550 | } |
551 | 551 | ||
552 | void add_hidden_formfields(int incl_head, int incl_search, char *page) | 552 | void add_hidden_formfields(int incl_head, int incl_search, char *page) |
553 | { | 553 | { |
554 | char *url; | 554 | char *url; |
555 | 555 | ||
556 | if (!ctx.cfg.virtual_root) { | 556 | if (!ctx.cfg.virtual_root) { |
557 | url = fmt("%s/%s", ctx.qry.repo, page); | 557 | url = fmt("%s/%s", ctx.qry.repo, page); |
558 | if (ctx.qry.path) | 558 | if (ctx.qry.path) |
559 | url = fmt("%s/%s", url, ctx.qry.path); | 559 | url = fmt("%s/%s", url, ctx.qry.path); |
560 | html_hidden("url", url); | 560 | html_hidden("url", url); |
561 | } | 561 | } |
562 | 562 | ||
563 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && | 563 | if (incl_head && ctx.qry.head && ctx.repo->defbranch && |
564 | strcmp(ctx.qry.head, ctx.repo->defbranch)) | 564 | strcmp(ctx.qry.head, ctx.repo->defbranch)) |
565 | html_hidden("h", ctx.qry.head); | 565 | html_hidden("h", ctx.qry.head); |
566 | 566 | ||
567 | if (ctx.qry.sha1) | 567 | if (ctx.qry.sha1) |
568 | html_hidden("id", ctx.qry.sha1); | 568 | html_hidden("id", ctx.qry.sha1); |
569 | if (ctx.qry.sha2) | 569 | if (ctx.qry.sha2) |
570 | html_hidden("id2", ctx.qry.sha2); | 570 | html_hidden("id2", ctx.qry.sha2); |
571 | 571 | ||
572 | if (incl_search) { | 572 | if (incl_search) { |
573 | if (ctx.qry.grep) | 573 | if (ctx.qry.grep) |
574 | html_hidden("qt", ctx.qry.grep); | 574 | html_hidden("qt", ctx.qry.grep); |
575 | if (ctx.qry.search) | 575 | if (ctx.qry.search) |
576 | html_hidden("q", ctx.qry.search); | 576 | html_hidden("q", ctx.qry.search); |
577 | } | 577 | } |
578 | } | 578 | } |
579 | 579 | ||
580 | char *hc(struct cgit_cmd *cmd, const char *page) | 580 | char *hc(struct cgit_cmd *cmd, const char *page) |
581 | { | 581 | { |
582 | return (strcmp(cmd->name, page) ? NULL : "active"); | 582 | return (strcmp(cmd->name, page) ? NULL : "active"); |
583 | } | 583 | } |
584 | 584 | ||
585 | void cgit_print_pageheader(struct cgit_context *ctx) | 585 | void cgit_print_pageheader(struct cgit_context *ctx) |
586 | { | 586 | { |
587 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); | 587 | struct cgit_cmd *cmd = cgit_get_cmd(ctx); |
588 | 588 | ||
589 | html("<table id='header'>\n"); | 589 | html("<table id='header'>\n"); |
590 | html("<tr>\n"); | 590 | html("<tr>\n"); |
591 | html("<td class='logo' rowspan='2'><a href='"); | 591 | html("<td class='logo' rowspan='2'><a href='"); |
592 | if (ctx->cfg.logo_link) | 592 | if (ctx->cfg.logo_link) |
593 | html_attr(ctx->cfg.logo_link); | 593 | html_attr(ctx->cfg.logo_link); |
594 | else | 594 | else |
595 | html_attr(cgit_rooturl()); | 595 | html_attr(cgit_rooturl()); |
596 | html("'><img src='"); | 596 | html("'><img src='"); |
597 | html_attr(ctx->cfg.logo); | 597 | html_attr(ctx->cfg.logo); |
598 | html("' alt='cgit logo'/></a></td>\n"); | 598 | html("' alt='cgit logo'/></a></td>\n"); |
599 | 599 | ||
600 | html("<td class='main'>"); | 600 | html("<td class='main'>"); |
601 | if (ctx->repo) { | 601 | if (ctx->repo) { |
602 | cgit_index_link("index", NULL, NULL, NULL, 0); | 602 | cgit_index_link("index", NULL, NULL, NULL, 0); |
603 | html(" : "); | 603 | html(" : "); |
604 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); | 604 | cgit_summary_link(ctx->repo->name, ctx->repo->name, NULL, NULL); |
605 | html("</td><td class='form'>"); | 605 | html("</td><td class='form'>"); |
606 | html("<form method='get' action=''>\n"); | 606 | html("<form method='get' action=''>\n"); |
607 | add_hidden_formfields(0, 1, ctx->qry.page); | 607 | add_hidden_formfields(0, 1, ctx->qry.page); |
608 | html("<select name='h' onchange='this.form.submit();'>\n"); | 608 | html("<select name='h' onchange='this.form.submit();'>\n"); |
609 | for_each_branch_ref(print_branch_option, ctx->qry.head); | 609 | for_each_branch_ref(print_branch_option, ctx->qry.head); |
610 | html("</select> "); | 610 | html("</select> "); |
611 | html("<input type='submit' name='' value='switch'/>"); | 611 | html("<input type='submit' name='' value='switch'/>"); |
612 | html("</form>"); | 612 | html("</form>"); |
613 | } else | 613 | } else |
614 | html_txt(ctx->cfg.root_title); | 614 | html_txt(ctx->cfg.root_title); |
615 | html("</td></tr>\n"); | 615 | html("</td></tr>\n"); |
616 | 616 | ||
617 | html("<tr><td class='sub'>"); | 617 | html("<tr><td class='sub'>"); |
618 | if (ctx->repo) { | 618 | if (ctx->repo) { |
619 | html_txt(ctx->repo->desc); | 619 | html_txt(ctx->repo->desc); |
620 | html("</td><td class='sub right'>"); | 620 | html("</td><td class='sub right'>"); |
621 | html_txt(ctx->repo->owner); | 621 | html_txt(ctx->repo->owner); |
622 | } else { | 622 | } else { |
623 | if (ctx->cfg.root_desc) | 623 | if (ctx->cfg.root_desc) |
624 | html_txt(ctx->cfg.root_desc); | 624 | html_txt(ctx->cfg.root_desc); |
625 | else if (ctx->cfg.index_info) | 625 | else if (ctx->cfg.index_info) |
626 | html_include(ctx->cfg.index_info); | 626 | html_include(ctx->cfg.index_info); |
627 | } | 627 | } |
628 | html("</td></tr></table>\n"); | 628 | html("</td></tr></table>\n"); |
629 | 629 | ||
630 | html("<table class='tabs'><tr><td>\n"); | 630 | html("<table class='tabs'><tr><td>\n"); |
631 | if (ctx->repo) { | 631 | if (ctx->repo) { |
632 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), | 632 | cgit_summary_link("summary", NULL, hc(cmd, "summary"), |
633 | ctx->qry.head); | 633 | ctx->qry.head); |
634 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, | 634 | cgit_refs_link("refs", NULL, hc(cmd, "refs"), ctx->qry.head, |
635 | ctx->qry.sha1, NULL); | 635 | ctx->qry.sha1, NULL); |
636 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, | 636 | cgit_log_link("log", NULL, hc(cmd, "log"), ctx->qry.head, |
637 | NULL, NULL, 0, NULL, NULL); | 637 | NULL, NULL, 0, NULL, NULL); |
638 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, | 638 | cgit_tree_link("tree", NULL, hc(cmd, "tree"), ctx->qry.head, |
639 | ctx->qry.sha1, NULL); | 639 | ctx->qry.sha1, NULL); |
640 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), | 640 | cgit_commit_link("commit", NULL, hc(cmd, "commit"), |
641 | ctx->qry.head, ctx->qry.sha1); | 641 | ctx->qry.head, ctx->qry.sha1); |
642 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, | 642 | cgit_diff_link("diff", NULL, hc(cmd, "diff"), ctx->qry.head, |
643 | ctx->qry.sha1, ctx->qry.sha2, NULL); | 643 | ctx->qry.sha1, ctx->qry.sha2, NULL); |
644 | if (ctx->repo->enable_stats) | 644 | if (ctx->repo->max_stats) |
645 | reporevlink("stats", "stats", NULL, hc(cmd, "stats"), | 645 | reporevlink("stats", "stats", NULL, hc(cmd, "stats"), |
646 | ctx->qry.head, NULL, NULL); | 646 | ctx->qry.head, NULL, NULL); |
647 | if (ctx->repo->readme) | 647 | if (ctx->repo->readme) |
648 | reporevlink("about", "about", NULL, | 648 | reporevlink("about", "about", NULL, |
649 | hc(cmd, "about"), ctx->qry.head, NULL, | 649 | hc(cmd, "about"), ctx->qry.head, NULL, |
650 | NULL); | 650 | NULL); |
651 | html("</td><td class='form'>"); | 651 | html("</td><td class='form'>"); |
652 | html("<form class='right' method='get' action='"); | 652 | html("<form class='right' method='get' action='"); |
653 | if (ctx->cfg.virtual_root) | 653 | if (ctx->cfg.virtual_root) |
654 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", | 654 | html_url_path(cgit_fileurl(ctx->qry.repo, "log", |
655 | ctx->qry.path, NULL)); | 655 | ctx->qry.path, NULL)); |
656 | html("'>\n"); | 656 | html("'>\n"); |
657 | add_hidden_formfields(1, 0, "log"); | 657 | add_hidden_formfields(1, 0, "log"); |
658 | html("<select name='qt'>\n"); | 658 | html("<select name='qt'>\n"); |
659 | html_option("grep", "log msg", ctx->qry.grep); | 659 | html_option("grep", "log msg", ctx->qry.grep); |
660 | html_option("author", "author", ctx->qry.grep); | 660 | html_option("author", "author", ctx->qry.grep); |
661 | html_option("committer", "committer", ctx->qry.grep); | 661 | html_option("committer", "committer", ctx->qry.grep); |
662 | html("</select>\n"); | 662 | html("</select>\n"); |
663 | html("<input class='txt' type='text' size='10' name='q' value='"); | 663 | html("<input class='txt' type='text' size='10' name='q' value='"); |
664 | html_attr(ctx->qry.search); | 664 | html_attr(ctx->qry.search); |
665 | html("'/>\n"); | 665 | html("'/>\n"); |
666 | html("<input type='submit' value='search'/>\n"); | 666 | html("<input type='submit' value='search'/>\n"); |
667 | html("</form>\n"); | 667 | html("</form>\n"); |
668 | } else { | 668 | } else { |
669 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); | 669 | site_link(NULL, "index", NULL, hc(cmd, "repolist"), NULL, 0); |
670 | if (ctx->cfg.root_readme) | 670 | if (ctx->cfg.root_readme) |
671 | site_link("about", "about", NULL, hc(cmd, "about"), | 671 | site_link("about", "about", NULL, hc(cmd, "about"), |
672 | NULL, 0); | 672 | NULL, 0); |
673 | html("</td><td class='form'>"); | 673 | html("</td><td class='form'>"); |
674 | html("<form method='get' action='"); | 674 | html("<form method='get' action='"); |
675 | html_attr(cgit_rooturl()); | 675 | html_attr(cgit_rooturl()); |
676 | html("'>\n"); | 676 | html("'>\n"); |
677 | html("<input type='text' name='q' size='10' value='"); | 677 | html("<input type='text' name='q' size='10' value='"); |
678 | html_attr(ctx->qry.search); | 678 | html_attr(ctx->qry.search); |
679 | html("'/>\n"); | 679 | html("'/>\n"); |
680 | html("<input type='submit' value='search'/>\n"); | 680 | html("<input type='submit' value='search'/>\n"); |
681 | html("</form>"); | 681 | html("</form>"); |
682 | } | 682 | } |
683 | html("</td></tr></table>\n"); | 683 | html("</td></tr></table>\n"); |
684 | html("<div class='content'>"); | 684 | html("<div class='content'>"); |
685 | } | 685 | } |
686 | 686 | ||
687 | void cgit_print_filemode(unsigned short mode) | 687 | void cgit_print_filemode(unsigned short mode) |
688 | { | 688 | { |
689 | if (S_ISDIR(mode)) | 689 | if (S_ISDIR(mode)) |
690 | html("d"); | 690 | html("d"); |
691 | else if (S_ISLNK(mode)) | 691 | else if (S_ISLNK(mode)) |
692 | html("l"); | 692 | html("l"); |
693 | else if (S_ISGITLINK(mode)) | 693 | else if (S_ISGITLINK(mode)) |
694 | html("m"); | 694 | html("m"); |
695 | else | 695 | else |
696 | html("-"); | 696 | html("-"); |
697 | html_fileperm(mode >> 6); | 697 | html_fileperm(mode >> 6); |
698 | html_fileperm(mode >> 3); | 698 | html_fileperm(mode >> 3); |
699 | html_fileperm(mode); | 699 | html_fileperm(mode); |
700 | } | 700 | } |
701 | 701 | ||
702 | void cgit_print_snapshot_links(const char *repo, const char *head, | 702 | void cgit_print_snapshot_links(const char *repo, const char *head, |
703 | const char *hex, int snapshots) | 703 | const char *hex, int snapshots) |
704 | { | 704 | { |
705 | const struct cgit_snapshot_format* f; | 705 | const struct cgit_snapshot_format* f; |
706 | char *filename; | 706 | char *filename; |
707 | 707 | ||
708 | for (f = cgit_snapshot_formats; f->suffix; f++) { | 708 | for (f = cgit_snapshot_formats; f->suffix; f++) { |
709 | if (!(snapshots & f->bit)) | 709 | if (!(snapshots & f->bit)) |
710 | continue; | 710 | continue; |
711 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, | 711 | filename = fmt("%s-%s%s", cgit_repobasename(repo), hex, |
712 | f->suffix); | 712 | f->suffix); |
713 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, | 713 | cgit_snapshot_link(filename, NULL, NULL, (char *)head, |
714 | (char *)hex, filename); | 714 | (char *)hex, filename); |
715 | html("<br/>"); | 715 | html("<br/>"); |
716 | } | 716 | } |
717 | } | 717 | } |
@@ -1,392 +1,411 @@ | |||
1 | #include <string-list.h> | ||
2 | |||
1 | #include "cgit.h" | 3 | #include "cgit.h" |
2 | #include "html.h" | 4 | #include "html.h" |
3 | #include <string-list.h> | 5 | #include "ui-shared.h" |
6 | #include "ui-stats.h" | ||
4 | 7 | ||
5 | #define MONTHS 6 | 8 | #define MONTHS 6 |
6 | 9 | ||
7 | struct Period { | ||
8 | const char code; | ||
9 | const char *name; | ||
10 | int max_periods; | ||
11 | int count; | ||
12 | |||
13 | /* Convert a tm value to the first day in the period */ | ||
14 | void (*trunc)(struct tm *tm); | ||
15 | |||
16 | /* Update tm value to start of next/previous period */ | ||
17 | void (*dec)(struct tm *tm); | ||
18 | void (*inc)(struct tm *tm); | ||
19 | |||
20 | /* Pretty-print a tm value */ | ||
21 | char *(*pretty)(struct tm *tm); | ||
22 | }; | ||
23 | |||
24 | struct authorstat { | 10 | struct authorstat { |
25 | long total; | 11 | long total; |
26 | struct string_list list; | 12 | struct string_list list; |
27 | }; | 13 | }; |
28 | 14 | ||
29 | #define DAY_SECS (60 * 60 * 24) | 15 | #define DAY_SECS (60 * 60 * 24) |
30 | #define WEEK_SECS (DAY_SECS * 7) | 16 | #define WEEK_SECS (DAY_SECS * 7) |
31 | 17 | ||
32 | static void trunc_week(struct tm *tm) | 18 | static void trunc_week(struct tm *tm) |
33 | { | 19 | { |
34 | time_t t = timegm(tm); | 20 | time_t t = timegm(tm); |
35 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; | 21 | t -= ((tm->tm_wday + 6) % 7) * DAY_SECS; |
36 | gmtime_r(&t, tm); | 22 | gmtime_r(&t, tm); |
37 | } | 23 | } |
38 | 24 | ||
39 | static void dec_week(struct tm *tm) | 25 | static void dec_week(struct tm *tm) |
40 | { | 26 | { |
41 | time_t t = timegm(tm); | 27 | time_t t = timegm(tm); |
42 | t -= WEEK_SECS; | 28 | t -= WEEK_SECS; |
43 | gmtime_r(&t, tm); | 29 | gmtime_r(&t, tm); |
44 | } | 30 | } |
45 | 31 | ||
46 | static void inc_week(struct tm *tm) | 32 | static void inc_week(struct tm *tm) |
47 | { | 33 | { |
48 | time_t t = timegm(tm); | 34 | time_t t = timegm(tm); |
49 | t += WEEK_SECS; | 35 | t += WEEK_SECS; |
50 | gmtime_r(&t, tm); | 36 | gmtime_r(&t, tm); |
51 | } | 37 | } |
52 | 38 | ||
53 | static char *pretty_week(struct tm *tm) | 39 | static char *pretty_week(struct tm *tm) |
54 | { | 40 | { |
55 | static char buf[10]; | 41 | static char buf[10]; |
56 | 42 | ||
57 | strftime(buf, sizeof(buf), "W%V %G", tm); | 43 | strftime(buf, sizeof(buf), "W%V %G", tm); |
58 | return buf; | 44 | return buf; |
59 | } | 45 | } |
60 | 46 | ||
61 | static void trunc_month(struct tm *tm) | 47 | static void trunc_month(struct tm *tm) |
62 | { | 48 | { |
63 | tm->tm_mday = 1; | 49 | tm->tm_mday = 1; |
64 | } | 50 | } |
65 | 51 | ||
66 | static void dec_month(struct tm *tm) | 52 | static void dec_month(struct tm *tm) |
67 | { | 53 | { |
68 | tm->tm_mon--; | 54 | tm->tm_mon--; |
69 | if (tm->tm_mon < 0) { | 55 | if (tm->tm_mon < 0) { |
70 | tm->tm_year--; | 56 | tm->tm_year--; |
71 | tm->tm_mon = 11; | 57 | tm->tm_mon = 11; |
72 | } | 58 | } |
73 | } | 59 | } |
74 | 60 | ||
75 | static void inc_month(struct tm *tm) | 61 | static void inc_month(struct tm *tm) |
76 | { | 62 | { |
77 | tm->tm_mon++; | 63 | tm->tm_mon++; |
78 | if (tm->tm_mon > 11) { | 64 | if (tm->tm_mon > 11) { |
79 | tm->tm_year++; | 65 | tm->tm_year++; |
80 | tm->tm_mon = 0; | 66 | tm->tm_mon = 0; |
81 | } | 67 | } |
82 | } | 68 | } |
83 | 69 | ||
84 | static char *pretty_month(struct tm *tm) | 70 | static char *pretty_month(struct tm *tm) |
85 | { | 71 | { |
86 | static const char *months[] = { | 72 | static const char *months[] = { |
87 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 73 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
88 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | 74 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
89 | }; | 75 | }; |
90 | return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); | 76 | return fmt("%s %d", months[tm->tm_mon], tm->tm_year + 1900); |
91 | } | 77 | } |
92 | 78 | ||
93 | static void trunc_quarter(struct tm *tm) | 79 | static void trunc_quarter(struct tm *tm) |
94 | { | 80 | { |
95 | trunc_month(tm); | 81 | trunc_month(tm); |
96 | while(tm->tm_mon % 3 != 0) | 82 | while(tm->tm_mon % 3 != 0) |
97 | dec_month(tm); | 83 | dec_month(tm); |
98 | } | 84 | } |
99 | 85 | ||
100 | static void dec_quarter(struct tm *tm) | 86 | static void dec_quarter(struct tm *tm) |
101 | { | 87 | { |
102 | dec_month(tm); | 88 | dec_month(tm); |
103 | dec_month(tm); | 89 | dec_month(tm); |
104 | dec_month(tm); | 90 | dec_month(tm); |
105 | } | 91 | } |
106 | 92 | ||
107 | static void inc_quarter(struct tm *tm) | 93 | static void inc_quarter(struct tm *tm) |
108 | { | 94 | { |
109 | inc_month(tm); | 95 | inc_month(tm); |
110 | inc_month(tm); | 96 | inc_month(tm); |
111 | inc_month(tm); | 97 | inc_month(tm); |
112 | } | 98 | } |
113 | 99 | ||
114 | static char *pretty_quarter(struct tm *tm) | 100 | static char *pretty_quarter(struct tm *tm) |
115 | { | 101 | { |
116 | return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900); | 102 | return fmt("Q%d %d", tm->tm_mon / 3 + 1, tm->tm_year + 1900); |
117 | } | 103 | } |
118 | 104 | ||
119 | static void trunc_year(struct tm *tm) | 105 | static void trunc_year(struct tm *tm) |
120 | { | 106 | { |
121 | trunc_month(tm); | 107 | trunc_month(tm); |
122 | tm->tm_mon = 0; | 108 | tm->tm_mon = 0; |
123 | } | 109 | } |
124 | 110 | ||
125 | static void dec_year(struct tm *tm) | 111 | static void dec_year(struct tm *tm) |
126 | { | 112 | { |
127 | tm->tm_year--; | 113 | tm->tm_year--; |
128 | } | 114 | } |
129 | 115 | ||
130 | static void inc_year(struct tm *tm) | 116 | static void inc_year(struct tm *tm) |
131 | { | 117 | { |
132 | tm->tm_year++; | 118 | tm->tm_year++; |
133 | } | 119 | } |
134 | 120 | ||
135 | static char *pretty_year(struct tm *tm) | 121 | static char *pretty_year(struct tm *tm) |
136 | { | 122 | { |
137 | return fmt("%d", tm->tm_year + 1900); | 123 | return fmt("%d", tm->tm_year + 1900); |
138 | } | 124 | } |
139 | 125 | ||
140 | struct Period periods[] = { | 126 | struct cgit_period periods[] = { |
141 | {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, | 127 | {'w', "week", 12, 4, trunc_week, dec_week, inc_week, pretty_week}, |
142 | {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, | 128 | {'m', "month", 12, 4, trunc_month, dec_month, inc_month, pretty_month}, |
143 | {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, | 129 | {'q', "quarter", 12, 4, trunc_quarter, dec_quarter, inc_quarter, pretty_quarter}, |
144 | {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year}, | 130 | {'y', "year", 12, 4, trunc_year, dec_year, inc_year, pretty_year}, |
145 | }; | 131 | }; |
146 | 132 | ||
133 | /* Given a period code or name, return a period index (1, 2, 3 or 4) | ||
134 | * and update the period pointer to the correcsponding struct. | ||
135 | * If no matching code is found, return 0. | ||
136 | */ | ||
137 | int cgit_find_stats_period(const char *expr, struct cgit_period **period) | ||
138 | { | ||
139 | int i; | ||
140 | char code = '\0'; | ||
141 | |||
142 | if (!expr) | ||
143 | return 0; | ||
144 | |||
145 | if (strlen(expr) == 1) | ||
146 | code = expr[0]; | ||
147 | |||
148 | for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++) | ||
149 | if (periods[i].code == code || !strcmp(periods[i].name, expr)) { | ||
150 | if (period) | ||
151 | *period = &periods[i]; | ||
152 | return i+1; | ||
153 | } | ||
154 | return 0; | ||
155 | } | ||
156 | |||
147 | static void add_commit(struct string_list *authors, struct commit *commit, | 157 | static void add_commit(struct string_list *authors, struct commit *commit, |
148 | struct Period *period) | 158 | struct cgit_period *period) |
149 | { | 159 | { |
150 | struct commitinfo *info; | 160 | struct commitinfo *info; |
151 | struct string_list_item *author, *item; | 161 | struct string_list_item *author, *item; |
152 | struct authorstat *authorstat; | 162 | struct authorstat *authorstat; |
153 | struct string_list *items; | 163 | struct string_list *items; |
154 | char *tmp; | 164 | char *tmp; |
155 | struct tm *date; | 165 | struct tm *date; |
156 | time_t t; | 166 | time_t t; |
157 | 167 | ||
158 | info = cgit_parse_commit(commit); | 168 | info = cgit_parse_commit(commit); |
159 | tmp = xstrdup(info->author); | 169 | tmp = xstrdup(info->author); |
160 | author = string_list_insert(tmp, authors); | 170 | author = string_list_insert(tmp, authors); |
161 | if (!author->util) | 171 | if (!author->util) |
162 | author->util = xcalloc(1, sizeof(struct authorstat)); | 172 | author->util = xcalloc(1, sizeof(struct authorstat)); |
163 | else | 173 | else |
164 | free(tmp); | 174 | free(tmp); |
165 | authorstat = author->util; | 175 | authorstat = author->util; |
166 | items = &authorstat->list; | 176 | items = &authorstat->list; |
167 | t = info->committer_date; | 177 | t = info->committer_date; |
168 | date = gmtime(&t); | 178 | date = gmtime(&t); |
169 | period->trunc(date); | 179 | period->trunc(date); |
170 | tmp = xstrdup(period->pretty(date)); | 180 | tmp = xstrdup(period->pretty(date)); |
171 | item = string_list_insert(tmp, items); | 181 | item = string_list_insert(tmp, items); |
172 | if (item->util) | 182 | if (item->util) |
173 | free(tmp); | 183 | free(tmp); |
174 | item->util++; | 184 | item->util++; |
175 | authorstat->total++; | 185 | authorstat->total++; |
176 | cgit_free_commitinfo(info); | 186 | cgit_free_commitinfo(info); |
177 | } | 187 | } |
178 | 188 | ||
179 | static int cmp_total_commits(const void *a1, const void *a2) | 189 | static int cmp_total_commits(const void *a1, const void *a2) |
180 | { | 190 | { |
181 | const struct string_list_item *i1 = a1; | 191 | const struct string_list_item *i1 = a1; |
182 | const struct string_list_item *i2 = a2; | 192 | const struct string_list_item *i2 = a2; |
183 | const struct authorstat *auth1 = i1->util; | 193 | const struct authorstat *auth1 = i1->util; |
184 | const struct authorstat *auth2 = i2->util; | 194 | const struct authorstat *auth2 = i2->util; |
185 | 195 | ||
186 | return auth2->total - auth1->total; | 196 | return auth2->total - auth1->total; |
187 | } | 197 | } |
188 | 198 | ||
189 | /* Walk the commit DAG and collect number of commits per author per | 199 | /* Walk the commit DAG and collect number of commits per author per |
190 | * timeperiod into a nested string_list collection. | 200 | * timeperiod into a nested string_list collection. |
191 | */ | 201 | */ |
192 | struct string_list collect_stats(struct cgit_context *ctx, | 202 | struct string_list collect_stats(struct cgit_context *ctx, |
193 | struct Period *period) | 203 | struct cgit_period *period) |
194 | { | 204 | { |
195 | struct string_list authors; | 205 | struct string_list authors; |
196 | struct rev_info rev; | 206 | struct rev_info rev; |
197 | struct commit *commit; | 207 | struct commit *commit; |
198 | const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL}; | 208 | const char *argv[] = {NULL, ctx->qry.head, NULL, NULL, NULL, NULL}; |
199 | int argc = 3; | 209 | int argc = 3; |
200 | time_t now; | 210 | time_t now; |
201 | long i; | 211 | long i; |
202 | struct tm *tm; | 212 | struct tm *tm; |
203 | char tmp[11]; | 213 | char tmp[11]; |
204 | 214 | ||
205 | time(&now); | 215 | time(&now); |
206 | tm = gmtime(&now); | 216 | tm = gmtime(&now); |
207 | period->trunc(tm); | 217 | period->trunc(tm); |
208 | for (i = 1; i < period->count; i++) | 218 | for (i = 1; i < period->count; i++) |
209 | period->dec(tm); | 219 | period->dec(tm); |
210 | strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); | 220 | strftime(tmp, sizeof(tmp), "%Y-%m-%d", tm); |
211 | argv[2] = xstrdup(fmt("--since=%s", tmp)); | 221 | argv[2] = xstrdup(fmt("--since=%s", tmp)); |
212 | if (ctx->qry.path) { | 222 | if (ctx->qry.path) { |
213 | argv[3] = "--"; | 223 | argv[3] = "--"; |
214 | argv[4] = ctx->qry.path; | 224 | argv[4] = ctx->qry.path; |
215 | argc += 2; | 225 | argc += 2; |
216 | } | 226 | } |
217 | init_revisions(&rev, NULL); | 227 | init_revisions(&rev, NULL); |
218 | rev.abbrev = DEFAULT_ABBREV; | 228 | rev.abbrev = DEFAULT_ABBREV; |
219 | rev.commit_format = CMIT_FMT_DEFAULT; | 229 | rev.commit_format = CMIT_FMT_DEFAULT; |
220 | rev.no_merges = 1; | 230 | rev.no_merges = 1; |
221 | rev.verbose_header = 1; | 231 | rev.verbose_header = 1; |
222 | rev.show_root_diff = 0; | 232 | rev.show_root_diff = 0; |
223 | setup_revisions(argc, argv, &rev, NULL); | 233 | setup_revisions(argc, argv, &rev, NULL); |
224 | prepare_revision_walk(&rev); | 234 | prepare_revision_walk(&rev); |
225 | memset(&authors, 0, sizeof(authors)); | 235 | memset(&authors, 0, sizeof(authors)); |
226 | while ((commit = get_revision(&rev)) != NULL) { | 236 | while ((commit = get_revision(&rev)) != NULL) { |
227 | add_commit(&authors, commit, period); | 237 | add_commit(&authors, commit, period); |
228 | free(commit->buffer); | 238 | free(commit->buffer); |
229 | free_commit_list(commit->parents); | 239 | free_commit_list(commit->parents); |
230 | } | 240 | } |
231 | return authors; | 241 | return authors; |
232 | } | 242 | } |
233 | 243 | ||
234 | void print_combined_authorrow(struct string_list *authors, int from, int to, | 244 | void print_combined_authorrow(struct string_list *authors, int from, int to, |
235 | const char *name, const char *leftclass, const char *centerclass, | 245 | const char *name, const char *leftclass, const char *centerclass, |
236 | const char *rightclass, struct Period *period) | 246 | const char *rightclass, struct cgit_period *period) |
237 | { | 247 | { |
238 | struct string_list_item *author; | 248 | struct string_list_item *author; |
239 | struct authorstat *authorstat; | 249 | struct authorstat *authorstat; |
240 | struct string_list *items; | 250 | struct string_list *items; |
241 | struct string_list_item *date; | 251 | struct string_list_item *date; |
242 | time_t now; | 252 | time_t now; |
243 | long i, j, total, subtotal; | 253 | long i, j, total, subtotal; |
244 | struct tm *tm; | 254 | struct tm *tm; |
245 | char *tmp; | 255 | char *tmp; |
246 | 256 | ||
247 | time(&now); | 257 | time(&now); |
248 | tm = gmtime(&now); | 258 | tm = gmtime(&now); |
249 | period->trunc(tm); | 259 | period->trunc(tm); |
250 | for (i = 1; i < period->count; i++) | 260 | for (i = 1; i < period->count; i++) |
251 | period->dec(tm); | 261 | period->dec(tm); |
252 | 262 | ||
253 | total = 0; | 263 | total = 0; |
254 | htmlf("<tr><td class='%s'>%s</td>", leftclass, | 264 | htmlf("<tr><td class='%s'>%s</td>", leftclass, |
255 | fmt(name, to - from + 1)); | 265 | fmt(name, to - from + 1)); |
256 | for (j = 0; j < period->count; j++) { | 266 | for (j = 0; j < period->count; j++) { |
257 | tmp = period->pretty(tm); | 267 | tmp = period->pretty(tm); |
258 | period->inc(tm); | 268 | period->inc(tm); |
259 | subtotal = 0; | 269 | subtotal = 0; |
260 | for (i = from; i <= to; i++) { | 270 | for (i = from; i <= to; i++) { |
261 | author = &authors->items[i]; | 271 | author = &authors->items[i]; |
262 | authorstat = author->util; | 272 | authorstat = author->util; |
263 | items = &authorstat->list; | 273 | items = &authorstat->list; |
264 | date = string_list_lookup(tmp, items); | 274 | date = string_list_lookup(tmp, items); |
265 | if (date) | 275 | if (date) |
266 | subtotal += (size_t)date->util; | 276 | subtotal += (size_t)date->util; |
267 | } | 277 | } |
268 | htmlf("<td class='%s'>%d</td>", centerclass, subtotal); | 278 | htmlf("<td class='%s'>%d</td>", centerclass, subtotal); |
269 | total += subtotal; | 279 | total += subtotal; |
270 | } | 280 | } |
271 | htmlf("<td class='%s'>%d</td></tr>", rightclass, total); | 281 | htmlf("<td class='%s'>%d</td></tr>", rightclass, total); |
272 | } | 282 | } |
273 | 283 | ||
274 | void print_authors(struct string_list *authors, int top, struct Period *period) | 284 | void print_authors(struct string_list *authors, int top, |
285 | struct cgit_period *period) | ||
275 | { | 286 | { |
276 | struct string_list_item *author; | 287 | struct string_list_item *author; |
277 | struct authorstat *authorstat; | 288 | struct authorstat *authorstat; |
278 | struct string_list *items; | 289 | struct string_list *items; |
279 | struct string_list_item *date; | 290 | struct string_list_item *date; |
280 | time_t now; | 291 | time_t now; |
281 | long i, j, total; | 292 | long i, j, total; |
282 | struct tm *tm; | 293 | struct tm *tm; |
283 | char *tmp; | 294 | char *tmp; |
284 | 295 | ||
285 | time(&now); | 296 | time(&now); |
286 | tm = gmtime(&now); | 297 | tm = gmtime(&now); |
287 | period->trunc(tm); | 298 | period->trunc(tm); |
288 | for (i = 1; i < period->count; i++) | 299 | for (i = 1; i < period->count; i++) |
289 | period->dec(tm); | 300 | period->dec(tm); |
290 | 301 | ||
291 | html("<table class='stats'><tr><th>Author</th>"); | 302 | html("<table class='stats'><tr><th>Author</th>"); |
292 | for (j = 0; j < period->count; j++) { | 303 | for (j = 0; j < period->count; j++) { |
293 | tmp = period->pretty(tm); | 304 | tmp = period->pretty(tm); |
294 | htmlf("<th>%s</th>", tmp); | 305 | htmlf("<th>%s</th>", tmp); |
295 | period->inc(tm); | 306 | period->inc(tm); |
296 | } | 307 | } |
297 | html("<th>Total</th></tr>\n"); | 308 | html("<th>Total</th></tr>\n"); |
298 | 309 | ||
299 | if (top <= 0 || top > authors->nr) | 310 | if (top <= 0 || top > authors->nr) |
300 | top = authors->nr; | 311 | top = authors->nr; |
301 | 312 | ||
302 | for (i = 0; i < top; i++) { | 313 | for (i = 0; i < top; i++) { |
303 | author = &authors->items[i]; | 314 | author = &authors->items[i]; |
304 | html("<tr><td class='left'>"); | 315 | html("<tr><td class='left'>"); |
305 | html_txt(author->string); | 316 | html_txt(author->string); |
306 | html("</td>"); | 317 | html("</td>"); |
307 | authorstat = author->util; | 318 | authorstat = author->util; |
308 | items = &authorstat->list; | 319 | items = &authorstat->list; |
309 | total = 0; | 320 | total = 0; |
310 | for (j = 0; j < period->count; j++) | 321 | for (j = 0; j < period->count; j++) |
311 | period->dec(tm); | 322 | period->dec(tm); |
312 | for (j = 0; j < period->count; j++) { | 323 | for (j = 0; j < period->count; j++) { |
313 | tmp = period->pretty(tm); | 324 | tmp = period->pretty(tm); |
314 | period->inc(tm); | 325 | period->inc(tm); |
315 | date = string_list_lookup(tmp, items); | 326 | date = string_list_lookup(tmp, items); |
316 | if (!date) | 327 | if (!date) |
317 | html("<td>0</td>"); | 328 | html("<td>0</td>"); |
318 | else { | 329 | else { |
319 | htmlf("<td>%d</td>", date->util); | 330 | htmlf("<td>%d</td>", date->util); |
320 | total += (size_t)date->util; | 331 | total += (size_t)date->util; |
321 | } | 332 | } |
322 | } | 333 | } |
323 | htmlf("<td class='sum'>%d</td></tr>", total); | 334 | htmlf("<td class='sum'>%d</td></tr>", total); |
324 | } | 335 | } |
325 | 336 | ||
326 | if (top < authors->nr) | 337 | if (top < authors->nr) |
327 | print_combined_authorrow(authors, top, authors->nr - 1, | 338 | print_combined_authorrow(authors, top, authors->nr - 1, |
328 | "Others (%d)", "left", "", "sum", period); | 339 | "Others (%d)", "left", "", "sum", period); |
329 | 340 | ||
330 | print_combined_authorrow(authors, 0, authors->nr - 1, "Total", | 341 | print_combined_authorrow(authors, 0, authors->nr - 1, "Total", |
331 | "total", "sum", "sum", period); | 342 | "total", "sum", "sum", period); |
332 | html("</table>"); | 343 | html("</table>"); |
333 | } | 344 | } |
334 | 345 | ||
335 | /* Create a sorted string_list with one entry per author. The util-field | 346 | /* Create a sorted string_list with one entry per author. The util-field |
336 | * for each author is another string_list which is used to calculate the | 347 | * for each author is another string_list which is used to calculate the |
337 | * number of commits per time-interval. | 348 | * number of commits per time-interval. |
338 | */ | 349 | */ |
339 | void cgit_show_stats(struct cgit_context *ctx) | 350 | void cgit_show_stats(struct cgit_context *ctx) |
340 | { | 351 | { |
341 | struct string_list authors; | 352 | struct string_list authors; |
342 | struct Period *period; | 353 | struct cgit_period *period; |
343 | int top, i; | 354 | int top, i; |
355 | const char *code = "w"; | ||
344 | 356 | ||
345 | period = &periods[0]; | 357 | if (ctx->qry.period) |
346 | if (ctx->qry.period) { | 358 | code = ctx->qry.period; |
347 | for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++) | 359 | |
348 | if (periods[i].code == ctx->qry.period[0]) { | 360 | i = cgit_find_stats_period(code, &period); |
349 | period = &periods[i]; | 361 | if (!i) { |
350 | break; | 362 | cgit_print_error(fmt("Unknown statistics type: %c", code)); |
351 | } | 363 | return; |
364 | } | ||
365 | if (i > ctx->repo->max_stats) { | ||
366 | cgit_print_error(fmt("Statistics type disabled: %s", | ||
367 | period->name)); | ||
368 | return; | ||
352 | } | 369 | } |
353 | authors = collect_stats(ctx, period); | 370 | authors = collect_stats(ctx, period); |
354 | qsort(authors.items, authors.nr, sizeof(struct string_list_item), | 371 | qsort(authors.items, authors.nr, sizeof(struct string_list_item), |
355 | cmp_total_commits); | 372 | cmp_total_commits); |
356 | 373 | ||
357 | top = ctx->qry.ofs; | 374 | top = ctx->qry.ofs; |
358 | if (!top) | 375 | if (!top) |
359 | top = 10; | 376 | top = 10; |
360 | htmlf("<h2>Commits per author per %s", period->name); | 377 | htmlf("<h2>Commits per author per %s", period->name); |
361 | if (ctx->qry.path) { | 378 | if (ctx->qry.path) { |
362 | html(" (path '"); | 379 | html(" (path '"); |
363 | html_txt(ctx->qry.path); | 380 | html_txt(ctx->qry.path); |
364 | html("')"); | 381 | html("')"); |
365 | } | 382 | } |
366 | html("</h2>"); | 383 | html("</h2>"); |
367 | 384 | ||
368 | html("<form method='get' action='.' style='float: right; text-align: right;'>"); | 385 | html("<form method='get' action='.' style='float: right; text-align: right;'>"); |
369 | if (strcmp(ctx->qry.head, ctx->repo->defbranch)) | 386 | if (strcmp(ctx->qry.head, ctx->repo->defbranch)) |
370 | htmlf("<input type='hidden' name='h' value='%s'/>", ctx->qry.head); | 387 | htmlf("<input type='hidden' name='h' value='%s'/>", ctx->qry.head); |
371 | html("Period: "); | 388 | if (ctx->repo->max_stats > 1) { |
372 | html("<select name='period' onchange='this.form.submit();'>"); | 389 | html("Period: "); |
373 | for (i = 0; i < sizeof(periods) / sizeof(periods[0]); i++) | 390 | html("<select name='period' onchange='this.form.submit();'>"); |
374 | htmlf("<option value='%c'%s>%s</option>", | 391 | for (i = 0; i < ctx->repo->max_stats; i++) |
375 | periods[i].code, | 392 | htmlf("<option value='%c'%s>%s</option>", |
376 | period == &periods[i] ? " selected" : "", | 393 | periods[i].code, |
377 | periods[i].name); | 394 | period == &periods[i] ? " selected" : "", |
378 | html("</select><br/><br/>"); | 395 | periods[i].name); |
396 | html("</select><br/><br/>"); | ||
397 | } | ||
379 | html("Authors: "); | 398 | html("Authors: "); |
380 | html(""); | 399 | html(""); |
381 | html("<select name='ofs' onchange='this.form.submit();'>"); | 400 | html("<select name='ofs' onchange='this.form.submit();'>"); |
382 | htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : ""); | 401 | htmlf("<option value='10'%s>10</option>", top == 10 ? " selected" : ""); |
383 | htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : ""); | 402 | htmlf("<option value='25'%s>25</option>", top == 25 ? " selected" : ""); |
384 | htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : ""); | 403 | htmlf("<option value='50'%s>50</option>", top == 50 ? " selected" : ""); |
385 | htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : ""); | 404 | htmlf("<option value='100'%s>100</option>", top == 100 ? " selected" : ""); |
386 | htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : ""); | 405 | htmlf("<option value='-1'%s>All</option>", top == -1 ? " selected" : ""); |
387 | html("</select>"); | 406 | html("</select>"); |
388 | html("<noscript> <input type='submit' value='Reload'/></noscript>"); | 407 | html("<noscript> <input type='submit' value='Reload'/></noscript>"); |
389 | html("</form>"); | 408 | html("</form>"); |
390 | print_authors(&authors, top, period); | 409 | print_authors(&authors, top, period); |
391 | } | 410 | } |
392 | 411 | ||
@@ -1,8 +1,27 @@ | |||
1 | #ifndef UI_STATS_H | 1 | #ifndef UI_STATS_H |
2 | #define UI_STATS_H | 2 | #define UI_STATS_H |
3 | 3 | ||
4 | #include "cgit.h" | 4 | #include "cgit.h" |
5 | 5 | ||
6 | struct cgit_period { | ||
7 | const char code; | ||
8 | const char *name; | ||
9 | int max_periods; | ||
10 | int count; | ||
11 | |||
12 | /* Convert a tm value to the first day in the period */ | ||
13 | void (*trunc)(struct tm *tm); | ||
14 | |||
15 | /* Update tm value to start of next/previous period */ | ||
16 | void (*dec)(struct tm *tm); | ||
17 | void (*inc)(struct tm *tm); | ||
18 | |||
19 | /* Pretty-print a tm value */ | ||
20 | char *(*pretty)(struct tm *tm); | ||
21 | }; | ||
22 | |||
23 | extern int cgit_find_stats_period(const char *expr, struct cgit_period **period); | ||
24 | |||
6 | extern void cgit_show_stats(struct cgit_context *ctx); | 25 | extern void cgit_show_stats(struct cgit_context *ctx); |
7 | 26 | ||
8 | #endif /* UI_STATS_H */ | 27 | #endif /* UI_STATS_H */ |