Skip to content

Commit 375ac08

Browse files
peffgitster
authored andcommitted
setup_revisions(): turn on diffs for all-negative diff filter
When the user gives us a diff filter like --diff-filter=D, we need to do a tree diff even if we're not planning to show the diff result itself, in order to decide whether to show the commit at all. So there's an explicit check of revs->diffopt.filter in setup_revisions(), and we set revs->diff if any bits are set. Originally that "filter" field covered both positive capital-letter filters (like "D") and also negative lowercase filters (like "d"), so it was sufficient for both cases. But later, 75408ca (diff-filter: be more careful when looking for negative bits, 2022-01-28) split the negative bits out into a "filter_not" field. We eventually fold those into "filter", but not until diff_setup_done() is called, which happens after our explicit check. As a result, a purely negative filter like: git log --diff-filter=d failed to turn on diffs at all. But rather than fail to filter by diff, because the filter variable is eventually set, we mistakenly show no commits at all, thinking that the empty diffs were cases where nothing passed through the filter. The smallest fix here is to just have our check look for any bits in either "filter" or "filter_not". I suspect it would also be OK to reorder the function a bit to call diff_setup_done() earlier, but that risks violating some other subtle ordering dependency. So I went with the simple and safe solution here. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f93ff17 commit 375ac08

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,7 +3112,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
31123112

31133113
/* Pickaxe, diff-filter and rename following need diffs */
31143114
if ((revs->diffopt.pickaxe_opts & DIFF_PICKAXE_KINDS_MASK) ||
3115-
revs->diffopt.filter ||
3115+
revs->diffopt.filter || revs->diffopt.filter_not ||
31163116
revs->diffopt.flags.follow_renames)
31173117
revs->diff = 1;
31183118

t/t4202-log.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ test_expect_success 'diff-filter=D' '
134134
135135
'
136136

137+
test_expect_success 'all-negative filter' '
138+
git log --no-renames --format=%s --diff-filter=d HEAD >actual &&
139+
printf "%s\n" fifth fourth third second initial >expect &&
140+
test_cmp expect actual
141+
'
142+
137143
test_expect_success 'diff-filter=R' '
138144
139145
git log -M --pretty="format:%s" --diff-filter=R HEAD >actual &&

0 commit comments

Comments
 (0)