Skip to content

Commit af63b54

Browse files
peffgitster
authored andcommitted
do not run pager with diff --no-index --quiet
There is no point in running a pager when --quiet is given, since we are producing no output. The regular diff code path handles this already, because --quiet implies --exit-code, and we check for --exit-code when deciding not to run the pager. However, the "quiet implies exit-code" logic is done in diff_setup_done, and the no-index code path sets up its pager before running diff_setup_done, and misses this case. We can fix this by reordering our initialization. Currently we do: 1. read command line arguments into diff_options 2. Set pager if EXIT_CODE not requested 3. always set EXIT_CODE, since we are emulating traditional diff 4. call diff_setup_done We can fix the problem by moving pager initialization (step 2) after step 4. But step 3 must come after step 2 (since we want to know whether the _user_ requested --exit-code, not whether we turned it on unconditionally). So we must move both. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1af3d97 commit af63b54

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

diff-no-index.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ void diff_no_index(struct rev_info *revs,
224224
}
225225
}
226226

227-
setup_diff_pager(&revs->diffopt);
228-
229227
if (prefix) {
230228
int len = strlen(prefix);
231229
const char *paths[3];
@@ -250,13 +248,15 @@ void diff_no_index(struct rev_info *revs,
250248
if (!revs->diffopt.output_format)
251249
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
252250

253-
DIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);
254251
DIFF_OPT_SET(&revs->diffopt, NO_INDEX);
255252

256253
revs->max_count = -2;
257254
if (diff_setup_done(&revs->diffopt) < 0)
258255
die("diff_setup_done failed");
259256

257+
setup_diff_pager(&revs->diffopt);
258+
DIFF_OPT_SET(&revs->diffopt, EXIT_WITH_STATUS);
259+
260260
if (queue_diff(&revs->diffopt, revs->diffopt.pathspec.raw[0],
261261
revs->diffopt.pathspec.raw[1]))
262262
exit(1);

0 commit comments

Comments
 (0)