Skip to content

Commit

Permalink
diff-index --quiet: learn the "stop feeding the backend early" logic
Browse files Browse the repository at this point in the history
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 <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed May 31, 2011
1 parent 2d11f21 commit b419482
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,13 @@ static int oneway_diff(struct cache_entry **src, struct unpack_trees_options *o)
if (tree == o->df_conflict_entry)
tree = NULL;

if (ce_path_match(idx ? idx : tree, &revs->prune_data))
if (ce_path_match(idx ? idx : tree, &revs->prune_data)) {
do_oneway_diff(o, idx, tree);
if (diff_can_quit_early(&revs->diffopt)) {
o->exiting_early = 1;
return -1;
}
}

return 0;
}
Expand Down
4 changes: 3 additions & 1 deletion unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ static int unpack_nondirectories(int n, unsigned long mask,
static int unpack_failed(struct unpack_trees_options *o, const char *message)
{
discard_index(&o->result);
if (!o->gently) {
if (!o->gently && !o->exiting_early) {
if (message)
return error("%s", message);
return -1;
Expand Down Expand Up @@ -1128,6 +1128,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
display_error_msgs(o);
mark_all_ce_unused(o->src_index);
ret = unpack_failed(o, NULL);
if (o->exiting_early)
ret = 0;
goto done;
}

Expand Down
1 change: 1 addition & 0 deletions unpack-trees.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct unpack_trees_options {
debug_unpack,
skip_sparse_checkout,
gently,
exiting_early,
show_all_errors;
const char *prefix;
int cache_bottom;
Expand Down

0 comments on commit b419482

Please sign in to comment.