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 <barkalow@iabervon.org>
Daniel Barkalow committed
Feb 7, 2008 at 11:39 UTC
17e464266701bc1453f60a80cd71d8ba55b528e6
2 files changed
+30
-14
unpack-trees.c
+29
-14
@@ -356,12 +356,23 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
356
posns[i] = create_tree_entry_list(t+i);
357
358
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
+ }
364
return -1;
365
+ }
366
}
367
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
+ }
376
377
check_updates(active_cache, active_nr, o);
378
return 0;
@@ -415,7 +426,8 @@ static int verify_uptodate(struct cache_entry *ce,
426
}
427
if (errno == ENOENT)
428
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);
431
}
432
433
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,
513
d.exclude_per_dir = o->dir->exclude_per_dir;
514
i = read_directory(&d, ce->name, pathbuf, namelen+1, NULL);
515
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);
519
free(pathbuf);
520
return cnt;
521
}
@@ -574,8 +587,9 @@ static int verify_absent(struct cache_entry *ce, const char *action,
587
return 0;
588
}
589
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);
593
}
594
return 0;
595
}
@@ -707,7 +721,7 @@ int threeway_merge(struct cache_entry **stages,
721
/* #14, #14ALT, #2ALT */
722
if (remote && !df_conflict_head && head_match && !remote_match) {
723
if (index && !same(index, remote) && !same(index, head))
710
- return reject_merge(index);
724
+ return o->gently ? -1 : reject_merge(index);
725
return merged_entry(remote, index, o);
726
}
727
/*
@@ -715,7 +729,7 @@ int threeway_merge(struct cache_entry **stages,
729
* make sure that it matches head.
730
*/
731
if (index && !same(index, head)) {
718
- return reject_merge(index);
732
+ return o->gently ? -1 : reject_merge(index);
733
}
734
735
if (head) {
@@ -866,11 +880,11 @@ int twoway_merge(struct cache_entry **src,
880
/* all other failures */
881
remove_entry(remove);
882
if (oldtree)
869
- return reject_merge(oldtree);
883
+ return o->gently ? -1 : reject_merge(oldtree);
884
if (current)
871
- return reject_merge(current);
885
+ return o->gently ? -1 : reject_merge(current);
886
if (newtree)
873
- return reject_merge(newtree);
887
+ return o->gently ? -1 : reject_merge(newtree);
888
return -1;
889
}
890
}
@@ -897,7 +911,8 @@ int bind_merge(struct cache_entry **src,
911
return error("Cannot do a bind merge of %d trees\n",
912
o->merge_size);
913
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);
916
if (!a)
917
return keep_entry(old, o);
918
else
unpack-trees.h
+1
@@ -16,6 +16,7 @@ struct unpack_trees_options {
16
int trivial_merges_only;
17
int verbose_update;
18
int aggressive;
19
+ int gently;
20
const char *prefix;
21
int pos;
22
struct dir_struct *dir;