Skip to content

Commit 087c745

Browse files
alexhenriegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dccf6c1 commit 087c745

File tree

5 files changed

+87
-4
lines changed

5 files changed

+87
-4
lines changed

builtin/blame.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
934934
parse_revision_opt(&revs, &ctx, options, blame_opt_usage);
935935
}
936936
parse_done:
937+
revision_opts_finish(&revs);
937938
no_whole_file_rename = !revs.diffopt.flags.follow_renames;
938939
xdl_opts |= revs.diffopt.xdl_opts & XDF_INDENT_HEURISTIC;
939940
revs.diffopt.flags.follow_renames = 0;

builtin/shortlog.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
388388
parse_revision_opt(&rev, &ctx, options, shortlog_usage);
389389
}
390390
parse_done:
391+
revision_opts_finish(&rev);
391392
argc = parse_options_end(&ctx);
392393

393394
if (nongit && argc > 1) {

revision.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,10 +2424,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
24242424
revs->pretty_given = 1;
24252425
revs->abbrev_commit = 1;
24262426
} else if (!strcmp(arg, "--graph")) {
2427-
revs->topo_order = 1;
2428-
revs->rewrite_parents = 1;
24292427
graph_clear(revs->graph);
24302428
revs->graph = graph_init(revs);
2429+
} else if (!strcmp(arg, "--no-graph")) {
2430+
graph_clear(revs->graph);
2431+
revs->graph = NULL;
24312432
} else if (!strcmp(arg, "--encode-email-headers")) {
24322433
revs->encode_email_headers = 1;
24332434
} 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
25242525
unkv[(*unkc)++] = arg;
25252526
return opts;
25262527
}
2527-
if (revs->graph && revs->track_linear)
2528-
die(_("options '%s' and '%s' cannot be used together"), "--show-linear-break", "--graph");
25292528

25302529
return 1;
25312530
}
@@ -2544,6 +2543,17 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
25442543
ctx->argc -= n;
25452544
}
25462545

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+
25472557
static int for_each_bisect_ref(struct ref_store *refs, each_ref_fn fn,
25482558
void *cb_data, const char *term)
25492559
{
@@ -2786,6 +2796,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
27862796
break;
27872797
}
27882798
}
2799+
revision_opts_finish(revs);
27892800

27902801
if (prune_data.nr) {
27912802
/*

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
372372
#define REVARG_COMMITTISH 02
373373
int handle_revision_arg(const char *arg, struct rev_info *revs,
374374
int flags, unsigned revarg_opt);
375+
void revision_opts_finish(struct rev_info *revs);
375376

376377
/**
377378
* Reset the flags used by the revision walking api. You can use this to do

t/t4202-log.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,75 @@ test_expect_success 'log --graph with --name-only' '
16711671
test_cmp_graph --name-only tangle..reach
16721672
'
16731673

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+
16741743
test_expect_success 'dotdot is a parent directory' '
16751744
mkdir -p a/b &&
16761745
( echo sixth && echo fifth ) >expect &&

0 commit comments

Comments
 (0)