Skip to content

Commit b419482

Browse files
committed
diff-index --quiet: learn the "stop feeding the backend early" logic
A negative return from the unpack callback function usually means unpack failed for the entry and signals the unpack_trees() machinery to fail the entire merge operation, immediately and there is no other way for the callback to tell the machinery to exit early without reporting an error. This is what we usually want to make a merge all-or-nothing operation, but the machinery is also used for diff-index codepath by using a custom unpack callback function. And we do sometimes want to exit early without failing, namely when we are under --quiet and can short-cut the diff upon finding the first difference. Add "exiting_early" field to unpack_trees_options structure, to signal the unpack_trees() machinery that the negative return value is not signaling an error but an early return from the unpack_trees() machinery. As this by definition hasn't unpacked everything, discard the resulting index just like the failure codepath. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2d11f21 commit b419482

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

diff-lib.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,13 @@ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
433433
if (tree == o->df_conflict_entry)
434434
tree = NULL;
435435

436-
if (ce_path_match(idx ? idx : tree, &revs->prune_data))
436+
if (ce_path_match(idx ? idx : tree, &revs->prune_data)) {
437437
do_oneway_diff(o, idx, tree);
438+
if (diff_can_quit_early(&revs->diffopt)) {
439+
o->exiting_early = 1;
440+
return -1;
441+
}
442+
}
438443

439444
return 0;
440445
}

unpack-trees.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ static int unpack_nondirectories(int n, unsigned long mask,
593593
static int unpack_failed(struct unpack_trees_options *o, const char *message)
594594
{
595595
discard_index(&o->result);
596-
if (!o->gently) {
596+
if (!o->gently && !o->exiting_early) {
597597
if (message)
598598
return error("%s", message);
599599
return -1;
@@ -1128,6 +1128,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
11281128
display_error_msgs(o);
11291129
mark_all_ce_unused(o->src_index);
11301130
ret = unpack_failed(o, NULL);
1131+
if (o->exiting_early)
1132+
ret = 0;
11311133
goto done;
11321134
}
11331135

unpack-trees.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct unpack_trees_options {
4646
debug_unpack,
4747
skip_sparse_checkout,
4848
gently,
49+
exiting_early,
4950
show_all_errors;
5051
const char *prefix;
5152
int cache_bottom;

0 commit comments

Comments
 (0)