about summary refs log tree commit diff stats
path: root/cgit.c
diff options
context:
space:
mode:
authorLukas Fleischer2016-10-08 15:45:12 +0200
committerJason A. Donenfeld2016-10-12 14:13:10 +0200
commit32c27e887732298da1724c0740004925fcadae39 (patch)
treed2b46038cd3e3e8e483363d5aad535c7de063c79 /cgit.c
parentpatch: reapply path limit (diff)
downloadcgit-32c27e887732298da1724c0740004925fcadae39.tar.gz
cgit-32c27e887732298da1724c0740004925fcadae39.zip
Use skip_prefix() to get rid of magic constants
Signed-off-by: Lukas Fleischer <lfleischer@lfos.de>
Diffstat (limited to 'cgit.c')
-rw-r--r--cgit.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/cgit.c b/cgit.c index 9f5a80f..1075753 100644 --- a/cgit.c +++ b/cgit.c
@@ -31,6 +31,7 @@ static void process_cached_repolist(const char *path);
31 31
32static void repo_config(struct cgit_repo *repo, const char *name, const char *value) 32static void repo_config(struct cgit_repo *repo, const char *name, const char *value)
33{ 33{
34 const char *path;
34 struct string_list_item *item; 35 struct string_list_item *item;
35 36
36 if (!strcmp(name, "name")) 37 if (!strcmp(name, "name"))
@@ -73,8 +74,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
73 repo->max_stats = cgit_find_stats_period(value, NULL); 74 repo->max_stats = cgit_find_stats_period(value, NULL);
74 else if (!strcmp(name, "module-link")) 75 else if (!strcmp(name, "module-link"))
75 repo->module_link= xstrdup(value); 76 repo->module_link= xstrdup(value);
76 else if (starts_with(name, "module-link.")) { 77 else if (skip_prefix(name, "module-link.", &path)) {
77 item = string_list_append(&repo->submodules, xstrdup(name + 12)); 78 item = string_list_append(&repo->submodules, xstrdup(path));
78 item->util = xstrdup(value); 79 item->util = xstrdup(value);
79 } else if (!strcmp(name, "section")) 80 } else if (!strcmp(name, "section"))
80 repo->section = xstrdup(value); 81 repo->section = xstrdup(value);
@@ -106,14 +107,16 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va
106 107
107static void config_cb(const char *name, const char *value) 108static void config_cb(const char *name, const char *value)
108{ 109{
110 const char *arg;
111
109 if (!strcmp(name, "section") || !strcmp(name, "repo.group")) 112 if (!strcmp(name, "section") || !strcmp(name, "repo.group"))
110 ctx.cfg.section = xstrdup(value); 113 ctx.cfg.section = xstrdup(value);
111 else if (!strcmp(name, "repo.url")) 114 else if (!strcmp(name, "repo.url"))
112 ctx.repo = cgit_add_repo(value); 115 ctx.repo = cgit_add_repo(value);
113 else if (ctx.repo && !strcmp(name, "repo.path")) 116 else if (ctx.repo && !strcmp(name, "repo.path"))
114 ctx.repo->path = trim_end(value, '/'); 117 ctx.repo->path = trim_end(value, '/');
115 else if (ctx.repo && starts_with(name, "repo.")) 118 else if (ctx.repo && skip_prefix(name, "repo.", &arg))
116 repo_config(ctx.repo, name + 5, value); 119 repo_config(ctx.repo, arg, value);
117 else if (!strcmp(name, "readme")) 120 else if (!strcmp(name, "readme"))
118 string_list_append(&ctx.cfg.readme, xstrdup(value)); 121 string_list_append(&ctx.cfg.readme, xstrdup(value));
119 else if (!strcmp(name, "root-title")) 122 else if (!strcmp(name, "root-title"))
@@ -280,8 +283,8 @@ static void config_cb(const char *name, const char *value)
280 ctx.cfg.branch_sort = 1; 283 ctx.cfg.branch_sort = 1;
281 if (!strcmp(value, "name")) 284 if (!strcmp(value, "name"))
282 ctx.cfg.branch_sort = 0; 285 ctx.cfg.branch_sort = 0;
283 } else if (starts_with(name, "mimetype.")) 286 } else if (skip_prefix(name, "mimetype.", &arg))
284 add_mimetype(name + 9, value); 287 add_mimetype(arg, value);
285 else if (!strcmp(name, "include")) 288 else if (!strcmp(name, "include"))
286 parse_configfile(expand_macros(value), config_cb); 289 parse_configfile(expand_macros(value), config_cb);
287} 290}
@@ -470,13 +473,13 @@ static char *find_default_branch(struct cgit_repo *repo)
470 473
471static char *guess_defbranch(void) 474static char *guess_defbranch(void)
472{ 475{
473 const char *ref; 476 const char *ref, *refname;
474 struct object_id oid; 477 struct object_id oid;
475 478
476 ref = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL); 479 ref = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL);
477 if (!ref || !starts_with(ref, "refs/heads/")) 480 if (!ref || !skip_prefix(ref, "refs/heads/", &refname))
478 return "master"; 481 return "master";
479 return xstrdup(ref + 11); 482 return xstrdup(refname);
480} 483}
481 484
482/* The caller must free filename and ref after calling this. */ 485/* The caller must free filename and ref after calling this. */
@@ -938,6 +941,7 @@ out:
938static void cgit_parse_args(int argc, const char **argv) 941static void cgit_parse_args(int argc, const char **argv)
939{ 942{
940 int i; 943 int i;
944 const char *arg;
941 int scan = 0; 945 int scan = 0;
942 946
943 for (i = 1; i < argc; i++) { 947 for (i = 1; i < argc; i++) {
@@ -958,28 +962,28 @@ static void cgit_parse_args(int argc, const char **argv)
958 962
959 exit(0); 963 exit(0);
960 } 964 }
961 if (starts_with(argv[i], "--cache=")) { 965 if (skip_prefix(argv[i], "--cache=", &arg)) {
962 ctx.cfg.cache_root = xstrdup(argv[i] + 8); 966 ctx.cfg.cache_root = xstrdup(arg);
963 } else if (!strcmp(argv[i], "--nocache")) { 967 } else if (!strcmp(argv[i], "--nocache")) {
964 ctx.cfg.nocache = 1; 968 ctx.cfg.nocache = 1;
965 } else if (!strcmp(argv[i], "--nohttp")) { 969 } else if (!strcmp(argv[i], "--nohttp")) {
966 ctx.env.no_http = "1"; 970 ctx.env.no_http = "1";
967 } else if (starts_with(argv[i], "--query=")) { 971 } else if (skip_prefix(argv[i], "--query=", &arg)) {
968 ctx.qry.raw = xstrdup(argv[i] + 8); 972 ctx.qry.raw = xstrdup(arg);
969 } else if (starts_with(argv[i], "--repo=")) { 973 } else if (skip_prefix(argv[i], "--repo=", &arg)) {
970 ctx.qry.repo = xstrdup(argv[i] + 7); 974 ctx.qry.repo = xstrdup(arg);
971 } else if (starts_with(argv[i], "--page=")) { 975 } else if (skip_prefix(argv[i], "--page=", &arg)) {
972 ctx.qry.page = xstrdup(argv[i] + 7); 976 ctx.qry.page = xstrdup(arg);
973 } else if (starts_with(argv[i], "--head=")) { 977 } else if (skip_prefix(argv[i], "--head=", &arg)) {
974 ctx.qry.head = xstrdup(argv[i] + 7); 978 ctx.qry.head = xstrdup(arg);
975 ctx.qry.has_symref = 1; 979 ctx.qry.has_symref = 1;
976 } else if (starts_with(argv[i], "--sha1=")) { 980 } else if (skip_prefix(argv[i], "--sha1=", &arg)) {
977 ctx.qry.sha1 = xstrdup(argv[i] + 7); 981 ctx.qry.sha1 = xstrdup(arg);
978 ctx.qry.has_sha1 = 1; 982 ctx.qry.has_sha1 = 1;
979 } else if (starts_with(argv[i], "--ofs=")) { 983 } else if (skip_prefix(argv[i], "--ofs=", &arg)) {
980 ctx.qry.ofs = atoi(argv[i] + 6); 984 ctx.qry.ofs = atoi(arg);
981 } else if (starts_with(argv[i], "--scan-tree=") || 985 } else if (skip_prefix(argv[i], "--scan-tree=", &arg) ||
982 starts_with(argv[i], "--scan-path=")) { 986 skip_prefix(argv[i], "--scan-path=", &arg)) {
983 /* 987 /*
984 * HACK: The global snapshot bit mask defines the set 988 * HACK: The global snapshot bit mask defines the set
985 * of allowed snapshot formats, but the config file 989 * of allowed snapshot formats, but the config file
@@ -993,7 +997,7 @@ static void cgit_parse_args(int argc, const char **argv)
993 */ 997 */
994 ctx.cfg.snapshots = 0xFF; 998 ctx.cfg.snapshots = 0xFF;
995 scan++; 999 scan++;
996 scan_tree(argv[i] + 12, repo_config); 1000 scan_tree(arg, repo_config);
997 } 1001 }
998 } 1002 }
999 if (scan) { 1003 if (scan) {