1 #define NO_THE_INDEX_COMPATIBILITY_MACROS
6 #include "cache-tree.h"
7 #include "unpack-trees.h"
12 * Error messages expected by scripts out of plumbing commands such as
13 * read-tree. Non-scripted Porcelain is not required to use these messages
14 * and in fact are encouraged to reword them to better suit their particular
15 * situation better. See how "git checkout" replaces not_uptodate_file to
16 * explain why it does not allow switching between branches when you have
17 * local changes, for example.
19 static struct unpack_trees_error_msgs unpack_plumbing_errors
= {
21 "Entry '%s' would be overwritten by merge. Cannot merge.",
23 /* not_uptodate_file */
24 "Entry '%s' not uptodate. Cannot merge.",
26 /* not_uptodate_dir */
27 "Updating '%s' would lose untracked files in it",
29 /* would_lose_untracked */
30 "Untracked working tree file '%s' would be %s by merge.",
33 "Entry '%s' overlaps with '%s'. Cannot bind.",
36 #define ERRORMSG(o,fld) \
37 ( ((o) && (o)->msgs.fld) \
39 : (unpack_plumbing_errors.fld) )
41 static void add_entry(struct unpack_trees_options
*o
, struct cache_entry
*ce
,
42 unsigned int set
, unsigned int clear
)
44 unsigned int size
= ce_size(ce
);
45 struct cache_entry
*new = xmalloc(size
);
47 clear
|= CE_HASHED
| CE_UNHASHED
;
49 memcpy(new, ce
, size
);
51 new->ce_flags
= (new->ce_flags
& ~clear
) | set
;
52 add_index_entry(&o
->result
, new, ADD_CACHE_OK_TO_ADD
|ADD_CACHE_OK_TO_REPLACE
|ADD_CACHE_SKIP_DFCHECK
);
56 * Unlink the last component and schedule the leading directories for
57 * removal, such that empty directories get removed.
59 static void unlink_entry(struct cache_entry
*ce
)
61 if (has_symlink_or_noent_leading_path(ce
->name
, ce_namelen(ce
)))
65 schedule_dir_for_removal(ce
->name
, ce_namelen(ce
));
68 static struct checkout state
;
69 static int check_updates(struct unpack_trees_options
*o
)
71 unsigned cnt
= 0, total
= 0;
72 struct progress
*progress
= NULL
;
73 struct index_state
*index
= &o
->result
;
77 if (o
->update
&& o
->verbose_update
) {
78 for (total
= cnt
= 0; cnt
< index
->cache_nr
; cnt
++) {
79 struct cache_entry
*ce
= index
->cache
[cnt
];
80 if (ce
->ce_flags
& (CE_UPDATE
| CE_REMOVE
))
84 progress
= start_progress_delay("Checking out files",
89 for (i
= 0; i
< index
->cache_nr
; i
++) {
90 struct cache_entry
*ce
= index
->cache
[i
];
92 if (ce
->ce_flags
& CE_REMOVE
) {
93 display_progress(progress
, ++cnt
);
98 remove_marked_cache_entries(&o
->result
);
99 remove_scheduled_dirs();
101 for (i
= 0; i
< index
->cache_nr
; i
++) {
102 struct cache_entry
*ce
= index
->cache
[i
];
104 if (ce
->ce_flags
& CE_UPDATE
) {
105 display_progress(progress
, ++cnt
);
106 ce
->ce_flags
&= ~CE_UPDATE
;
108 errs
|= checkout_entry(ce
, &state
, NULL
);
112 stop_progress(&progress
);
116 static inline int call_unpack_fn(struct cache_entry
**src
, struct unpack_trees_options
*o
)
118 int ret
= o
->fn(src
, o
);
124 static int unpack_index_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
126 struct cache_entry
*src
[5] = { ce
, };
130 if (o
->skip_unmerged
) {
131 add_entry(o
, ce
, 0, 0);
135 return call_unpack_fn(src
, o
);
138 int traverse_trees_recursive(int n
, unsigned long dirmask
, unsigned long df_conflicts
, struct name_entry
*names
, struct traverse_info
*info
)
141 struct tree_desc t
[MAX_UNPACK_TREES
];
142 struct traverse_info newinfo
;
143 struct name_entry
*p
;
152 newinfo
.pathlen
+= tree_entry_len(p
->path
, p
->sha1
) + 1;
153 newinfo
.conflicts
|= df_conflicts
;
155 for (i
= 0; i
< n
; i
++, dirmask
>>= 1) {
156 const unsigned char *sha1
= NULL
;
158 sha1
= names
[i
].sha1
;
159 fill_tree_descriptor(t
+i
, sha1
);
161 return traverse_trees(n
, t
, &newinfo
);
165 * Compare the traverse-path to the cache entry without actually
166 * having to generate the textual representation of the traverse
169 * NOTE! This *only* compares up to the size of the traverse path
170 * itself - the caller needs to do the final check for the cache
171 * entry having more data at the end!
173 static int do_compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
175 int len
, pathlen
, ce_len
;
179 int cmp
= do_compare_entry(ce
, info
->prev
, &info
->name
);
183 pathlen
= info
->pathlen
;
184 ce_len
= ce_namelen(ce
);
186 /* If ce_len < pathlen then we must have previously hit "name == directory" entry */
187 if (ce_len
< pathlen
)
191 ce_name
= ce
->name
+ pathlen
;
193 len
= tree_entry_len(n
->path
, n
->sha1
);
194 return df_name_compare(ce_name
, ce_len
, S_IFREG
, n
->path
, len
, n
->mode
);
197 static int compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
199 int cmp
= do_compare_entry(ce
, info
, n
);
204 * Even if the beginning compared identically, the ce should
205 * compare as bigger than a directory leading up to it!
207 return ce_namelen(ce
) > traverse_path_len(info
, n
);
210 static struct cache_entry
*create_ce_entry(const struct traverse_info
*info
, const struct name_entry
*n
, int stage
)
212 int len
= traverse_path_len(info
, n
);
213 struct cache_entry
*ce
= xcalloc(1, cache_entry_size(len
));
215 ce
->ce_mode
= create_ce_mode(n
->mode
);
216 ce
->ce_flags
= create_ce_flags(len
, stage
);
217 hashcpy(ce
->sha1
, n
->sha1
);
218 make_traverse_path(ce
->name
, info
, n
);
223 static int unpack_nondirectories(int n
, unsigned long mask
,
224 unsigned long dirmask
,
225 struct cache_entry
**src
,
226 const struct name_entry
*names
,
227 const struct traverse_info
*info
)
230 struct unpack_trees_options
*o
= info
->data
;
231 unsigned long conflicts
;
233 /* Do we have *only* directories? Nothing to do */
234 if (mask
== dirmask
&& !src
[0])
237 conflicts
= info
->conflicts
;
240 conflicts
|= dirmask
;
243 * Ok, we've filled in up to any potential index entry in src[0],
246 for (i
= 0; i
< n
; i
++) {
248 unsigned int bit
= 1ul << i
;
249 if (conflicts
& bit
) {
250 src
[i
+ o
->merge
] = o
->df_conflict_entry
;
257 else if (i
+ 1 < o
->head_idx
)
259 else if (i
+ 1 > o
->head_idx
)
263 src
[i
+ o
->merge
] = create_ce_entry(info
, names
+ i
, stage
);
267 return call_unpack_fn(src
, o
);
270 for (i
= 0; i
< n
; i
++)
271 add_entry(o
, src
[i
], 0, 0);
275 static int unpack_callback(int n
, unsigned long mask
, unsigned long dirmask
, struct name_entry
*names
, struct traverse_info
*info
)
277 struct cache_entry
*src
[MAX_UNPACK_TREES
+ 1] = { NULL
, };
278 struct unpack_trees_options
*o
= info
->data
;
279 const struct name_entry
*p
= names
;
281 /* Find first entry with a real name (we could use "mask" too) */
285 /* Are we supposed to look at the index too? */
287 while (o
->pos
< o
->src_index
->cache_nr
) {
288 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
289 int cmp
= compare_entry(ce
, info
, p
);
291 if (unpack_index_entry(ce
, o
) < 0)
299 * If we skip unmerged index entries, we'll skip this
300 * entry *and* the tree entries associated with it!
302 if (o
->skip_unmerged
) {
303 add_entry(o
, ce
, 0, 0);
313 if (unpack_nondirectories(n
, mask
, dirmask
, src
, names
, info
) < 0)
316 /* Now handle any directories.. */
318 unsigned long conflicts
= mask
& ~dirmask
;
324 if (traverse_trees_recursive(n
, dirmask
, conflicts
,
333 static int unpack_failed(struct unpack_trees_options
*o
, const char *message
)
335 discard_index(&o
->result
);
338 return error("%s", message
);
345 * N-way merge "len" trees. Returns 0 on success, -1 on failure to manipulate the
346 * resulting index, -2 on failure to reflect the changes to the work tree.
348 int unpack_trees(unsigned len
, struct tree_desc
*t
, struct unpack_trees_options
*o
)
351 static struct cache_entry
*dfc
;
353 if (len
> MAX_UNPACK_TREES
)
354 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES
);
355 memset(&state
, 0, sizeof(state
));
359 state
.refresh_cache
= 1;
361 memset(&o
->result
, 0, sizeof(o
->result
));
362 o
->result
.initialized
= 1;
364 o
->result
.timestamp
.sec
= o
->src_index
->timestamp
.sec
;
366 o
->result
.timestamp
.nsec
= o
->src_index
->timestamp
.nsec
;
372 dfc
= xcalloc(1, cache_entry_size(0));
373 o
->df_conflict_entry
= dfc
;
376 const char *prefix
= o
->prefix
? o
->prefix
: "";
377 struct traverse_info info
;
379 setup_traverse_info(&info
, prefix
);
380 info
.fn
= unpack_callback
;
383 if (traverse_trees(len
, t
, &info
) < 0)
384 return unpack_failed(o
, NULL
);
387 /* Any left-over entries in the index? */
389 while (o
->pos
< o
->src_index
->cache_nr
) {
390 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
391 if (unpack_index_entry(ce
, o
) < 0)
392 return unpack_failed(o
, NULL
);
396 if (o
->trivial_merges_only
&& o
->nontrivial_merge
)
397 return unpack_failed(o
, "Merge requires file-level merging");
400 ret
= check_updates(o
) ? (-2) : 0;
402 *o
->dst_index
= o
->result
;
406 /* Here come the merge functions */
408 static int reject_merge(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
410 return error(ERRORMSG(o
, would_overwrite
), ce
->name
);
413 static int same(struct cache_entry
*a
, struct cache_entry
*b
)
419 return a
->ce_mode
== b
->ce_mode
&&
420 !hashcmp(a
->sha1
, b
->sha1
);
425 * When a CE gets turned into an unmerged entry, we
426 * want it to be up-to-date
428 static int verify_uptodate(struct cache_entry
*ce
,
429 struct unpack_trees_options
*o
)
433 if (o
->index_only
|| o
->reset
|| ce_uptodate(ce
))
436 if (!lstat(ce
->name
, &st
)) {
437 unsigned changed
= ie_match_stat(o
->src_index
, ce
, &st
, CE_MATCH_IGNORE_VALID
);
441 * NEEDSWORK: the current default policy is to allow
442 * submodule to be out of sync wrt the supermodule
443 * index. This needs to be tightened later for
444 * submodules that are marked to be automatically
447 if (S_ISGITLINK(ce
->ce_mode
))
453 return o
->gently
? -1 :
454 error(ERRORMSG(o
, not_uptodate_file
), ce
->name
);
457 static void invalidate_ce_path(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
460 cache_tree_invalidate_path(o
->src_index
->cache_tree
, ce
->name
);
464 * Check that checking out ce->sha1 in subdir ce->name is not
465 * going to overwrite any working files.
467 * Currently, git does not checkout subprojects during a superproject
468 * checkout, so it is not going to overwrite anything.
470 static int verify_clean_submodule(struct cache_entry
*ce
, const char *action
,
471 struct unpack_trees_options
*o
)
476 static int verify_clean_subdirectory(struct cache_entry
*ce
, const char *action
,
477 struct unpack_trees_options
*o
)
480 * we are about to extract "ce->name"; we would not want to lose
481 * anything in the existing directory there.
488 unsigned char sha1
[20];
490 if (S_ISGITLINK(ce
->ce_mode
) &&
491 resolve_gitlink_ref(ce
->name
, "HEAD", sha1
) == 0) {
492 /* If we are not going to update the submodule, then
495 if (!hashcmp(sha1
, ce
->sha1
))
497 return verify_clean_submodule(ce
, action
, o
);
501 * First let's make sure we do not have a local modification
504 namelen
= strlen(ce
->name
);
505 for (i
= o
->pos
; i
< o
->src_index
->cache_nr
; i
++) {
506 struct cache_entry
*ce2
= o
->src_index
->cache
[i
];
507 int len
= ce_namelen(ce2
);
509 strncmp(ce
->name
, ce2
->name
, namelen
) ||
510 ce2
->name
[namelen
] != '/')
513 * ce2->name is an entry in the subdirectory.
515 if (!ce_stage(ce2
)) {
516 if (verify_uptodate(ce2
, o
))
518 add_entry(o
, ce2
, CE_REMOVE
, 0);
524 * Then we need to make sure that we do not lose a locally
525 * present file that is not ignored.
527 pathbuf
= xmalloc(namelen
+ 2);
528 memcpy(pathbuf
, ce
->name
, namelen
);
529 strcpy(pathbuf
+namelen
, "/");
531 memset(&d
, 0, sizeof(d
));
533 d
.exclude_per_dir
= o
->dir
->exclude_per_dir
;
534 i
= read_directory(&d
, ce
->name
, pathbuf
, namelen
+1, NULL
);
536 return o
->gently
? -1 :
537 error(ERRORMSG(o
, not_uptodate_dir
), ce
->name
);
543 * This gets called when there was no index entry for the tree entry 'dst',
544 * but we found a file in the working tree that 'lstat()' said was fine,
545 * and we're on a case-insensitive filesystem.
547 * See if we can find a case-insensitive match in the index that also
548 * matches the stat information, and assume it's that other file!
550 static int icase_exists(struct unpack_trees_options
*o
, struct cache_entry
*dst
, struct stat
*st
)
552 struct cache_entry
*src
;
554 src
= index_name_exists(o
->src_index
, dst
->name
, ce_namelen(dst
), 1);
555 return src
&& !ie_match_stat(o
->src_index
, src
, st
, CE_MATCH_IGNORE_VALID
);
559 * We do not want to remove or overwrite a working tree file that
560 * is not tracked, unless it is ignored.
562 static int verify_absent(struct cache_entry
*ce
, const char *action
,
563 struct unpack_trees_options
*o
)
567 if (o
->index_only
|| o
->reset
|| !o
->update
)
570 if (has_symlink_or_noent_leading_path(ce
->name
, ce_namelen(ce
)))
573 if (!lstat(ce
->name
, &st
)) {
575 int dtype
= ce_to_dtype(ce
);
576 struct cache_entry
*result
;
579 * It may be that the 'lstat()' succeeded even though
580 * target 'ce' was absent, because there is an old
581 * entry that is different only in case..
583 * Ignore that lstat() if it matches.
585 if (ignore_case
&& icase_exists(o
, ce
, &st
))
588 if (o
->dir
&& excluded(o
->dir
, ce
->name
, &dtype
))
590 * ce->name is explicitly excluded, so it is Ok to
594 if (S_ISDIR(st
.st_mode
)) {
596 * We are checking out path "foo" and
597 * found "foo/." in the working tree.
598 * This is tricky -- if we have modified
599 * files that are in "foo/" we would lose
602 ret
= verify_clean_subdirectory(ce
, action
, o
);
607 * If this removed entries from the index,
608 * what that means is:
610 * (1) the caller unpack_callback() saw path/foo
611 * in the index, and it has not removed it because
612 * it thinks it is handling 'path' as blob with
614 * (2) we will return "ok, we placed a merged entry
615 * in the index" which would cause o->pos to be
616 * incremented by one;
617 * (3) however, original o->pos now has 'path/foo'
618 * marked with "to be removed".
620 * We need to increment it by the number of
621 * deleted entries here.
628 * The previous round may already have decided to
629 * delete this path, which is in a subdirectory that
630 * is being replaced with a blob.
632 result
= index_name_exists(&o
->result
, ce
->name
, ce_namelen(ce
), 0);
634 if (result
->ce_flags
& CE_REMOVE
)
638 return o
->gently
? -1 :
639 error(ERRORMSG(o
, would_lose_untracked
), ce
->name
, action
);
644 static int merged_entry(struct cache_entry
*merge
, struct cache_entry
*old
,
645 struct unpack_trees_options
*o
)
647 int update
= CE_UPDATE
;
651 * See if we can re-use the old CE directly?
652 * That way we get the uptodate stat info.
654 * This also removes the UPDATE flag on a match; otherwise
655 * we will end up overwriting local changes in the work tree.
657 if (same(old
, merge
)) {
658 copy_cache_entry(merge
, old
);
661 if (verify_uptodate(old
, o
))
663 invalidate_ce_path(old
, o
);
667 if (verify_absent(merge
, "overwritten", o
))
669 invalidate_ce_path(merge
, o
);
672 add_entry(o
, merge
, update
, CE_STAGEMASK
);
676 static int deleted_entry(struct cache_entry
*ce
, struct cache_entry
*old
,
677 struct unpack_trees_options
*o
)
679 /* Did it exist in the index? */
681 if (verify_absent(ce
, "removed", o
))
685 if (verify_uptodate(old
, o
))
687 add_entry(o
, ce
, CE_REMOVE
, 0);
688 invalidate_ce_path(ce
, o
);
692 static int keep_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
694 add_entry(o
, ce
, 0, 0);
699 static void show_stage_entry(FILE *o
,
700 const char *label
, const struct cache_entry
*ce
)
703 fprintf(o
, "%s (missing)\n", label
);
705 fprintf(o
, "%s%06o %s %d\t%s\n",
708 sha1_to_hex(ce
->sha1
),
714 int threeway_merge(struct cache_entry
**stages
, struct unpack_trees_options
*o
)
716 struct cache_entry
*index
;
717 struct cache_entry
*head
;
718 struct cache_entry
*remote
= stages
[o
->head_idx
+ 1];
721 int remote_match
= 0;
723 int df_conflict_head
= 0;
724 int df_conflict_remote
= 0;
726 int any_anc_missing
= 0;
727 int no_anc_exists
= 1;
730 for (i
= 1; i
< o
->head_idx
; i
++) {
731 if (!stages
[i
] || stages
[i
] == o
->df_conflict_entry
)
738 head
= stages
[o
->head_idx
];
740 if (head
== o
->df_conflict_entry
) {
741 df_conflict_head
= 1;
745 if (remote
== o
->df_conflict_entry
) {
746 df_conflict_remote
= 1;
750 /* First, if there's a #16 situation, note that to prevent #13
753 if (!same(remote
, head
)) {
754 for (i
= 1; i
< o
->head_idx
; i
++) {
755 if (same(stages
[i
], head
)) {
758 if (same(stages
[i
], remote
)) {
764 /* We start with cases where the index is allowed to match
765 * something other than the head: #14(ALT) and #2ALT, where it
766 * is permitted to match the result instead.
768 /* #14, #14ALT, #2ALT */
769 if (remote
&& !df_conflict_head
&& head_match
&& !remote_match
) {
770 if (index
&& !same(index
, remote
) && !same(index
, head
))
771 return o
->gently
? -1 : reject_merge(index
, o
);
772 return merged_entry(remote
, index
, o
);
775 * If we have an entry in the index cache, then we want to
776 * make sure that it matches head.
778 if (index
&& !same(index
, head
))
779 return o
->gently
? -1 : reject_merge(index
, o
);
783 if (same(head
, remote
))
784 return merged_entry(head
, index
, o
);
786 if (!df_conflict_remote
&& remote_match
&& !head_match
)
787 return merged_entry(head
, index
, o
);
791 if (!head
&& !remote
&& any_anc_missing
)
794 /* Under the new "aggressive" rule, we resolve mostly trivial
795 * cases that we historically had git-merge-one-file resolve.
798 int head_deleted
= !head
&& !df_conflict_head
;
799 int remote_deleted
= !remote
&& !df_conflict_remote
;
800 struct cache_entry
*ce
= NULL
;
809 for (i
= 1; i
< o
->head_idx
; i
++) {
810 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
819 * Deleted in one and unchanged in the other.
821 if ((head_deleted
&& remote_deleted
) ||
822 (head_deleted
&& remote
&& remote_match
) ||
823 (remote_deleted
&& head
&& head_match
)) {
825 return deleted_entry(index
, index
, o
);
826 if (ce
&& !head_deleted
) {
827 if (verify_absent(ce
, "removed", o
))
833 * Added in both, identically.
835 if (no_anc_exists
&& head
&& remote
&& same(head
, remote
))
836 return merged_entry(head
, index
, o
);
840 /* Below are "no merge" cases, which require that the index be
841 * up-to-date to avoid the files getting overwritten with
842 * conflict resolution files.
845 if (verify_uptodate(index
, o
))
849 o
->nontrivial_merge
= 1;
851 /* #2, #3, #4, #6, #7, #9, #10, #11. */
853 if (!head_match
|| !remote_match
) {
854 for (i
= 1; i
< o
->head_idx
; i
++) {
855 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
856 keep_entry(stages
[i
], o
);
864 fprintf(stderr
, "read-tree: warning #16 detected\n");
865 show_stage_entry(stderr
, "head ", stages
[head_match
]);
866 show_stage_entry(stderr
, "remote ", stages
[remote_match
]);
869 if (head
) { count
+= keep_entry(head
, o
); }
870 if (remote
) { count
+= keep_entry(remote
, o
); }
877 * The rule is to "carry forward" what is in the index without losing
878 * information across a "fast forward", favoring a successful merge
879 * over a merge failure when it makes sense. For details of the
880 * "carry forward" rule, please see <Documentation/git-read-tree.txt>.
883 int twoway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
885 struct cache_entry
*current
= src
[0];
886 struct cache_entry
*oldtree
= src
[1];
887 struct cache_entry
*newtree
= src
[2];
889 if (o
->merge_size
!= 2)
890 return error("Cannot do a twoway merge of %d trees",
893 if (oldtree
== o
->df_conflict_entry
)
895 if (newtree
== o
->df_conflict_entry
)
899 if ((!oldtree
&& !newtree
) || /* 4 and 5 */
900 (!oldtree
&& newtree
&&
901 same(current
, newtree
)) || /* 6 and 7 */
902 (oldtree
&& newtree
&&
903 same(oldtree
, newtree
)) || /* 14 and 15 */
904 (oldtree
&& newtree
&&
905 !same(oldtree
, newtree
) && /* 18 and 19 */
906 same(current
, newtree
))) {
907 return keep_entry(current
, o
);
909 else if (oldtree
&& !newtree
&& same(current
, oldtree
)) {
911 return deleted_entry(oldtree
, current
, o
);
913 else if (oldtree
&& newtree
&&
914 same(current
, oldtree
) && !same(current
, newtree
)) {
916 return merged_entry(newtree
, current
, o
);
919 /* all other failures */
921 return o
->gently
? -1 : reject_merge(oldtree
, o
);
923 return o
->gently
? -1 : reject_merge(current
, o
);
925 return o
->gently
? -1 : reject_merge(newtree
, o
);
930 if (oldtree
&& !o
->initial_checkout
) {
932 * deletion of the path was staged;
934 if (same(oldtree
, newtree
))
936 return reject_merge(oldtree
, o
);
938 return merged_entry(newtree
, current
, o
);
940 return deleted_entry(oldtree
, current
, o
);
946 * Keep the index entries at stage0, collapse stage1 but make sure
947 * stage0 does not have anything there.
949 int bind_merge(struct cache_entry
**src
,
950 struct unpack_trees_options
*o
)
952 struct cache_entry
*old
= src
[0];
953 struct cache_entry
*a
= src
[1];
955 if (o
->merge_size
!= 1)
956 return error("Cannot do a bind merge of %d trees\n",
959 return o
->gently
? -1 :
960 error(ERRORMSG(o
, bind_overlap
), a
->name
, old
->name
);
962 return keep_entry(old
, o
);
964 return merged_entry(a
, NULL
, o
);
971 * - take the stat information from stage0, take the data from stage1
973 int oneway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
975 struct cache_entry
*old
= src
[0];
976 struct cache_entry
*a
= src
[1];
978 if (o
->merge_size
!= 1)
979 return error("Cannot do a oneway merge of %d trees",
983 return deleted_entry(old
, old
, o
);
985 if (old
&& same(old
, a
)) {
989 if (lstat(old
->name
, &st
) ||
990 ie_match_stat(o
->src_index
, old
, &st
, CE_MATCH_IGNORE_VALID
))
993 add_entry(o
, old
, update
, 0);
996 return merged_entry(a
, old
, o
);