Skip to content

Commit 83bb8e5

Browse files
committed
show-branch: --no-sparse should give dense output
"git show-branch --no-sparse" behaved exactly the same way as "git show-branch --sparse", which did not make any sense. This was because it used a variable "dense" initialized to 1 by default to give "non sparse" behaviour, and OPT_SET_INT() to set the varilable to 0 in response to the "--sparse" option. Unfortunately, OPT_SET_INT() sets 0 to the given variable when the option is negated. Flip the polarity of the variable "dense" by renaming it to "sparse" and initializing it to 0, and have OPT_SET_INT() set the variable to 1 when "--sparse" is given. This way, "--no-sparse" would set 0 to the variable and would give us the "dense" behaviour. Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb7d80e commit 83bb8e5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

builtin/show-branch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
645645
int with_current_branch = 0;
646646
int head_at = -1;
647647
int topics = 0;
648-
int dense = 1;
648+
int sparse = 0;
649649
const char *reflog_base = NULL;
650650
struct option builtin_show_branch_options[] = {
651651
OPT_BOOL('a', "all", &all_heads,
@@ -672,8 +672,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
672672
REV_SORT_IN_GRAPH_ORDER),
673673
OPT_BOOL(0, "topics", &topics,
674674
N_("show only commits not on the first branch")),
675-
OPT_SET_INT(0, "sparse", &dense,
676-
N_("show merges reachable from only one tip"), 0),
675+
OPT_SET_INT(0, "sparse", &sparse,
676+
N_("show merges reachable from only one tip"), 1),
677677
OPT_SET_INT(0, "date-order", &sort_order,
678678
N_("topologically sort, maintaining date order "
679679
"where possible"),
@@ -936,7 +936,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
936936
!is_merge_point &&
937937
(this_flag & (1u << REV_SHIFT)))
938938
continue;
939-
if (dense && is_merge &&
939+
if (!sparse && is_merge &&
940940
omit_in_dense(commit, rev, num_rev))
941941
continue;
942942
for (i = 0; i < num_rev; i++) {

t/t3202-show-branch.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ test_expect_success 'show branch --remotes' '
119119
test_must_be_empty actual.out
120120
'
121121

122+
test_expect_success 'show-branch --sparse' '
123+
test_when_finished "git checkout branch10 && git branch -D branchA" &&
124+
git checkout -b branchA branch10 &&
125+
git merge -s ours -m "merge 1 and 10 to make A" branch1 &&
126+
git commit --allow-empty -m "another" &&
127+
128+
git show-branch --sparse >out &&
129+
grep "merge 1 and 10 to make A" out &&
130+
131+
git show-branch >out &&
132+
! grep "merge 1 and 10 to make A" out &&
133+
134+
git show-branch --no-sparse >out &&
135+
! grep "merge 1 and 10 to make A" out
136+
'
137+
122138
test_expect_success 'setup show branch --list' '
123139
sed "s/^> //" >expect <<-\EOF
124140
> [branch1] branch1

0 commit comments

Comments
 (0)