From kian at kasad.com Fri Aug 5 04:59:33 2022 From: kian at kasad.com (Kian Kasad) Date: Thu, 4 Aug 2022 21:59:33 -0700 Subject: [PATCH 0/6] Option for separate 'log' and 'graph' pages In-Reply-To: <20211230210820.3ncgngexbbhlpbdq@frisbee.local> References: <20211230210820.3ncgngexbbhlpbdq@frisbee.local> Message-ID: <20220805045939.57987-1-kian@kasad.com> Since I never got a reply regarding whether this feature is wanted, I'm sending the patches anyways and you all can decide whether or not to merge them. The changes are backwards-compatible so all existing configurations will exhibit exactly the same behavior as before this patch series. See the first patch (1/6) for details of exactly what changes, as it's all documented in that commit's message. -- Kian Kasad kian at kasad.com (925) 871-9823 From kian at kasad.com Fri Aug 5 04:59:34 2022 From: kian at kasad.com (Kian Kasad) Date: Thu, 4 Aug 2022 21:59:34 -0700 Subject: [PATCH 1/6] Implement parsing of new enable-commit-graph option In-Reply-To: <20220805045939.57987-1-kian@kasad.com> References: <20211230210820.3ncgngexbbhlpbdq@frisbee.local> <20220805045939.57987-1-kian@kasad.com> Message-ID: <20220805045939.57987-2-kian@kasad.com> The enable-commit-graph option has been changed from a boolean option to a string option. It takes the following values: "none" or "0": Disable the display of commit graphs completely. The graph page will be disabled and the log page will not show commit graphs. "combined" or "1": Disable the graph page and show the commit graph on the log page. The commit age is still displayed in a separate column. This follows the same behavior as before when this option was set to "1". "separate": Enable the graph page and give it its own tab. The graph page is the same as the log page except it displays the commit graph *instead of* the commit age. The log page shows the commit age and not the commit graph. The "0" and "1" option values should be avoided in new configurations and only exist for backwards compatibility. --- cgit.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/cgit.c b/cgit.c index 08d81a1..ce7b291 100644 --- a/cgit.c +++ b/cgit.c @@ -62,9 +62,14 @@ static void repo_config(struct cgit_repo *repo, const char *name, const char *va repo->snapshots = ctx.cfg.snapshots & cgit_parse_snapshots_mask(value); else if (!strcmp(name, "enable-blame")) repo->enable_blame = atoi(value); - else if (!strcmp(name, "enable-commit-graph")) - repo->enable_commit_graph = atoi(value); - else if (!strcmp(name, "enable-log-filecount")) + else if (!strcmp(name, "enable-commit-graph")) { + if (!strcmp(value, "none") || !strcmp(value, "0")) + repo->enable_commit_graph = 0; + else if (!strcmp(value, "combined") || !strcmp(value, "1")) + repo->enable_commit_graph = 1; + else if (!strcmp(value, "separate")) + repo->enable_commit_graph = 2; + } else if (!strcmp(name, "enable-log-filecount")) repo->enable_log_filecount = atoi(value); else if (!strcmp(name, "enable-log-linecount")) repo->enable_log_linecount = atoi(value); @@ -179,9 +184,14 @@ static void config_cb(const char *name, const char *value) ctx.cfg.enable_index_owner = atoi(value); else if (!strcmp(name, "enable-blame")) ctx.cfg.enable_blame = atoi(value); - else if (!strcmp(name, "enable-commit-graph")) - ctx.cfg.enable_commit_graph = atoi(value); - else if (!strcmp(name, "enable-log-filecount")) + else if (!strcmp(name, "enable-commit-graph")) { + if (!strcmp(value, "none") || !strcmp(value, "0")) + ctx.cfg.enable_commit_graph = 0; + else if (!strcmp(value, "combined") || !strcmp(value, "1")) + ctx.cfg.enable_commit_graph = 1; + else if (!strcmp(value, "separate")) + ctx.cfg.enable_commit_graph = 2; + } else if (!strcmp(name, "enable-log-filecount")) ctx.cfg.enable_log_filecount = atoi(value); else if (!strcmp(name, "enable-log-linecount")) ctx.cfg.enable_log_linecount = atoi(value); @@ -818,8 +828,12 @@ static void print_repo(FILE *f, struct cgit_repo *repo) fprintf(f, "repo.clone-url=%s\n", repo->clone_url); fprintf(f, "repo.enable-blame=%d\n", repo->enable_blame); - fprintf(f, "repo.enable-commit-graph=%d\n", - repo->enable_commit_graph); + if (repo->enable_commit_graph) { + if (repo->enable_commit_graph == 1) + fprintf(f, "repo.enable-commit-graph=combined\n"); + if (repo->enable_commit_graph == 2) + fprintf(f, "repo.enable-commit-graph=separate\n"); + } fprintf(f, "repo.enable-log-filecount=%d\n", repo->enable_log_filecount); fprintf(f, "repo.enable-log-linecount=%d\n", -- 2.37.1 From kian at kasad.com Fri Aug 5 04:59:35 2022 From: kian at kasad.com (Kian Kasad) Date: Thu, 4 Aug 2022 21:59:35 -0700 Subject: [PATCH 2/6] Add graph page In-Reply-To: <20220805045939.57987-1-kian@kasad.com> References: <20211230210820.3ncgngexbbhlpbdq@frisbee.local> <20220805045939.57987-1-kian@kasad.com> Message-ID: <20220805045939.57987-3-kian@kasad.com> Adds a basic graph page which is the same as the log page except the commit graph is enabled when the 'enable-commit-graph' option is set to "separate". It does not implement the full option behavior yet. --- cmd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd.c b/cmd.c index 0eb75b1..1f86047 100644 --- a/cmd.c +++ b/cmd.c @@ -101,7 +101,15 @@ static void log_fn(void) { cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, - ctx.repo->enable_commit_graph, + (ctx.repo->enable_commit_graph == 1) ? 1 : 0, + ctx.repo->commit_sort); +} + +static void graph_fn(void) +{ + cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, + ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, + (ctx.repo->enable_commit_graph == 2) ? 1 : 0, ctx.repo->commit_sort); } @@ -179,6 +187,7 @@ struct cgit_cmd *cgit_get_cmd(void) def_cmd(diff, 1, 1, 0), def_cmd(info, 1, 0, 1), def_cmd(log, 1, 1, 0), + def_cmd(graph, 1, 1, 0), def_cmd(ls_cache, 0, 0, 0), def_cmd(objects, 1, 0, 1), def_cmd(patch, 1, 1, 0), -- 2.37.1 From kian at kasad.com Fri Aug 5 04:59:36 2022 From: kian at kasad.com (Kian Kasad) Date: Thu, 4 Aug 2022 21:59:36 -0700 Subject: [PATCH 3/6] Don't display commit age on graph page In-Reply-To: <20220805045939.57987-1-kian@kasad.com> References: <20211230210820.3ncgngexbbhlpbdq@frisbee.local> <20220805045939.57987-1-kian@kasad.com> Message-ID: <20220805045939.57987-4-kian@kasad.com> Hides the commit age column on the graph page. It is still shown on the log page, even when the "enable-commit-graph" option is set to "combined". --- cmd.c | 2 +- ui-log.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd.c b/cmd.c index 1f86047..c780895 100644 --- a/cmd.c +++ b/cmd.c @@ -109,7 +109,7 @@ static void graph_fn(void) { cgit_print_log(ctx.qry.oid, ctx.qry.ofs, ctx.cfg.max_commit_count, ctx.qry.grep, ctx.qry.search, ctx.qry.path, 1, - (ctx.repo->enable_commit_graph == 2) ? 1 : 0, + (ctx.repo->enable_commit_graph == 2) ? 2 : 0, ctx.repo->commit_sort); } diff --git a/ui-log.c b/ui-log.c index 20774bf..c795fb2 100644 --- a/ui-log.c +++ b/ui-log.c @@ -175,7 +175,7 @@ static int show_commit(struct commit *commit, struct rev_info *revs) static void print_commit(struct commit *commit, struct rev_info *revs) { struct commitinfo *info; - int columns = revs->graph ? 4 : 3; + int columns = (revs->graph && ctx.repo->enable_commit_graph == 1) ? 4 : 3; struct strbuf graphbuf = STRBUF_INIT; struct strbuf msgbuf = STRBUF_INIT; @@ -246,7 +246,7 @@ static void print_commit(struct commit *commit, struct rev_info *revs) html_txt(info->author); cgit_close_filter(ctx.repo->email_filter); - if (revs->graph) { + if (revs->graph && ctx.repo->enable_commit_graph == 1) { html("