From dccf6c16f1cee485f05ef42ba67a9309c358a78d Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Fri, 11 Feb 2022 09:36:24 -0700 Subject: log: fix memory leak if --graph is passed multiple times Signed-off-by: Alex Henrie Signed-off-by: Junio C Hamano --- revision.c | 1 + 1 file changed, 1 insertion(+) (limited to 'revision.c') diff --git a/revision.c b/revision.c index ad4286fbdd..816061f3d9 100644 --- a/revision.c +++ b/revision.c @@ -2426,6 +2426,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg } else if (!strcmp(arg, "--graph")) { revs->topo_order = 1; revs->rewrite_parents = 1; + graph_clear(revs->graph); revs->graph = graph_init(revs); } else if (!strcmp(arg, "--encode-email-headers")) { revs->encode_email_headers = 1; -- cgit v1.2.3 From 087c745833be1edd3b3e4d8ea5d8b1a09fc6c245 Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Fri, 11 Feb 2022 09:36:25 -0700 Subject: log: add a --no-graph option It's useful to be able to countermand a previous --graph option, for example if `git log --graph` is run via an alias. Signed-off-by: Alex Henrie Signed-off-by: Junio C Hamano --- revision.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'revision.c') diff --git a/revision.c b/revision.c index 816061f3d9..a39fd1c278 100644 --- a/revision.c +++ b/revision.c @@ -2424,10 +2424,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->pretty_given = 1; revs->abbrev_commit = 1; } else if (!strcmp(arg, "--graph")) { - revs->topo_order = 1; - revs->rewrite_parents = 1; graph_clear(revs->graph); revs->graph = graph_init(revs); + } else if (!strcmp(arg, "--no-graph")) { + graph_clear(revs->graph); + revs->graph = NULL; } else if (!strcmp(arg, "--encode-email-headers")) { revs->encode_email_headers = 1; } else if (!strcmp(arg, "--no-encode-email-headers")) { @@ -2524,8 +2525,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg unkv[(*unkc)++] = arg; return opts; } - if (revs->graph && revs->track_linear) - die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph"); return 1; } @@ -2544,6 +2543,17 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx, ctx->argc -= n; } +void revision_opts_finish(struct rev_info *revs) +{ + if (revs->graph && revs->track_linear) + die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph"); + + if (revs->graph) { + revs->topo_order = 1; + revs->rewrite_parents = 1; + } +} + static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data, const char *term) { @@ -2786,6 +2796,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s break; } } + revision_opts_finish(revs); if (prune_data.nr) { /* -- cgit v1.2.3