]> git.ipfire.org Git - thirdparty/git.git/commitdiff
log: add a --no-graph option
authorAlex Henrie <alexhenrie24@gmail.com>
Fri, 11 Feb 2022 16:36:25 +0000 (09:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 11 Feb 2022 18:06:41 +0000 (10:06 -0800)
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 <alexhenrie24@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/blame.c
builtin/shortlog.c
revision.c
revision.h
t/t4202-log.sh

index 7fafeac408141bb89e5c69512c3a7f174729e4dd..ef831de5aca610183c4db0629fcc8484559fc514 100644 (file)
@@ -934,6 +934,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
        }
 parse_done:
+       revision_opts_finish(&revs);
        no_whole_file_rename = !revs.diffopt.flags.follow_renames;
        xdl_opts |= revs.diffopt.xdl_opts & XDF_INDENT_HEURISTIC;
        revs.diffopt.flags.follow_renames = 0;
index e7f7af5de3ff005150680d19761828c7b9984ecf..228d782754af33350a51ad80d855151aa7f8a6d1 100644 (file)
@@ -388,6 +388,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                parse_revision_opt(&rev, &ctx, options, shortlog_usage);
        }
 parse_done:
+       revision_opts_finish(&rev);
        argc = parse_options_end(&ctx);
 
        if (nongit && argc > 1) {
index 816061f3d9d4ffa42a61921c18f45221bdbcea42..a39fd1c278868667a75fd4e55c93da47d96ff8e9 100644 (file)
@@ -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) {
                /*
index 3f66147bfd390abdd98de4f366014bdce88179c2..5a507db2021ea3a3b848eba417de1d2e1f52bd49 100644 (file)
@@ -372,6 +372,7 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
 #define REVARG_COMMITTISH 02
 int handle_revision_arg(const char *arg, struct rev_info *revs,
                        int flags, unsigned revarg_opt);
+void revision_opts_finish(struct rev_info *revs);
 
 /**
  * Reset the flags used by the revision walking api. You can use this to do
index dc884107de49938379c8541d53ac4b869155b5dc..a7d5edf7204ff212f80ab079df27edecddf1d326 100755 (executable)
@@ -1671,6 +1671,75 @@ test_expect_success 'log --graph with --name-only' '
        test_cmp_graph --name-only tangle..reach
 '
 
+test_expect_success '--no-graph countermands --graph' '
+       git log >expect &&
+       git log --graph --no-graph >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--graph countermands --no-graph' '
+       git log --graph >expect &&
+       git log --no-graph --graph >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--no-graph does not unset --topo-order' '
+       git log --topo-order >expect &&
+       git log --topo-order --no-graph >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--no-graph does not unset --parents' '
+       git log --parents >expect &&
+       git log --parents --no-graph >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--reverse and --graph conflict' '
+       test_must_fail git log --reverse --graph 2>stderr &&
+       test_i18ngrep "cannot be used together" stderr
+'
+
+test_expect_success '--reverse --graph --no-graph works' '
+       git log --reverse >expect &&
+       git log --reverse --graph --no-graph >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--show-linear-break and --graph conflict' '
+       test_must_fail git log --show-linear-break --graph 2>stderr &&
+       test_i18ngrep "cannot be used together" stderr
+'
+
+test_expect_success '--show-linear-break --graph --no-graph works' '
+       git log --show-linear-break >expect &&
+       git log --show-linear-break --graph --no-graph >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--no-walk and --graph conflict' '
+       test_must_fail git log --no-walk --graph 2>stderr &&
+       test_i18ngrep "cannot be used together" stderr
+'
+
+test_expect_success '--no-walk --graph --no-graph works' '
+       git log --no-walk >expect &&
+       git log --no-walk --graph --no-graph >actual &&
+       test_cmp expect actual
+'
+
+test_expect_success '--walk-reflogs and --graph conflict' '
+       test_must_fail git log --walk-reflogs --graph 2>stderr &&
+       (test_i18ngrep "cannot combine" stderr ||
+               test_i18ngrep "cannot be used together" stderr)
+'
+
+test_expect_success '--walk-reflogs --graph --no-graph works' '
+       git log --walk-reflogs >expect &&
+       git log --walk-reflogs --graph --no-graph >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'dotdot is a parent directory' '
        mkdir -p a/b &&
        ( echo sixth && echo fifth ) >expect &&