aboutsummaryrefslogtreecommitdiffstats
path: root/shared.c
diff options
context:
space:
mode:
Diffstat (limited to 'shared.c')
-rw-r--r--shared.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/shared.c b/shared.c
index b6d2fa1..077934f 100644
--- a/shared.c
+++ b/shared.c
@@ -12,6 +12,8 @@ struct 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;
16
15char *cgit_root_title = "Git repository browser"; 17char *cgit_root_title = "Git repository browser";
16char *cgit_css = "/cgit.css"; 18char *cgit_css = "/cgit.css";
17char *cgit_logo = "/git-logo.png"; 19char *cgit_logo = "/git-logo.png";
@@ -26,6 +28,7 @@ char *cgit_repo_group = NULL;
26 28
27int cgit_nocache = 0; 29int cgit_nocache = 0;
28int cgit_snapshots = 0; 30int cgit_snapshots = 0;
31int cgit_enable_index_links = 0;
29int cgit_enable_log_filecount = 0; 32int cgit_enable_log_filecount = 0;
30int cgit_enable_log_linecount = 0; 33int cgit_enable_log_linecount = 0;
31int cgit_max_lock_attempts = 5; 34int cgit_max_lock_attempts = 5;
@@ -59,7 +62,8 @@ int htmlfd = 0;
59 62
60int cgit_get_cmd_index(const char *cmd) 63int cgit_get_cmd_index(const char *cmd)
61{ 64{
62 static char *cmds[] = {"log", "commit", "diff", "tree", "view", "blob", "snapshot", NULL}; 65 static char *cmds[] = {"log", "commit", "diff", "tree", "blob",
66 "snapshot", "tag", NULL};
63 int i; 67 int i;
64 68
65 for(i = 0; cmds[i]; i++) 69 for(i = 0; cmds[i]; i++)
@@ -82,6 +86,13 @@ int chk_positive(int result, char *msg)
82 return result; 86 return result;
83} 87}
84 88
89int chk_non_negative(int result, char *msg)
90{
91 if (result < 0)
92 die("%s: %s",msg, strerror(errno));
93 return result;
94}
95
85struct repoinfo *add_repo(const char *url) 96struct repoinfo *add_repo(const char *url)
86{ 97{
87 struct repoinfo *ret; 98 struct repoinfo *ret;
@@ -144,7 +155,9 @@ void cgit_global_config_cb(const char *name, const char *value)
144 else if (!strcmp(name, "nocache")) 155 else if (!strcmp(name, "nocache"))
145 cgit_nocache = atoi(value); 156 cgit_nocache = atoi(value);
146 else if (!strcmp(name, "snapshots")) 157 else if (!strcmp(name, "snapshots"))
147 cgit_snapshots = atoi(value); 158 cgit_snapshots = cgit_parse_snapshots_mask(value);
159 else if (!strcmp(name, "enable-index-links"))
160 cgit_enable_index_links = atoi(value);
148 else if (!strcmp(name, "enable-log-filecount")) 161 else if (!strcmp(name, "enable-log-filecount"))
149 cgit_enable_log_filecount = atoi(value); 162 cgit_enable_log_filecount = atoi(value);
150 else if (!strcmp(name, "enable-log-linecount")) 163 else if (!strcmp(name, "enable-log-linecount"))
@@ -184,7 +197,7 @@ void cgit_global_config_cb(const char *name, const char *value)
184 else if (cgit_repo && !strcmp(name, "repo.defbranch")) 197 else if (cgit_repo && !strcmp(name, "repo.defbranch"))
185 cgit_repo->defbranch = xstrdup(value); 198 cgit_repo->defbranch = xstrdup(value);
186 else if (cgit_repo && !strcmp(name, "repo.snapshots")) 199 else if (cgit_repo && !strcmp(name, "repo.snapshots"))
187 cgit_repo->snapshots = cgit_snapshots * atoi(value); 200 cgit_repo->snapshots = cgit_snapshots & cgit_parse_snapshots_mask(value); /* XXX: &? */
188 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount")) 201 else if (cgit_repo && !strcmp(name, "repo.enable-log-filecount"))
189 cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value); 202 cgit_repo->enable_log_filecount = cgit_enable_log_filecount * atoi(value);
190 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount")) 203 else if (cgit_repo && !strcmp(name, "repo.enable-log-linecount"))
@@ -224,7 +237,7 @@ void cgit_querystring_cb(const char *name, const char *value)
224 } else if (!strcmp(name, "ofs")) { 237 } else if (!strcmp(name, "ofs")) {
225 cgit_query_ofs = atoi(value); 238 cgit_query_ofs = atoi(value);
226 } else if (!strcmp(name, "path")) { 239 } else if (!strcmp(name, "path")) {
227 cgit_query_path = xstrdup(value); 240 cgit_query_path = trim_end(value, '/');
228 } else if (!strcmp(name, "name")) { 241 } else if (!strcmp(name, "name")) {
229 cgit_query_name = xstrdup(value); 242 cgit_query_name = xstrdup(value);
230 } 243 }
@@ -253,6 +266,28 @@ int hextoint(char c)
253 return -1; 266 return -1;
254} 267}
255 268
269char *trim_end(const char *str, char c)
270{
271 int len;
272 char *s, *t;
273
274 if (str == NULL)
275 return NULL;
276 t = (char *)str;
277 len = strlen(t);
278 while(len > 0 && t[len - 1] == c)
279 len--;
280
281 if (len == 0)
282 return NULL;
283
284 c = t[len];
285 t[len] = '\0';
286 s = xstrdup(t);
287 t[len] = c;
288 return s;
289}
290
256void cgit_diff_tree_cb(struct diff_queue_struct *q, 291void cgit_diff_tree_cb(struct diff_queue_struct *q,
257 struct diff_options *options, void *data) 292 struct diff_options *options, void *data)
258{ 293{
@@ -359,7 +394,7 @@ void cgit_diff_tree(const unsigned char *old_sha1,
359 opt.format_callback_data = fn; 394 opt.format_callback_data = fn;
360 diff_setup_done(&opt); 395 diff_setup_done(&opt);
361 396
362 if (old_sha1) 397 if (old_sha1 && !is_null_sha1(old_sha1))
363 ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); 398 ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt);
364 else 399 else
365 ret = diff_root_tree_sha1(new_sha1, "", &opt); 400 ret = diff_root_tree_sha1(new_sha1, "", &opt);