Skip to content

Commit 17e4642

Browse files
iabervongitster
authored andcommitted
Add flag to make unpack_trees() not print errors.
(This applies only to errors where a plausible operation is impossible due to the particular data, not to errors resulting from misuse of the merge functions.) This will allow builtin-checkout to suppress merge errors if it's going to try more merging methods. Additionally, if unpack_trees() returns with an error, but without printing anything, it will roll back any changes to the index (by rereading the index, currently). This obviously could be done by the caller, but chances are that the caller would forget and debugging this is difficult. Also, future implementations may give unpack_trees() a more efficient way of undoing its changes than the caller could. Signed-off-by: Daniel Barkalow <[email protected]>
1 parent 203a2fe commit 17e4642

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

unpack-trees.c

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,23 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
356356
posns[i] = create_tree_entry_list(t+i);
357357

358358
if (unpack_trees_rec(posns, len, o->prefix ? o->prefix : "",
359-
o, &df_conflict_list))
359+
o, &df_conflict_list)) {
360+
if (o->gently) {
361+
discard_cache();
362+
read_cache();
363+
}
360364
return -1;
365+
}
361366
}
362367

363-
if (o->trivial_merges_only && o->nontrivial_merge)
364-
return error("Merge requires file-level merging");
368+
if (o->trivial_merges_only && o->nontrivial_merge) {
369+
if (o->gently) {
370+
discard_cache();
371+
read_cache();
372+
}
373+
return o->gently ? -1 :
374+
error("Merge requires file-level merging");
375+
}
365376

366377
check_updates(active_cache, active_nr, o);
367378
return 0;
@@ -415,7 +426,8 @@ static int verify_uptodate(struct cache_entry *ce,
415426
}
416427
if (errno == ENOENT)
417428
return 0;
418-
return error("Entry '%s' not uptodate. Cannot merge.", ce->name);
429+
return o->gently ? -1 :
430+
error("Entry '%s' not uptodate. Cannot merge.", ce->name);
419431
}
420432

421433
static void invalidate_ce_path(struct cache_entry *ce)
@@ -501,8 +513,9 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action,
501513
d.exclude_per_dir = o->dir->exclude_per_dir;
502514
i = read_directory(&d, ce->name, pathbuf, namelen+1, NULL);
503515
if (i)
504-
return error("Updating '%s' would lose untracked files in it",
505-
ce->name);
516+
return o->gently ? -1 :
517+
error("Updating '%s' would lose untracked files in it",
518+
ce->name);
506519
free(pathbuf);
507520
return cnt;
508521
}
@@ -574,8 +587,9 @@ static int verify_absent(struct cache_entry *ce, const char *action,
574587
return 0;
575588
}
576589

577-
return error("Untracked working tree file '%s' "
578-
"would be %s by merge.", ce->name, action);
590+
return o->gently ? -1 :
591+
error("Untracked working tree file '%s' "
592+
"would be %s by merge.", ce->name, action);
579593
}
580594
return 0;
581595
}
@@ -707,15 +721,15 @@ int threeway_merge(struct cache_entry **stages,
707721
/* #14, #14ALT, #2ALT */
708722
if (remote && !df_conflict_head && head_match && !remote_match) {
709723
if (index && !same(index, remote) && !same(index, head))
710-
return reject_merge(index);
724+
return o->gently ? -1 : reject_merge(index);
711725
return merged_entry(remote, index, o);
712726
}
713727
/*
714728
* If we have an entry in the index cache, then we want to
715729
* make sure that it matches head.
716730
*/
717731
if (index && !same(index, head)) {
718-
return reject_merge(index);
732+
return o->gently ? -1 : reject_merge(index);
719733
}
720734

721735
if (head) {
@@ -866,11 +880,11 @@ int twoway_merge(struct cache_entry **src,
866880
/* all other failures */
867881
remove_entry(remove);
868882
if (oldtree)
869-
return reject_merge(oldtree);
883+
return o->gently ? -1 : reject_merge(oldtree);
870884
if (current)
871-
return reject_merge(current);
885+
return o->gently ? -1 : reject_merge(current);
872886
if (newtree)
873-
return reject_merge(newtree);
887+
return o->gently ? -1 : reject_merge(newtree);
874888
return -1;
875889
}
876890
}
@@ -897,7 +911,8 @@ int bind_merge(struct cache_entry **src,
897911
return error("Cannot do a bind merge of %d trees\n",
898912
o->merge_size);
899913
if (a && old)
900-
return error("Entry '%s' overlaps. Cannot bind.", a->name);
914+
return o->gently ? -1 :
915+
error("Entry '%s' overlaps. Cannot bind.", a->name);
901916
if (!a)
902917
return keep_entry(old, o);
903918
else

unpack-trees.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct unpack_trees_options {
1616
int trivial_merges_only;
1717
int verbose_update;
1818
int aggressive;
19+
int gently;
1920
const char *prefix;
2021
int pos;
2122
struct dir_struct *dir;

0 commit comments

Comments
 (0)