Introduce a configuration option enable-switch-form that is enabled by default and can be used to disable the branch quick switch form in the top-right corner of repository pages.
Rationale: For repositories with a huge number of branches, the code generated for the switch form might become so large that it dominates the size of the HTTP response. For example, at the time of writing this commit message, the HTTP body of the Arch Linux community.git cgit index at https://projects.archlinux.org/svntogit/community.git/ has a size of 228KB. Removing the form shrinks the size to only 12KB. Signed-off-by: Lukas Fleischer <[email protected]> --- I am not totally happy with the name but I did not come up with anything more expressive that is short enough at the same time. Suggestions welcome! cgit.c | 6 ++++++ cgit.h | 2 ++ cgitrc.5.txt | 9 +++++++++ shared.c | 1 + ui-shared.c | 2 +- 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cgit.c b/cgit.c index 431e325..58dd200 100644 --- a/cgit.c +++ b/cgit.c @@ -55,6 +55,8 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) repo->enable_subject_links = atoi(value); + else if (!strcmp(name, "enable-switch-form")) + repo->enable_switch_form = atoi(value); else if (!strcmp(name, "branch-sort")) { if (!strcmp(value, "age")) repo->branch_sort = 1; @@ -168,6 +170,8 @@ static void config_cb(const char *name, const char *value) ctx.cfg.enable_remote_branches = atoi(value); else if (!strcmp(name, "enable-subject-links")) ctx.cfg.enable_subject_links = atoi(value); + else if (!strcmp(name, "enable-switch-form")) + ctx.cfg.enable_switch_form = atoi(value); else if (!strcmp(name, "enable-tree-linenumbers")) ctx.cfg.enable_tree_linenumbers = atoi(value); else if (!strcmp(name, "enable-git-config")) @@ -362,6 +366,7 @@ static void prepare_context(void) ctx.cfg.enable_index_owner = 1; ctx.cfg.enable_tree_linenumbers = 1; ctx.cfg.enable_git_config = 0; + ctx.cfg.enable_switch_form = 1; ctx.cfg.max_repo_count = 50; ctx.cfg.max_commit_count = 50; ctx.cfg.max_lock_attempts = 5; @@ -824,6 +829,7 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.logo-link=%s\n", repo->logo_link); fprintf(f, "repo.enable-remote-branches=%d\n", repo->enable_remote_branches); fprintf(f, "repo.enable-subject-links=%d\n", repo->enable_subject_links); + fprintf(f, "repo.enable-switch-form=%d\n", repo->enable_switch_form); if (repo->branch_sort == 1) fprintf(f, "repo.branch-sort=age\n"); if (repo->commit_sort) { diff --git a/cgit.h b/cgit.h index 16f8092..c3c56dd 100644 --- a/cgit.h +++ b/cgit.h @@ -96,6 +96,7 @@ struct cgit_repo { int enable_log_linecount; int enable_remote_branches; int enable_subject_links; + int enable_switch_form; int max_stats; int branch_sort; int commit_sort; @@ -229,6 +230,7 @@ struct cgit_config { int enable_log_linecount; int enable_remote_branches; int enable_subject_links; + int enable_switch_form; int enable_tree_linenumbers; int enable_git_config; int local_time; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index e21ece9..b99b787 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -186,6 +186,11 @@ enable-subject-links:: in commit view. Default value: "0". See also: "repo.enable-subject-links". +enable-switch-form:: + Flag which, when set to "1", will make cgit add a form to the top right + of each repository page that allows for quickly switching branches. + Default value: "1". See also: "repo.enable-switch-form". + enable-tree-linenumbers:: Flag which, when set to "1", will make cgit generate linenumber links for plaintext blobs printed in the tree view. Default value: "1". @@ -509,6 +514,10 @@ repo.enable-subject-links:: A flag which can be used to override the global setting `enable-subject-links'. Default value: none. +repo.enable-switch-form:: + A flag which can be used to override the global setting + `enable-switch-form'. Default value: none. + repo.hide:: Flag which, when set to "1", hides the repository from the repository index. The repository can still be accessed by providing a direct path. diff --git a/shared.c b/shared.c index ae17d78..ad38c88 100644 --- a/shared.c +++ b/shared.c @@ -62,6 +62,7 @@ struct cgit_repo *cgit_add_repo(const char *url) ret->enable_log_linecount = ctx.cfg.enable_log_linecount; ret->enable_remote_branches = ctx.cfg.enable_remote_branches; ret->enable_subject_links = ctx.cfg.enable_subject_links; + ret->enable_switch_form = ctx.cfg.enable_switch_form; ret->max_stats = ctx.cfg.max_stats; ret->branch_sort = ctx.cfg.branch_sort; ret->commit_sort = ctx.cfg.commit_sort; diff --git a/ui-shared.c b/ui-shared.c index 1a84afc..874bfa4 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -871,7 +871,7 @@ static void print_header(void) cgit_index_link("index", NULL, NULL, NULL, NULL, 0); html(" : "); cgit_summary_link(ctx.repo->name, ctx.repo->name, NULL, NULL); - if (ctx.env.authenticated) { + if (ctx.env.authenticated && ctx.repo->enable_switch_form) { html("</td><td class='form'>"); html("<form method='get' action=''>\n"); cgit_add_hidden_formfields(0, 1, ctx.qry.page); -- 2.3.0 _______________________________________________ CGit mailing list [email protected] http://lists.zx2c4.com/mailman/listinfo/cgit
