From c1572bb5ec4540b5008490cf471cc4a5e65ef728 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sat, 31 Mar 2018 14:20:01 +0100 Subject: Add "snapshot-prefix" repo configuration Allow using a user-specified value for the prefix in snapshot files instead of the repository basename. For example, files downloaded from the linux-stable.git repository should be named linux-$VERSION and not linux-stable-$VERSION, which can be achieved by setting: repo.snapshot-prefix=linux Signed-off-by: John Keeping Reviewed-by: Christian Hesse --- cgit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index bd9cb3f..d2f7b9c 100644 --- a/cgit.c +++ b/cgit.c @@ -79,6 +79,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va item->util = xstrdup(value); } else if (!strcmp(name, "section")) repo->section = xstrdup(value); + else if (!strcmp(name, "snapshot-prefix")) + repo->snapshot_prefix = xstrdup(value); else if (!strcmp(name, "readme") && value != NULL) { if (repo->readme.items == ctx.cfg.readme.items) memset(&repo->readme, 0, sizeof(repo->readme)); -- cgit v1.2.3-24-g4f1b From 2f8648ff7f5c7119ab035c134504f04eefe068fb Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 11 Jun 2018 08:26:59 +0200 Subject: snapshot: strip bit from struct cgit_snapshot_format We had a static bit value in struct cgit_snapshot_format. We do not rely on it and things can be calculated on the fly. So strip it. Signed-off-by: Christian Hesse --- cgit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index d2f7b9c..ca0a89c 100644 --- a/cgit.c +++ b/cgit.c @@ -765,7 +765,7 @@ static char *build_snapshot_setting(int bitmap) struct strbuf result = STRBUF_INIT; for (f = cgit_snapshot_formats; f->suffix; f++) { - if (f->bit & bitmap) { + if (cgit_snapshot_format_bit(f) & bitmap) { if (result.len) strbuf_addch(&result, ' '); strbuf_addstr(&result, f->suffix); -- cgit v1.2.3-24-g4f1b From 54d37dc154f5308459df0a90c81dabd0245b6c17 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Mon, 18 Jun 2018 11:48:43 +0200 Subject: global: remove functionality we deprecated for cgit v1.0 The man page states these were deprecated for v1.0. We are past v1.1, so remove the functionality. Signed-off-by: Christian Hesse Reviewed-by: John Keeping --- cgit.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index ca0a89c..223dfc8 100644 --- a/cgit.c +++ b/cgit.c @@ -111,7 +111,7 @@ static void config_cb(const char *name, const char *value) { const char *arg; - if (!strcmp(name, "section") || !strcmp(name, "repo.group")) + if (!strcmp(name, "section")) ctx.cfg.section = xstrdup(value); else if (!strcmp(name, "repo.url")) ctx.repo = cgit_add_repo(value); @@ -139,20 +139,14 @@ static void config_cb(const char *name, const char *value) ctx.cfg.header = xstrdup(value); else if (!strcmp(name, "logo")) ctx.cfg.logo = xstrdup(value); - else if (!strcmp(name, "index-header")) - ctx.cfg.index_header = xstrdup(value); - else if (!strcmp(name, "index-info")) - ctx.cfg.index_info = xstrdup(value); else if (!strcmp(name, "logo-link")) ctx.cfg.logo_link = xstrdup(value); else if (!strcmp(name, "module-link")) ctx.cfg.module_link = xstrdup(value); else if (!strcmp(name, "strict-export")) ctx.cfg.strict_export = xstrdup(value); - else if (!strcmp(name, "virtual-root")) { + else if (!strcmp(name, "virtual-root")) ctx.cfg.virtual_root = ensure_end(value, '/'); - } else if (!strcmp(name, "nocache")) - ctx.cfg.nocache = atoi(value); else if (!strcmp(name, "noplainemail")) ctx.cfg.noplainemail = atoi(value); else if (!strcmp(name, "noheader")) @@ -236,7 +230,7 @@ static void config_cb(const char *name, const char *value) else if (!strcmp(name, "project-list")) ctx.cfg.project_list = xstrdup(expand_macros(value)); else if (!strcmp(name, "scan-path")) - if (!ctx.cfg.nocache && ctx.cfg.cache_size) + if (ctx.cfg.cache_size) process_cached_repolist(expand_macros(value)); else if (ctx.cfg.project_list) scan_projects(expand_macros(value), @@ -355,7 +349,6 @@ static void prepare_context(void) { memset(&ctx, 0, sizeof(ctx)); ctx.cfg.agefile = "info/web/last-modified"; - ctx.cfg.nocache = 0; ctx.cfg.cache_size = 0; ctx.cfg.cache_max_create_time = 5; ctx.cfg.cache_root = CGIT_CACHE_ROOT; @@ -973,8 +966,6 @@ static void cgit_parse_args(int argc, const char **argv) } if (skip_prefix(argv[i], "--cache=", &arg)) { ctx.cfg.cache_root = xstrdup(arg); - } else if (!strcmp(argv[i], "--nocache")) { - ctx.cfg.nocache = 1; } else if (!strcmp(argv[i], "--nohttp")) { ctx.env.no_http = "1"; } else if (skip_prefix(argv[i], "--query=", &arg)) { @@ -1095,8 +1086,6 @@ int cmd_main(int argc, const char **argv) else ctx.page.expires += ttl * 60; if (!ctx.env.authenticated || (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))) - ctx.cfg.nocache = 1; - if (ctx.cfg.nocache) ctx.cfg.cache_size = 0; err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, ctx.qry.raw, ttl, process_request); -- cgit v1.2.3-24-g4f1b From c4fbb99cee30fa295e240b429b2dc7e8ad83d535 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Wed, 20 Jun 2018 18:12:09 +0800 Subject: Use string list strdup_strings for mimetypes There's no need to do this manually with the string list API will do it for us. Signed-off-by: John Keeping --- cgit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index 223dfc8..0c9f3e9 100644 --- a/cgit.c +++ b/cgit.c @@ -23,7 +23,7 @@ static void add_mimetype(const char *name, const char *value) { struct string_list_item *item; - item = string_list_insert(&ctx.cfg.mimetypes, xstrdup(name)); + item = string_list_insert(&ctx.cfg.mimetypes, name); item->util = xstrdup(value); } @@ -414,7 +414,7 @@ static void prepare_context(void) ctx.page.modified = time(NULL); ctx.page.expires = ctx.page.modified; ctx.page.etag = NULL; - memset(&ctx.cfg.mimetypes, 0, sizeof(struct string_list)); + string_list_init(&ctx.cfg.mimetypes, 1); if (ctx.env.script_name) ctx.cfg.script_name = xstrdup(ctx.env.script_name); if (ctx.env.query_string) -- cgit v1.2.3-24-g4f1b From b522a302c9c4fb9fd9e1ea829ee990afc74980ca Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 12 Feb 2018 23:10:06 +0100 Subject: extra-head-content: introduce another option for meta tags This is to support things like go-import meta tags, which are on a per-repo basis. Signed-off-by: Jason A. Donenfeld --- cgit.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index 0c9f3e9..e2d7891 100644 --- a/cgit.c +++ b/cgit.c @@ -46,6 +46,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->homepage = xstrdup(value); else if (!strcmp(name, "defbranch")) repo->defbranch = xstrdup(value); + else if (!strcmp(name, "extra-head-content")) + repo->extra_head_content = xstrdup(value); else if (!strcmp(name, "snapshots")) repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-commit-graph")) @@ -797,6 +799,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) } if (repo->defbranch) fprintf(f, "repo.defbranch=%s\n", repo->defbranch); + if (repo->extra_head_content) + fprintf(f, "repo.extra-head-content=%s\n", repo->extra_head_content); if (repo->module_link) fprintf(f, "repo.module-link=%s\n", repo->module_link); if (repo->section) -- cgit v1.2.3-24-g4f1b From 93a2c3305190ca87cc1a6c98868c251ef67c3f37 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 14 Jul 2018 05:09:27 +0200 Subject: auth-filter: do not write more than we've read Signed-off-by: Jason A. Donenfeld --- cgit.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index e2d7891..fda0aa4 100644 --- a/cgit.c +++ b/cgit.c @@ -659,13 +659,13 @@ static inline void open_auth_filter(const char *function) static inline void authenticate_post(void) { char buffer[MAX_AUTHENTICATION_POST_BYTES]; - unsigned int len; + ssize_t len; open_auth_filter("authenticate-post"); len = ctx.env.content_length; if (len > MAX_AUTHENTICATION_POST_BYTES) len = MAX_AUTHENTICATION_POST_BYTES; - if (read(STDIN_FILENO, buffer, len) < 0) + if ((len = read(STDIN_FILENO, buffer, len)) < 0) die_errno("Could not read POST from stdin"); if (write(STDOUT_FILENO, buffer, len) < 0) die_errno("Could not write POST to stdout"); -- cgit v1.2.3-24-g4f1b From c679d9010451b986bae719a6abe0458af2b2dfb9 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Tue, 17 Jul 2018 12:38:22 -0400 Subject: config: record repo.snapshot-prefix in the per-repo config Even if we find snapshot-prefix in the repo configuration, we are not writing it out into the rc- file, so setting the value does not have any effect. Signed-off-by: Konstantin Ryabitsev --- cgit.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cgit.c') diff --git a/cgit.c b/cgit.c index fda0aa4..6301b87 100644 --- a/cgit.c +++ b/cgit.c @@ -830,6 +830,8 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.snapshots=%s\n", tmp ? tmp : ""); free(tmp); } + if (repo->snapshot_prefix) + fprintf(f, "repo.snapshot-prefix=%s\n", repo->snapshot_prefix); if (repo->max_stats != ctx.cfg.max_stats) fprintf(f, "repo.max-stats=%s\n", cgit_find_stats_periodname(repo->max_stats)); -- cgit v1.2.3-24-g4f1b