about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-04-26 21:11:14 +0200
committerRory& <root@rory.gay>2025-07-02 11:24:54 +0200
commit1a082bc56f5810046e6d84681ef8bfc6377c2a85 (patch)
treeb1e925f041d9bb434a162be904da4c357436c9cd
parentFix change header class (diff)
downloadcgit-magenta-1a082bc56f5810046e6d84681ef8bfc6377c2a85.tar.xz
WIP: Add config bits for tarball compression settings
-rw-r--r--cgit.c34
-rw-r--r--cgit.h12
-rw-r--r--ui-snapshot.c8
3 files changed, 45 insertions, 9 deletions
diff --git a/cgit.c b/cgit.c

index cbb1929..63b3d4a 100644 --- a/cgit.c +++ b/cgit.c
@@ -21,6 +21,7 @@ #include "ui-blob.h" #include "ui-summary.h" #include "scan-tree.h" +#include "ui-plain.h" const char *cgit_version = CGIT_VERSION; @@ -44,6 +45,10 @@ static void add_mimetype(const char *name, const char *value) static void process_cached_repolist(const char *path); +/// Parse a config key/value pair from git config +/// @param repo Repository the config belongs to +/// @param name Name of the argument +/// @param value Value of the argument static void repo_config(struct cgit_repo *repo, const char *name, const char *value) { const char *path; @@ -126,6 +131,9 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va } } +/// Parse a config key/value pair +/// @param name Name of the argument +/// @param value Value of the argument static void config_cb(const char *name, const char *value) { const char *arg; @@ -368,6 +376,7 @@ static void querystring_cb(const char *name, const char *value) } } +/// Prepare CGI context, set default config values static void prepare_context(void) { memset(&ctx, 0, sizeof(ctx)); @@ -443,6 +452,13 @@ static void prepare_context(void) ctx.qry.raw = xstrdup(ctx.env.query_string); if (!ctx.env.cgit_config) ctx.env.cgit_config = CGIT_CONFIG; + + // cgit-magenta: + ctx.cfg.snapshot.save_on_disk_max_idle_age = 1 * 24 * 60 * 60; // 1 day + ctx.cfg.snapshot.save_on_disk = 1; + ctx.cfg.snapshot.max_compression_threads = 0; + ctx.cfg.snapshot.compression_level_zstd = 3; + ctx.cfg.snapshot.compression_level_xz = 6; } struct refmatch { @@ -1054,9 +1070,6 @@ static int calc_ttl(void) int cmd_main(int argc, const char **argv) { - const char *path; - int err, ttl; - atexit(cgit_cleanup_filters); prepare_context(); @@ -1081,7 +1094,7 @@ int cmd_main(int argc, const char **argv) * urls without the need for rewriterules in the webserver (as * long as PATH_INFO is included in the cache lookup key). */ - path = ctx.env.path_info; + const char* path = ctx.env.path_info; if (!ctx.qry.url && path) { if (path[0] == '/') path++; @@ -1159,18 +1172,23 @@ int cmd_main(int argc, const char **argv) * auth_filter. If there is an auth_filter, the filter decides. */ authenticate_cookie(); - ttl = calc_ttl(); + int ttl = calc_ttl(); if (ttl < 0) ctx.page.expires += 10 * 365 * 24 * 60 * 60; /* 10 years */ else ctx.page.expires += ttl * 60; if (!ctx.env.authenticated || (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))) ctx.cfg.cache_size = 0; - err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, - ctx.qry.raw, ttl, process_request); + int err = cache_process(ctx.cfg.cache_size, ctx.cfg.cache_root, + ctx.qry.raw, ttl, process_request); cgit_cleanup_filters(); if (err) cgit_print_error("Error processing page: %s (%d)", strerror(err), err); + + + printf("<p>path: %s</p>\n", ctx.qry.path); + printf("<p>script_name: %s</p>\n", ctx.cfg.script_name); + printf("<p>url: %s</p>\n", ctx.qry.url); return err; -} +} \ No newline at end of file diff --git a/cgit.h b/cgit.h
index 3081576..44d74b5 100644 --- a/cgit.h +++ b/cgit.h
@@ -196,6 +196,15 @@ struct cgit_query { char *vpath; }; +struct cgit_config_snapshot +{ + bool save_on_disk; + int save_on_disk_max_idle_age; // in seconds + int max_compression_threads; + int compression_level_zstd; + int compression_level_xz; +}; + struct cgit_config { char *agefile; char *cache_root; @@ -277,6 +286,9 @@ struct cgit_config { struct cgit_filter *email_filter; struct cgit_filter *owner_filter; struct cgit_filter *auth_filter; + + // cgit-magenta: + struct cgit_config_snapshot snapshot; }; struct cgit_page { diff --git a/ui-snapshot.c b/ui-snapshot.c
index bd24879..cf8b0d8 100644 --- a/ui-snapshot.c +++ b/ui-snapshot.c
@@ -98,7 +98,13 @@ static int write_tar_xz_archive(const char *hex, const char *prefix) static int write_tar_zstd_archive(const char *hex, const char *prefix) { - char *argv[] = { "zstd", "-T0", NULL }; + int threads = ctx.cfg.snapshot.max_compression_threads; + int compress_level = ctx.cfg.snapshot.compression_level_zstd; + char *argv[] = { "zstd", xstrfmt("-T%d", threads), xstrfmt("-%d", compress_level), NULL }; + if (compress_level >= 19) { + // add --ultra flag for levels 19 and above + + } return write_compressed_tar_archive(hex, prefix, argv); }