summaryrefslogtreecommitdiffabout
path: root/shared.c
authorLars Hjemli <hjemli@gmail.com>2007-10-28 14:23:00 (UTC)
committer Lars Hjemli <hjemli@gmail.com>2007-10-28 14:23:00 (UTC)
commit68ca032dbe7379f78775fb03ef34a9ad2abc409f (patch) (unidiff)
tree2209ae312eb932bc61b41ae9c774f6cfcc3dd372 /shared.c
parent6ec5f36f279a85f59db2851ab476d9acd0015770 (diff)
downloadcgit-68ca032dbe7379f78775fb03ef34a9ad2abc409f.zip
cgit-68ca032dbe7379f78775fb03ef34a9ad2abc409f.tar.gz
cgit-68ca032dbe7379f78775fb03ef34a9ad2abc409f.tar.bz2
Teach log search about --grep, --author and --committer
This makes the log searching more explicit, using a dropdown box to specify the commit field to match against. Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'shared.c') (more/less context) (ignore whitespace changes)
-rw-r--r--shared.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/shared.c b/shared.c
index 7eb2b0e..4fab1c9 100644
--- a/shared.c
+++ b/shared.c
@@ -9,96 +9,97 @@
9#include "cgit.h" 9#include "cgit.h"
10 10
11struct repolist cgit_repolist; 11struct repolist cgit_repolist;
12struct repoinfo *cgit_repo; 12struct repoinfo *cgit_repo;
13int cgit_cmd; 13int cgit_cmd;
14 14
15const char *cgit_version = CGIT_VERSION; 15const char *cgit_version = CGIT_VERSION;
16 16
17char *cgit_root_title = "Git repository browser"; 17char *cgit_root_title = "Git repository browser";
18char *cgit_css = "/cgit.css"; 18char *cgit_css = "/cgit.css";
19char *cgit_logo = "/git-logo.png"; 19char *cgit_logo = "/git-logo.png";
20char *cgit_index_header = NULL; 20char *cgit_index_header = NULL;
21char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/"; 21char *cgit_logo_link = "http://www.kernel.org/pub/software/scm/git/docs/";
22char *cgit_module_link = "./?repo=%s&page=commit&id=%s"; 22char *cgit_module_link = "./?repo=%s&page=commit&id=%s";
23char *cgit_agefile = "info/web/last-modified"; 23char *cgit_agefile = "info/web/last-modified";
24char *cgit_virtual_root = NULL; 24char *cgit_virtual_root = NULL;
25char *cgit_script_name = CGIT_SCRIPT_NAME; 25char *cgit_script_name = CGIT_SCRIPT_NAME;
26char *cgit_cache_root = CGIT_CACHE_ROOT; 26char *cgit_cache_root = CGIT_CACHE_ROOT;
27char *cgit_repo_group = NULL; 27char *cgit_repo_group = NULL;
28 28
29int cgit_nocache = 0; 29int cgit_nocache = 0;
30int cgit_snapshots = 0; 30int cgit_snapshots = 0;
31int cgit_enable_index_links = 0; 31int cgit_enable_index_links = 0;
32int cgit_enable_log_filecount = 0; 32int cgit_enable_log_filecount = 0;
33int cgit_enable_log_linecount = 0; 33int cgit_enable_log_linecount = 0;
34int cgit_max_lock_attempts = 5; 34int cgit_max_lock_attempts = 5;
35int cgit_cache_root_ttl = 5; 35int cgit_cache_root_ttl = 5;
36int cgit_cache_repo_ttl = 5; 36int cgit_cache_repo_ttl = 5;
37int cgit_cache_dynamic_ttl = 5; 37int cgit_cache_dynamic_ttl = 5;
38int cgit_cache_static_ttl = -1; 38int cgit_cache_static_ttl = -1;
39int cgit_cache_max_create_time = 5; 39int cgit_cache_max_create_time = 5;
40int cgit_summary_log = 0; 40int cgit_summary_log = 0;
41int cgit_summary_tags = 0; 41int cgit_summary_tags = 0;
42int cgit_summary_branches = 0; 42int cgit_summary_branches = 0;
43int cgit_renamelimit = -1; 43int cgit_renamelimit = -1;
44 44
45int cgit_max_msg_len = 60; 45int cgit_max_msg_len = 60;
46int cgit_max_repodesc_len = 60; 46int cgit_max_repodesc_len = 60;
47int cgit_max_commit_count = 50; 47int cgit_max_commit_count = 50;
48 48
49int cgit_query_has_symref = 0; 49int cgit_query_has_symref = 0;
50int cgit_query_has_sha1 = 0; 50int cgit_query_has_sha1 = 0;
51 51
52char *cgit_querystring = NULL; 52char *cgit_querystring = NULL;
53char *cgit_query_repo = NULL; 53char *cgit_query_repo = NULL;
54char *cgit_query_page = NULL; 54char *cgit_query_page = NULL;
55char *cgit_query_head = NULL; 55char *cgit_query_head = NULL;
56char *cgit_query_search = NULL; 56char *cgit_query_search = NULL;
57char *cgit_query_grep = NULL;
57char *cgit_query_sha1 = NULL; 58char *cgit_query_sha1 = NULL;
58char *cgit_query_sha2 = NULL; 59char *cgit_query_sha2 = NULL;
59char *cgit_query_path = NULL; 60char *cgit_query_path = NULL;
60char *cgit_query_name = NULL; 61char *cgit_query_name = NULL;
61int cgit_query_ofs = 0; 62int cgit_query_ofs = 0;
62 63
63int htmlfd = 0; 64int htmlfd = 0;
64 65
65 66
66int cgit_get_cmd_index(const char *cmd) 67int cgit_get_cmd_index(const char *cmd)
67{ 68{
68 static char *cmds[] = {"log", "commit", "diff", "tree", "blob", 69 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
69 "snapshot", "tag", "refs", NULL}; 70 "snapshot", "tag", "refs", NULL};
70 int i; 71 int i;
71 72
72 for(i = 0; cmds[i]; i++) 73 for(i = 0; cmds[i]; i++)
73 if (!strcmp(cmd, cmds[i])) 74 if (!strcmp(cmd, cmds[i]))
74 return i + 1; 75 return i + 1;
75 return 0; 76 return 0;
76} 77}
77 78
78int chk_zero(int result, char *msg) 79int chk_zero(int result, char *msg)
79{ 80{
80 if (result != 0) 81 if (result != 0)
81 die("%s: %s", msg, strerror(errno)); 82 die("%s: %s", msg, strerror(errno));
82 return result; 83 return result;
83} 84}
84 85
85int chk_positive(int result, char *msg) 86int chk_positive(int result, char *msg)
86{ 87{
87 if (result <= 0) 88 if (result <= 0)
88 die("%s: %s", msg, strerror(errno)); 89 die("%s: %s", msg, strerror(errno));
89 return result; 90 return result;
90} 91}
91 92
92int chk_non_negative(int result, char *msg) 93int chk_non_negative(int result, char *msg)
93{ 94{
94 if (result < 0) 95 if (result < 0)
95 die("%s: %s",msg, strerror(errno)); 96 die("%s: %s",msg, strerror(errno));
96 return result; 97 return result;
97} 98}
98 99
99struct repoinfo *add_repo(const char *url) 100struct repoinfo *add_repo(const char *url)
100{ 101{
101 struct repoinfo *ret; 102 struct repoinfo *ret;
102 103
103 if (++cgit_repolist.count > cgit_repolist.length) { 104 if (++cgit_repolist.count > cgit_repolist.length) {
104 if (cgit_repolist.length == 0) 105 if (cgit_repolist.length == 0)
@@ -187,96 +188,98 @@ void cgit_global_config_cb(const char *name, const char *value)
187 cgit_summary_branches = atoi(value); 188 cgit_summary_branches = atoi(value);
188 else if (!strcmp(name, "summary-tags")) 189 else if (!strcmp(name, "summary-tags"))
189 cgit_summary_tags = atoi(value); 190 cgit_summary_tags = atoi(value);
190 else if (!strcmp(name, "agefile")) 191 else if (!strcmp(name, "agefile"))
191 cgit_agefile = xstrdup(value); 192 cgit_agefile = xstrdup(value);
192 else if (!strcmp(name, "renamelimit")) 193 else if (!strcmp(name, "renamelimit"))
193 cgit_renamelimit = atoi(value); 194 cgit_renamelimit = atoi(value);
194 else if (!strcmp(name, "repo.group")) 195 else if (!strcmp(name, "repo.group"))
195 cgit_repo_group = xstrdup(value); 196 cgit_repo_group = xstrdup(value);
196 else if (!strcmp(name, "repo.url")) 197 else if (!strcmp(name, "repo.url"))
197 cgit_repo = add_repo(value); 198 cgit_repo = add_repo(value);
198 else if (!strcmp(name, "repo.name")) 199 else if (!strcmp(name, "repo.name"))
199 cgit_repo->name = xstrdup(value); 200 cgit_repo->name = xstrdup(value);
200 else if (cgit_repo && !strcmp(name, "repo.path")) 201 else if (cgit_repo && !strcmp(name, "repo.path"))
201 cgit_repo->path = trim_end(value, '/'); 202 cgit_repo->path = trim_end(value, '/');
202 else if (cgit_repo && !strcmp(name, "repo.desc")) 203 else if (cgit_repo && !strcmp(name, "repo.desc"))
203 cgit_repo->desc = xstrdup(value); 204 cgit_repo->desc = xstrdup(value);
204 else if (cgit_repo && !strcmp(name, "repo.owner")) 205 else if (cgit_repo && !strcmp(name, "repo.owner"))
205 cgit_repo->owner = xstrdup(value); 206 cgit_repo->owner = xstrdup(value);
206 else if (cgit_repo && !strcmp(name, "repo.defbranch")) 207 else if (cgit_repo && !strcmp(name, "repo.defbranch"))
207 cgit_repo->defbranch = xstrdup(value); 208 cgit_repo->defbranch = xstrdup(value);
208 else if (cgit_repo && !strcmp(name, "repo.snapshots")) 209 else if (cgit_repo && !strcmp(name, "repo.snapshots"))
209 cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */ 210 cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
210 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) 211 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount"))
211 cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); 212 cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value);
212 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) 213 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount"))
213 cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value); 214 cgit_repo->enable_log_linecount = cgit_enable_log_linecount * atoi(value);
214 else if (cgit_repo && !strcmp(name, "repo.module-link")) 215 else if (cgit_repo && !strcmp(name, "repo.module-link"))
215 cgit_repo->module_link= xstrdup(value); 216 cgit_repo->module_link= xstrdup(value);
216 else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) { 217 else if (cgit_repo && !strcmp(name, "repo.readme") && value != NULL) {
217 if (*value == '/') 218 if (*value == '/')
218 cgit_repo->readme = xstrdup(value); 219 cgit_repo->readme = xstrdup(value);
219 else 220 else
220 cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value)); 221 cgit_repo->readme = xstrdup(fmt("%s/%s", cgit_repo->path, value));
221 } else if (!strcmp(name, "include")) 222 } else if (!strcmp(name, "include"))
222 cgit_read_config(value, cgit_global_config_cb); 223 cgit_read_config(value, cgit_global_config_cb);
223} 224}
224 225
225void cgit_querystring_cb(const char *name, const char *value) 226void cgit_querystring_cb(const char *name, const char *value)
226{ 227{
227 if (!strcmp(name,"r")) { 228 if (!strcmp(name,"r")) {
228 cgit_query_repo = xstrdup(value); 229 cgit_query_repo = xstrdup(value);
229 cgit_repo = cgit_get_repoinfo(value); 230 cgit_repo = cgit_get_repoinfo(value);
230 } else if (!strcmp(name, "p")) { 231 } else if (!strcmp(name, "p")) {
231 cgit_query_page = xstrdup(value); 232 cgit_query_page = xstrdup(value);
232 cgit_cmd = cgit_get_cmd_index(value); 233 cgit_cmd = cgit_get_cmd_index(value);
233 } else if (!strcmp(name, "url")) { 234 } else if (!strcmp(name, "url")) {
234 cgit_parse_url(value); 235 cgit_parse_url(value);
236 } else if (!strcmp(name, "qt")) {
237 cgit_query_grep = xstrdup(value);
235 } else if (!strcmp(name, "q")) { 238 } else if (!strcmp(name, "q")) {
236 cgit_query_search = xstrdup(value); 239 cgit_query_search = xstrdup(value);
237 } else if (!strcmp(name, "h")) { 240 } else if (!strcmp(name, "h")) {
238 cgit_query_head = xstrdup(value); 241 cgit_query_head = xstrdup(value);
239 cgit_query_has_symref = 1; 242 cgit_query_has_symref = 1;
240 } else if (!strcmp(name, "id")) { 243 } else if (!strcmp(name, "id")) {
241 cgit_query_sha1 = xstrdup(value); 244 cgit_query_sha1 = xstrdup(value);
242 cgit_query_has_sha1 = 1; 245 cgit_query_has_sha1 = 1;
243 } else if (!strcmp(name, "id2")) { 246 } else if (!strcmp(name, "id2")) {
244 cgit_query_sha2 = xstrdup(value); 247 cgit_query_sha2 = xstrdup(value);
245 cgit_query_has_sha1 = 1; 248 cgit_query_has_sha1 = 1;
246 } else if (!strcmp(name, "ofs")) { 249 } else if (!strcmp(name, "ofs")) {
247 cgit_query_ofs = atoi(value); 250 cgit_query_ofs = atoi(value);
248 } else if (!strcmp(name, "path")) { 251 } else if (!strcmp(name, "path")) {
249 cgit_query_path = trim_end(value, '/'); 252 cgit_query_path = trim_end(value, '/');
250 } else if (!strcmp(name, "name")) { 253 } else if (!strcmp(name, "name")) {
251 cgit_query_name = xstrdup(value); 254 cgit_query_name = xstrdup(value);
252 } 255 }
253} 256}
254 257
255void *cgit_free_commitinfo(struct commitinfo *info) 258void *cgit_free_commitinfo(struct commitinfo *info)
256{ 259{
257 free(info->author); 260 free(info->author);
258 free(info->author_email); 261 free(info->author_email);
259 free(info->committer); 262 free(info->committer);
260 free(info->committer_email); 263 free(info->committer_email);
261 free(info->subject); 264 free(info->subject);
262 free(info); 265 free(info);
263 return NULL; 266 return NULL;
264} 267}
265 268
266int hextoint(char c) 269int hextoint(char c)
267{ 270{
268 if (c >= 'a' && c <= 'f') 271 if (c >= 'a' && c <= 'f')
269 return 10 + c - 'a'; 272 return 10 + c - 'a';
270 else if (c >= 'A' && c <= 'F') 273 else if (c >= 'A' && c <= 'F')
271 return 10 + c - 'A'; 274 return 10 + c - 'A';
272 else if (c >= '0' && c <= '9') 275 else if (c >= '0' && c <= '9')
273 return c - '0'; 276 return c - '0';
274 else 277 else
275 return -1; 278 return -1;
276} 279}
277 280
278char *trim_end(const char *str, char c) 281char *trim_end(const char *str, char c)
279{ 282{
280 int len; 283 int len;
281 char *s, *t; 284 char *s, *t;
282 285