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
);
55 /* Unlink the last component and attempt to remove leading
56 * directories, in case this unlink is the removal of the
57 * last entry in the directory -- empty directories are removed.
59 static void unlink_entry(struct cache_entry
*ce
)
62 char *name
= ce
->name
;
64 if (has_symlink_leading_path(ce_namelen(ce
), ce
->name
))
71 cp
= strrchr(name
, '/');
87 static struct checkout state
;
88 static int check_updates(struct unpack_trees_options
*o
)
90 unsigned cnt
= 0, total
= 0;
91 struct progress
*progress
= NULL
;
92 struct index_state
*index
= &o
->result
;
96 if (o
->update
&& o
->verbose_update
) {
97 for (total
= cnt
= 0; cnt
< index
->cache_nr
; cnt
++) {
98 struct cache_entry
*ce
= index
->cache
[cnt
];
99 if (ce
->ce_flags
& (CE_UPDATE
| CE_REMOVE
))
103 progress
= start_progress_delay("Checking out files",
108 for (i
= 0; i
< index
->cache_nr
; i
++) {
109 struct cache_entry
*ce
= index
->cache
[i
];
111 if (ce
->ce_flags
& CE_REMOVE
) {
112 display_progress(progress
, ++cnt
);
115 remove_index_entry_at(&o
->result
, i
);
121 for (i
= 0; i
< index
->cache_nr
; i
++) {
122 struct cache_entry
*ce
= index
->cache
[i
];
124 if (ce
->ce_flags
& CE_UPDATE
) {
125 display_progress(progress
, ++cnt
);
126 ce
->ce_flags
&= ~CE_UPDATE
;
128 errs
|= checkout_entry(ce
, &state
, NULL
);
132 stop_progress(&progress
);
136 static inline int call_unpack_fn(struct cache_entry
**src
, struct unpack_trees_options
*o
)
138 int ret
= o
->fn(src
, o
);
144 static int unpack_index_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
146 struct cache_entry
*src
[5] = { ce
, };
150 if (o
->skip_unmerged
) {
151 add_entry(o
, ce
, 0, 0);
155 return call_unpack_fn(src
, o
);
158 int traverse_trees_recursive(int n
, unsigned long dirmask
, unsigned long df_conflicts
, struct name_entry
*names
, struct traverse_info
*info
)
161 struct tree_desc t
[MAX_UNPACK_TREES
];
162 struct traverse_info newinfo
;
163 struct name_entry
*p
;
172 newinfo
.pathlen
+= tree_entry_len(p
->path
, p
->sha1
) + 1;
173 newinfo
.conflicts
|= df_conflicts
;
175 for (i
= 0; i
< n
; i
++, dirmask
>>= 1) {
176 const unsigned char *sha1
= NULL
;
178 sha1
= names
[i
].sha1
;
179 fill_tree_descriptor(t
+i
, sha1
);
181 return traverse_trees(n
, t
, &newinfo
);
185 * Compare the traverse-path to the cache entry without actually
186 * having to generate the textual representation of the traverse
189 * NOTE! This *only* compares up to the size of the traverse path
190 * itself - the caller needs to do the final check for the cache
191 * entry having more data at the end!
193 static int do_compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
195 int len
, pathlen
, ce_len
;
199 int cmp
= do_compare_entry(ce
, info
->prev
, &info
->name
);
203 pathlen
= info
->pathlen
;
204 ce_len
= ce_namelen(ce
);
206 /* If ce_len < pathlen then we must have previously hit "name == directory" entry */
207 if (ce_len
< pathlen
)
211 ce_name
= ce
->name
+ pathlen
;
213 len
= tree_entry_len(n
->path
, n
->sha1
);
214 return df_name_compare(ce_name
, ce_len
, S_IFREG
, n
->path
, len
, n
->mode
);
217 static int compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
219 int cmp
= do_compare_entry(ce
, info
, n
);
224 * Even if the beginning compared identically, the ce should
225 * compare as bigger than a directory leading up to it!
227 return ce_namelen(ce
) > traverse_path_len(info
, n
);
230 static struct cache_entry
*create_ce_entry(const struct traverse_info
*info
, const struct name_entry
*n
, int stage
)
232 int len
= traverse_path_len(info
, n
);
233 struct cache_entry
*ce
= xcalloc(1, cache_entry_size(len
));
235 ce
->ce_mode
= create_ce_mode(n
->mode
);
236 ce
->ce_flags
= create_ce_flags(len
, stage
);
237 hashcpy(ce
->sha1
, n
->sha1
);
238 make_traverse_path(ce
->name
, info
, n
);
243 static int unpack_nondirectories(int n
, unsigned long mask
, unsigned long dirmask
, struct cache_entry
*src
[5],
244 const struct name_entry
*names
, const struct traverse_info
*info
)
247 struct unpack_trees_options
*o
= info
->data
;
248 unsigned long conflicts
;
250 /* Do we have *only* directories? Nothing to do */
251 if (mask
== dirmask
&& !src
[0])
254 conflicts
= info
->conflicts
;
257 conflicts
|= dirmask
;
260 * Ok, we've filled in up to any potential index entry in src[0],
263 for (i
= 0; i
< n
; i
++) {
265 unsigned int bit
= 1ul << i
;
266 if (conflicts
& bit
) {
267 src
[i
+ o
->merge
] = o
->df_conflict_entry
;
274 else if (i
+ 1 < o
->head_idx
)
276 else if (i
+ 1 > o
->head_idx
)
280 src
[i
+ o
->merge
] = create_ce_entry(info
, names
+ i
, stage
);
284 return call_unpack_fn(src
, o
);
287 for (i
= 0; i
< n
; i
++)
288 add_entry(o
, src
[i
], 0, 0);
292 static int unpack_callback(int n
, unsigned long mask
, unsigned long dirmask
, struct name_entry
*names
, struct traverse_info
*info
)
294 struct cache_entry
*src
[5] = { NULL
, };
295 struct unpack_trees_options
*o
= info
->data
;
296 const struct name_entry
*p
= names
;
298 /* Find first entry with a real name (we could use "mask" too) */
302 /* Are we supposed to look at the index too? */
304 while (o
->pos
< o
->src_index
->cache_nr
) {
305 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
306 int cmp
= compare_entry(ce
, info
, p
);
308 if (unpack_index_entry(ce
, o
) < 0)
316 * If we skip unmerged index entries, we'll skip this
317 * entry *and* the tree entries associated with it!
319 if (o
->skip_unmerged
) {
320 add_entry(o
, ce
, 0, 0);
330 if (unpack_nondirectories(n
, mask
, dirmask
, src
, names
, info
) < 0)
333 /* Now handle any directories.. */
335 unsigned long conflicts
= mask
& ~dirmask
;
341 if (traverse_trees_recursive(n
, dirmask
, conflicts
,
350 static int unpack_failed(struct unpack_trees_options
*o
, const char *message
)
352 discard_index(&o
->result
);
355 return error(message
);
362 * N-way merge "len" trees. Returns 0 on success, -1 on failure to manipulate the
363 * resulting index, -2 on failure to reflect the changes to the work tree.
365 int unpack_trees(unsigned len
, struct tree_desc
*t
, struct unpack_trees_options
*o
)
368 static struct cache_entry
*dfc
;
370 if (len
> MAX_UNPACK_TREES
)
371 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES
);
372 memset(&state
, 0, sizeof(state
));
376 state
.refresh_cache
= 1;
378 memset(&o
->result
, 0, sizeof(o
->result
));
380 o
->result
.timestamp
= o
->src_index
->timestamp
;
384 dfc
= xcalloc(1, sizeof(struct cache_entry
) + 1);
385 o
->df_conflict_entry
= dfc
;
388 const char *prefix
= o
->prefix
? o
->prefix
: "";
389 struct traverse_info info
;
391 setup_traverse_info(&info
, prefix
);
392 info
.fn
= unpack_callback
;
395 if (traverse_trees(len
, t
, &info
) < 0)
396 return unpack_failed(o
, NULL
);
399 /* Any left-over entries in the index? */
401 while (o
->pos
< o
->src_index
->cache_nr
) {
402 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
403 if (unpack_index_entry(ce
, o
) < 0)
404 return unpack_failed(o
, NULL
);
408 if (o
->trivial_merges_only
&& o
->nontrivial_merge
)
409 return unpack_failed(o
, "Merge requires file-level merging");
412 ret
= check_updates(o
) ? (-2) : 0;
414 *o
->dst_index
= o
->result
;
418 /* Here come the merge functions */
420 static int reject_merge(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
422 return error(ERRORMSG(o
, would_overwrite
), ce
->name
);
425 static int same(struct cache_entry
*a
, struct cache_entry
*b
)
431 return a
->ce_mode
== b
->ce_mode
&&
432 !hashcmp(a
->sha1
, b
->sha1
);
437 * When a CE gets turned into an unmerged entry, we
438 * want it to be up-to-date
440 static int verify_uptodate(struct cache_entry
*ce
,
441 struct unpack_trees_options
*o
)
445 if (o
->index_only
|| o
->reset
)
448 if (!lstat(ce
->name
, &st
)) {
449 unsigned changed
= ie_match_stat(o
->src_index
, ce
, &st
, CE_MATCH_IGNORE_VALID
);
453 * NEEDSWORK: the current default policy is to allow
454 * submodule to be out of sync wrt the supermodule
455 * index. This needs to be tightened later for
456 * submodules that are marked to be automatically
459 if (S_ISGITLINK(ce
->ce_mode
))
465 return o
->gently
? -1 :
466 error(ERRORMSG(o
, not_uptodate_file
), ce
->name
);
469 static void invalidate_ce_path(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
472 cache_tree_invalidate_path(o
->src_index
->cache_tree
, ce
->name
);
476 * Check that checking out ce->sha1 in subdir ce->name is not
477 * going to overwrite any working files.
479 * Currently, git does not checkout subprojects during a superproject
480 * checkout, so it is not going to overwrite anything.
482 static int verify_clean_submodule(struct cache_entry
*ce
, const char *action
,
483 struct unpack_trees_options
*o
)
488 static int verify_clean_subdirectory(struct cache_entry
*ce
, const char *action
,
489 struct unpack_trees_options
*o
)
492 * we are about to extract "ce->name"; we would not want to lose
493 * anything in the existing directory there.
500 unsigned char sha1
[20];
502 if (S_ISGITLINK(ce
->ce_mode
) &&
503 resolve_gitlink_ref(ce
->name
, "HEAD", sha1
) == 0) {
504 /* If we are not going to update the submodule, then
507 if (!hashcmp(sha1
, ce
->sha1
))
509 return verify_clean_submodule(ce
, action
, o
);
513 * First let's make sure we do not have a local modification
516 namelen
= strlen(ce
->name
);
517 pos
= index_name_pos(o
->src_index
, ce
->name
, namelen
);
519 return 0; /* we have it as nondirectory */
521 for (i
= pos
; i
< o
->src_index
->cache_nr
; i
++) {
522 struct cache_entry
*ce2
= o
->src_index
->cache
[i
];
523 int len
= ce_namelen(ce2
);
525 strncmp(ce
->name
, ce2
->name
, namelen
) ||
526 ce2
->name
[namelen
] != '/')
529 * ce2->name is an entry in the subdirectory.
531 if (!ce_stage(ce2
)) {
532 if (verify_uptodate(ce2
, o
))
534 add_entry(o
, ce2
, CE_REMOVE
, 0);
540 * Then we need to make sure that we do not lose a locally
541 * present file that is not ignored.
543 pathbuf
= xmalloc(namelen
+ 2);
544 memcpy(pathbuf
, ce
->name
, namelen
);
545 strcpy(pathbuf
+namelen
, "/");
547 memset(&d
, 0, sizeof(d
));
549 d
.exclude_per_dir
= o
->dir
->exclude_per_dir
;
550 i
= read_directory(&d
, ce
->name
, pathbuf
, namelen
+1, NULL
);
552 return o
->gently
? -1 :
553 error(ERRORMSG(o
, not_uptodate_dir
), ce
->name
);
559 * This gets called when there was no index entry for the tree entry 'dst',
560 * but we found a file in the working tree that 'lstat()' said was fine,
561 * and we're on a case-insensitive filesystem.
563 * See if we can find a case-insensitive match in the index that also
564 * matches the stat information, and assume it's that other file!
566 static int icase_exists(struct unpack_trees_options
*o
, struct cache_entry
*dst
, struct stat
*st
)
568 struct cache_entry
*src
;
570 src
= index_name_exists(o
->src_index
, dst
->name
, ce_namelen(dst
), 1);
571 return src
&& !ie_match_stat(o
->src_index
, src
, st
, CE_MATCH_IGNORE_VALID
);
575 * We do not want to remove or overwrite a working tree file that
576 * is not tracked, unless it is ignored.
578 static int verify_absent(struct cache_entry
*ce
, const char *action
,
579 struct unpack_trees_options
*o
)
583 if (o
->index_only
|| o
->reset
|| !o
->update
)
586 if (has_symlink_leading_path(ce_namelen(ce
), ce
->name
))
589 if (!lstat(ce
->name
, &st
)) {
591 int dtype
= ce_to_dtype(ce
);
592 struct cache_entry
*result
;
595 * It may be that the 'lstat()' succeeded even though
596 * target 'ce' was absent, because there is an old
597 * entry that is different only in case..
599 * Ignore that lstat() if it matches.
601 if (ignore_case
&& icase_exists(o
, ce
, &st
))
604 if (o
->dir
&& excluded(o
->dir
, ce
->name
, &dtype
))
606 * ce->name is explicitly excluded, so it is Ok to
610 if (S_ISDIR(st
.st_mode
)) {
612 * We are checking out path "foo" and
613 * found "foo/." in the working tree.
614 * This is tricky -- if we have modified
615 * files that are in "foo/" we would lose
618 ret
= verify_clean_subdirectory(ce
, action
, o
);
623 * If this removed entries from the index,
624 * what that means is:
626 * (1) the caller unpack_callback() saw path/foo
627 * in the index, and it has not removed it because
628 * it thinks it is handling 'path' as blob with
630 * (2) we will return "ok, we placed a merged entry
631 * in the index" which would cause o->pos to be
632 * incremented by one;
633 * (3) however, original o->pos now has 'path/foo'
634 * marked with "to be removed".
636 * We need to increment it by the number of
637 * deleted entries here.
644 * The previous round may already have decided to
645 * delete this path, which is in a subdirectory that
646 * is being replaced with a blob.
648 result
= index_name_exists(&o
->result
, ce
->name
, ce_namelen(ce
), 0);
650 if (result
->ce_flags
& CE_REMOVE
)
654 return o
->gently
? -1 :
655 error(ERRORMSG(o
, would_lose_untracked
), ce
->name
, action
);
660 static int merged_entry(struct cache_entry
*merge
, struct cache_entry
*old
,
661 struct unpack_trees_options
*o
)
663 int update
= CE_UPDATE
;
667 * See if we can re-use the old CE directly?
668 * That way we get the uptodate stat info.
670 * This also removes the UPDATE flag on a match; otherwise
671 * we will end up overwriting local changes in the work tree.
673 if (same(old
, merge
)) {
674 copy_cache_entry(merge
, old
);
677 if (verify_uptodate(old
, o
))
679 invalidate_ce_path(old
, o
);
683 if (verify_absent(merge
, "overwritten", o
))
685 invalidate_ce_path(merge
, o
);
688 add_entry(o
, merge
, update
, CE_STAGEMASK
);
692 static int deleted_entry(struct cache_entry
*ce
, struct cache_entry
*old
,
693 struct unpack_trees_options
*o
)
695 /* Did it exist in the index? */
697 if (verify_absent(ce
, "removed", o
))
701 if (verify_uptodate(old
, o
))
703 add_entry(o
, ce
, CE_REMOVE
, 0);
704 invalidate_ce_path(ce
, o
);
708 static int keep_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
710 add_entry(o
, ce
, 0, 0);
715 static void show_stage_entry(FILE *o
,
716 const char *label
, const struct cache_entry
*ce
)
719 fprintf(o
, "%s (missing)\n", label
);
721 fprintf(o
, "%s%06o %s %d\t%s\n",
724 sha1_to_hex(ce
->sha1
),
730 int threeway_merge(struct cache_entry
**stages
, struct unpack_trees_options
*o
)
732 struct cache_entry
*index
;
733 struct cache_entry
*head
;
734 struct cache_entry
*remote
= stages
[o
->head_idx
+ 1];
737 int remote_match
= 0;
739 int df_conflict_head
= 0;
740 int df_conflict_remote
= 0;
742 int any_anc_missing
= 0;
743 int no_anc_exists
= 1;
746 for (i
= 1; i
< o
->head_idx
; i
++) {
747 if (!stages
[i
] || stages
[i
] == o
->df_conflict_entry
)
754 head
= stages
[o
->head_idx
];
756 if (head
== o
->df_conflict_entry
) {
757 df_conflict_head
= 1;
761 if (remote
== o
->df_conflict_entry
) {
762 df_conflict_remote
= 1;
766 /* First, if there's a #16 situation, note that to prevent #13
769 if (!same(remote
, head
)) {
770 for (i
= 1; i
< o
->head_idx
; i
++) {
771 if (same(stages
[i
], head
)) {
774 if (same(stages
[i
], remote
)) {
780 /* We start with cases where the index is allowed to match
781 * something other than the head: #14(ALT) and #2ALT, where it
782 * is permitted to match the result instead.
784 /* #14, #14ALT, #2ALT */
785 if (remote
&& !df_conflict_head
&& head_match
&& !remote_match
) {
786 if (index
&& !same(index
, remote
) && !same(index
, head
))
787 return o
->gently
? -1 : reject_merge(index
, o
);
788 return merged_entry(remote
, index
, o
);
791 * If we have an entry in the index cache, then we want to
792 * make sure that it matches head.
794 if (index
&& !same(index
, head
))
795 return o
->gently
? -1 : reject_merge(index
, o
);
799 if (same(head
, remote
))
800 return merged_entry(head
, index
, o
);
802 if (!df_conflict_remote
&& remote_match
&& !head_match
)
803 return merged_entry(head
, index
, o
);
807 if (!head
&& !remote
&& any_anc_missing
)
810 /* Under the new "aggressive" rule, we resolve mostly trivial
811 * cases that we historically had git-merge-one-file resolve.
814 int head_deleted
= !head
&& !df_conflict_head
;
815 int remote_deleted
= !remote
&& !df_conflict_remote
;
816 struct cache_entry
*ce
= NULL
;
825 for (i
= 1; i
< o
->head_idx
; i
++) {
826 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
835 * Deleted in one and unchanged in the other.
837 if ((head_deleted
&& remote_deleted
) ||
838 (head_deleted
&& remote
&& remote_match
) ||
839 (remote_deleted
&& head
&& head_match
)) {
841 return deleted_entry(index
, index
, o
);
842 if (ce
&& !head_deleted
) {
843 if (verify_absent(ce
, "removed", o
))
849 * Added in both, identically.
851 if (no_anc_exists
&& head
&& remote
&& same(head
, remote
))
852 return merged_entry(head
, index
, o
);
856 /* Below are "no merge" cases, which require that the index be
857 * up-to-date to avoid the files getting overwritten with
858 * conflict resolution files.
861 if (verify_uptodate(index
, o
))
865 o
->nontrivial_merge
= 1;
867 /* #2, #3, #4, #6, #7, #9, #10, #11. */
869 if (!head_match
|| !remote_match
) {
870 for (i
= 1; i
< o
->head_idx
; i
++) {
871 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
872 keep_entry(stages
[i
], o
);
880 fprintf(stderr
, "read-tree: warning #16 detected\n");
881 show_stage_entry(stderr
, "head ", stages
[head_match
]);
882 show_stage_entry(stderr
, "remote ", stages
[remote_match
]);
885 if (head
) { count
+= keep_entry(head
, o
); }
886 if (remote
) { count
+= keep_entry(remote
, o
); }
893 * The rule is to "carry forward" what is in the index without losing
894 * information across a "fast forward", favoring a successful merge
895 * over a merge failure when it makes sense. For details of the
896 * "carry forward" rule, please see <Documentation/git-read-tree.txt>.
899 int twoway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
901 struct cache_entry
*current
= src
[0];
902 struct cache_entry
*oldtree
= src
[1];
903 struct cache_entry
*newtree
= src
[2];
905 if (o
->merge_size
!= 2)
906 return error("Cannot do a twoway merge of %d trees",
909 if (oldtree
== o
->df_conflict_entry
)
911 if (newtree
== o
->df_conflict_entry
)
915 if ((!oldtree
&& !newtree
) || /* 4 and 5 */
916 (!oldtree
&& newtree
&&
917 same(current
, newtree
)) || /* 6 and 7 */
918 (oldtree
&& newtree
&&
919 same(oldtree
, newtree
)) || /* 14 and 15 */
920 (oldtree
&& newtree
&&
921 !same(oldtree
, newtree
) && /* 18 and 19 */
922 same(current
, newtree
))) {
923 return keep_entry(current
, o
);
925 else if (oldtree
&& !newtree
&& same(current
, oldtree
)) {
927 return deleted_entry(oldtree
, current
, o
);
929 else if (oldtree
&& newtree
&&
930 same(current
, oldtree
) && !same(current
, newtree
)) {
932 return merged_entry(newtree
, current
, o
);
935 /* all other failures */
937 return o
->gently
? -1 : reject_merge(oldtree
, o
);
939 return o
->gently
? -1 : reject_merge(current
, o
);
941 return o
->gently
? -1 : reject_merge(newtree
, o
);
946 return merged_entry(newtree
, current
, o
);
947 return deleted_entry(oldtree
, current
, o
);
953 * Keep the index entries at stage0, collapse stage1 but make sure
954 * stage0 does not have anything there.
956 int bind_merge(struct cache_entry
**src
,
957 struct unpack_trees_options
*o
)
959 struct cache_entry
*old
= src
[0];
960 struct cache_entry
*a
= src
[1];
962 if (o
->merge_size
!= 1)
963 return error("Cannot do a bind merge of %d trees\n",
966 return o
->gently
? -1 :
967 error(ERRORMSG(o
, bind_overlap
), a
->name
, old
->name
);
969 return keep_entry(old
, o
);
971 return merged_entry(a
, NULL
, o
);
978 * - take the stat information from stage0, take the data from stage1
980 int oneway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
982 struct cache_entry
*old
= src
[0];
983 struct cache_entry
*a
= src
[1];
985 if (o
->merge_size
!= 1)
986 return error("Cannot do a oneway merge of %d trees",
990 return deleted_entry(old
, old
, o
);
992 if (old
&& same(old
, a
)) {
996 if (lstat(old
->name
, &st
) ||
997 ie_match_stat(o
->src_index
, old
, &st
, CE_MATCH_IGNORE_VALID
))
1000 add_entry(o
, old
, update
, 0);
1003 return merged_entry(a
, old
, o
);