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 <alexhenrie24@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Alex Henrie committed
Feb 11, 2022 at 09:36 UTC
087c745833be1edd3b3e4d8ea5d8b1a09fc6c245
5 files changed
+87
-4
builtin/blame.c
+1
@@ -934,6 +934,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
934
parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
935
}
936
parse_done:
937
+ revision_opts_finish(&revs);
938
no_whole_file_rename = !revs.diffopt.flags.follow_renames;
939
xdl_opts |= revs.diffopt.xdl_opts & XDF_INDENT_HEURISTIC;
940
revs.diffopt.flags.follow_renames = 0;
builtin/shortlog.c
+1
@@ -388,6 +388,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
388
parse_revision_opt(&rev, &ctx, options, shortlog_usage);
389
}
390
parse_done:
391
+ revision_opts_finish(&rev);
392
argc = parse_options_end(&ctx);
393
394
if (nongit && argc > 1) {
revision.c
+15
-4
@@ -2424,10 +2424,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
2424
revs->pretty_given = 1;
2425
revs->abbrev_commit = 1;
2426
} else if (!strcmp(arg, "--graph")) {
2427
- revs->topo_order = 1;
2428
- revs->rewrite_parents = 1;
2427
graph_clear(revs->graph);
2428
revs->graph = graph_init(revs);
2429
+ } else if (!strcmp(arg, "--no-graph")) {
2430
+ graph_clear(revs->graph);
2431
+ revs->graph = NULL;
2432
} else if (!strcmp(arg, "--encode-email-headers")) {
2433
revs->encode_email_headers = 1;
2434
} 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
2525
unkv[(*unkc)++] = arg;
2526
return opts;
2527
}
2527
- if (revs->graph && revs->track_linear)
2528
- die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph");
2528
2529
return 1;
2530
}
@@ -2544,6 +2543,17 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
2543
ctx->argc -= n;
2544
}
2545
2546
+void revision_opts_finish(struct rev_info *revs)
2547
+{
2548
+ if (revs->graph && revs->track_linear)
2549
+ die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph");
2550
+
2551
+ if (revs->graph) {
2552
+ revs->topo_order = 1;
2553
+ revs->rewrite_parents = 1;
2554
+ }
2555
+}
2556
+
2557
static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn,
2558
void *cb_data, const char *term)
2559
{
@@ -2786,6 +2796,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
2796
break;
2797
}
2798
}
2799
+ revision_opts_finish(revs);
2800
2801
if (prune_data.nr) {
2802
/*
revision.h
+1
@@ -372,6 +372,7 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
372
#define REVARG_COMMITTISH 02
373
int handle_revision_arg(const char *arg, struct rev_info *revs,
374
int flags, unsigned revarg_opt);
375
+void revision_opts_finish(struct rev_info *revs);
376
377
/**
378
* Reset the flags used by the revision walking api. You can use this to do
t/t4202-log.sh
+69
@@ -1671,6 +1671,75 @@ test_expect_success 'log --graph with --name-only' '
1671
test_cmp_graph --name-only tangle..reach
1672
'
1673
1674
+test_expect_success '--no-graph countermands --graph' '
1675
+ git log >expect &&
1676
+ git log --graph --no-graph >actual &&
1677
+ test_cmp expect actual
1678
+'
1679
+
1680
+test_expect_success '--graph countermands --no-graph' '
1681
+ git log --graph >expect &&
1682
+ git log --no-graph --graph >actual &&
1683
+ test_cmp expect actual
1684
+'
1685
+
1686
+test_expect_success '--no-graph does not unset --topo-order' '
1687
+ git log --topo-order >expect &&
1688
+ git log --topo-order --no-graph >actual &&
1689
+ test_cmp expect actual
1690
+'
1691
+
1692
+test_expect_success '--no-graph does not unset --parents' '
1693
+ git log --parents >expect &&
1694
+ git log --parents --no-graph >actual &&
1695
+ test_cmp expect actual
1696
+'
1697
+
1698
+test_expect_success '--reverse and --graph conflict' '
1699
+ test_must_fail git log --reverse --graph 2>stderr &&
1700
+ test_i18ngrep "cannot be used together" stderr
1701
+'
1702
+
1703
+test_expect_success '--reverse --graph --no-graph works' '
1704
+ git log --reverse >expect &&
1705
+ git log --reverse --graph --no-graph >actual &&
1706
+ test_cmp expect actual
1707
+'
1708
+
1709
+test_expect_success '--show-linear-break and --graph conflict' '
1710
+ test_must_fail git log --show-linear-break --graph 2>stderr &&
1711
+ test_i18ngrep "cannot be used together" stderr
1712
+'
1713
+
1714
+test_expect_success '--show-linear-break --graph --no-graph works' '
1715
+ git log --show-linear-break >expect &&
1716
+ git log --show-linear-break --graph --no-graph >actual &&
1717
+ test_cmp expect actual
1718
+'
1719
+
1720
+test_expect_success '--no-walk and --graph conflict' '
1721
+ test_must_fail git log --no-walk --graph 2>stderr &&
1722
+ test_i18ngrep "cannot be used together" stderr
1723
+'
1724
+
1725
+test_expect_success '--no-walk --graph --no-graph works' '
1726
+ git log --no-walk >expect &&
1727
+ git log --no-walk --graph --no-graph >actual &&
1728
+ test_cmp expect actual
1729
+'
1730
+
1731
+test_expect_success '--walk-reflogs and --graph conflict' '
1732
+ test_must_fail git log --walk-reflogs --graph 2>stderr &&
1733
+ (test_i18ngrep "cannot combine" stderr ||
1734
+ test_i18ngrep "cannot be used together" stderr)
1735
+'
1736
+
1737
+test_expect_success '--walk-reflogs --graph --no-graph works' '
1738
+ git log --walk-reflogs >expect &&
1739
+ git log --walk-reflogs --graph --no-graph >actual &&
1740
+ test_cmp expect actual
1741
+'
1742
+
1743
test_expect_success 'dotdot is a parent directory' '
1744
mkdir -p a/b &&
1745
( echo sixth && echo fifth ) >expect &&