1 #define NO_THE_INDEX_COMPATIBILITY_MACROS
6 #include "cache-tree.h"
7 #include "unpack-trees.h"
13 * Error messages expected by scripts out of plumbing commands such as
14 * read-tree. Non-scripted Porcelain is not required to use these messages
15 * and in fact are encouraged to reword them to better suit their particular
16 * situation better. See how "git checkout" replaces not_uptodate_file to
17 * explain why it does not allow switching between branches when you have
18 * local changes, for example.
20 static struct unpack_trees_error_msgs unpack_plumbing_errors
= {
22 "Entry '%s' would be overwritten by merge. Cannot merge.",
24 /* not_uptodate_file */
25 "Entry '%s' not uptodate. Cannot merge.",
27 /* not_uptodate_dir */
28 "Updating '%s' would lose untracked files in it",
30 /* would_lose_untracked */
31 "Untracked working tree file '%s' would be %s by merge.",
34 "Entry '%s' overlaps with '%s'. Cannot bind.",
37 #define ERRORMSG(o,fld) \
38 ( ((o) && (o)->msgs.fld) \
40 : (unpack_plumbing_errors.fld) )
42 static void add_entry(struct unpack_trees_options
*o
, struct cache_entry
*ce
,
43 unsigned int set
, unsigned int clear
)
45 unsigned int size
= ce_size(ce
);
46 struct cache_entry
*new = xmalloc(size
);
48 clear
|= CE_HASHED
| CE_UNHASHED
;
50 memcpy(new, ce
, size
);
52 new->ce_flags
= (new->ce_flags
& ~clear
) | set
;
53 add_index_entry(&o
->result
, new, ADD_CACHE_OK_TO_ADD
|ADD_CACHE_OK_TO_REPLACE
);
57 * Unlink the last component and schedule the leading directories for
58 * removal, such that empty directories get removed.
60 static void unlink_entry(struct cache_entry
*ce
)
62 if (has_symlink_or_noent_leading_path(ce
->name
, ce_namelen(ce
)))
66 schedule_dir_for_removal(ce
->name
, ce_namelen(ce
));
69 static struct checkout state
;
70 static int check_updates(struct unpack_trees_options
*o
)
72 unsigned cnt
= 0, total
= 0;
73 struct progress
*progress
= NULL
;
74 struct index_state
*index
= &o
->result
;
78 if (o
->update
&& o
->verbose_update
) {
79 for (total
= cnt
= 0; cnt
< index
->cache_nr
; cnt
++) {
80 struct cache_entry
*ce
= index
->cache
[cnt
];
81 if (ce
->ce_flags
& (CE_UPDATE
| CE_REMOVE
))
85 progress
= start_progress_delay("Checking out files",
90 git_attr_set_direction(GIT_ATTR_CHECKOUT
, &o
->result
);
91 for (i
= 0; i
< index
->cache_nr
; i
++) {
92 struct cache_entry
*ce
= index
->cache
[i
];
94 if (ce
->ce_flags
& CE_REMOVE
) {
95 display_progress(progress
, ++cnt
);
100 remove_marked_cache_entries(&o
->result
);
101 remove_scheduled_dirs();
103 for (i
= 0; i
< index
->cache_nr
; i
++) {
104 struct cache_entry
*ce
= index
->cache
[i
];
106 if (ce
->ce_flags
& CE_UPDATE
) {
107 display_progress(progress
, ++cnt
);
108 ce
->ce_flags
&= ~CE_UPDATE
;
110 errs
|= checkout_entry(ce
, &state
, NULL
);
114 stop_progress(&progress
);
115 git_attr_set_direction(GIT_ATTR_CHECKIN
, NULL
);
119 static inline int call_unpack_fn(struct cache_entry
**src
, struct unpack_trees_options
*o
)
121 int ret
= o
->fn(src
, o
);
127 static int unpack_index_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
129 struct cache_entry
*src
[5] = { ce
, };
133 if (o
->skip_unmerged
) {
134 add_entry(o
, ce
, 0, 0);
138 return call_unpack_fn(src
, o
);
141 int traverse_trees_recursive(int n
, unsigned long dirmask
, unsigned long df_conflicts
, struct name_entry
*names
, struct traverse_info
*info
)
144 struct tree_desc t
[MAX_UNPACK_TREES
];
145 struct traverse_info newinfo
;
146 struct name_entry
*p
;
155 newinfo
.pathlen
+= tree_entry_len(p
->path
, p
->sha1
) + 1;
156 newinfo
.conflicts
|= df_conflicts
;
158 for (i
= 0; i
< n
; i
++, dirmask
>>= 1) {
159 const unsigned char *sha1
= NULL
;
161 sha1
= names
[i
].sha1
;
162 fill_tree_descriptor(t
+i
, sha1
);
164 return traverse_trees(n
, t
, &newinfo
);
168 * Compare the traverse-path to the cache entry without actually
169 * having to generate the textual representation of the traverse
172 * NOTE! This *only* compares up to the size of the traverse path
173 * itself - the caller needs to do the final check for the cache
174 * entry having more data at the end!
176 static int do_compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
178 int len
, pathlen
, ce_len
;
182 int cmp
= do_compare_entry(ce
, info
->prev
, &info
->name
);
186 pathlen
= info
->pathlen
;
187 ce_len
= ce_namelen(ce
);
189 /* If ce_len < pathlen then we must have previously hit "name == directory" entry */
190 if (ce_len
< pathlen
)
194 ce_name
= ce
->name
+ pathlen
;
196 len
= tree_entry_len(n
->path
, n
->sha1
);
197 return df_name_compare(ce_name
, ce_len
, S_IFREG
, n
->path
, len
, n
->mode
);
200 static int compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
202 int cmp
= do_compare_entry(ce
, info
, n
);
207 * Even if the beginning compared identically, the ce should
208 * compare as bigger than a directory leading up to it!
210 return ce_namelen(ce
) > traverse_path_len(info
, n
);
213 static struct cache_entry
*create_ce_entry(const struct traverse_info
*info
, const struct name_entry
*n
, int stage
)
215 int len
= traverse_path_len(info
, n
);
216 struct cache_entry
*ce
= xcalloc(1, cache_entry_size(len
));
218 ce
->ce_mode
= create_ce_mode(n
->mode
);
219 ce
->ce_flags
= create_ce_flags(len
, stage
);
220 hashcpy(ce
->sha1
, n
->sha1
);
221 make_traverse_path(ce
->name
, info
, n
);
226 static int unpack_nondirectories(int n
, unsigned long mask
,
227 unsigned long dirmask
,
228 struct cache_entry
**src
,
229 const struct name_entry
*names
,
230 const struct traverse_info
*info
)
233 struct unpack_trees_options
*o
= info
->data
;
234 unsigned long conflicts
;
236 /* Do we have *only* directories? Nothing to do */
237 if (mask
== dirmask
&& !src
[0])
240 conflicts
= info
->conflicts
;
243 conflicts
|= dirmask
;
246 * Ok, we've filled in up to any potential index entry in src[0],
249 for (i
= 0; i
< n
; i
++) {
251 unsigned int bit
= 1ul << i
;
252 if (conflicts
& bit
) {
253 src
[i
+ o
->merge
] = o
->df_conflict_entry
;
260 else if (i
+ 1 < o
->head_idx
)
262 else if (i
+ 1 > o
->head_idx
)
266 src
[i
+ o
->merge
] = create_ce_entry(info
, names
+ i
, stage
);
270 return call_unpack_fn(src
, o
);
272 for (i
= 0; i
< n
; i
++)
273 if (src
[i
] && src
[i
] != o
->df_conflict_entry
)
274 add_entry(o
, src
[i
], 0, 0);
278 static int unpack_callback(int n
, unsigned long mask
, unsigned long dirmask
, struct name_entry
*names
, struct traverse_info
*info
)
280 struct cache_entry
*src
[MAX_UNPACK_TREES
+ 1] = { NULL
, };
281 struct unpack_trees_options
*o
= info
->data
;
282 const struct name_entry
*p
= names
;
284 /* Find first entry with a real name (we could use "mask" too) */
288 /* Are we supposed to look at the index too? */
290 while (o
->pos
< o
->src_index
->cache_nr
) {
291 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
292 int cmp
= compare_entry(ce
, info
, p
);
294 if (unpack_index_entry(ce
, o
) < 0)
302 * If we skip unmerged index entries, we'll skip this
303 * entry *and* the tree entries associated with it!
305 if (o
->skip_unmerged
) {
306 add_entry(o
, ce
, 0, 0);
316 if (unpack_nondirectories(n
, mask
, dirmask
, src
, names
, info
) < 0)
319 /* Now handle any directories.. */
321 unsigned long conflicts
= mask
& ~dirmask
;
327 if (traverse_trees_recursive(n
, dirmask
, conflicts
,
336 static int unpack_failed(struct unpack_trees_options
*o
, const char *message
)
338 discard_index(&o
->result
);
341 return error("%s", message
);
348 * N-way merge "len" trees. Returns 0 on success, -1 on failure to manipulate the
349 * resulting index, -2 on failure to reflect the changes to the work tree.
351 int unpack_trees(unsigned len
, struct tree_desc
*t
, struct unpack_trees_options
*o
)
354 static struct cache_entry
*dfc
;
356 if (len
> MAX_UNPACK_TREES
)
357 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES
);
358 memset(&state
, 0, sizeof(state
));
362 state
.refresh_cache
= 1;
364 memset(&o
->result
, 0, sizeof(o
->result
));
365 o
->result
.initialized
= 1;
367 o
->result
.timestamp
.sec
= o
->src_index
->timestamp
.sec
;
368 o
->result
.timestamp
.nsec
= o
->src_index
->timestamp
.nsec
;
373 dfc
= xcalloc(1, cache_entry_size(0));
374 o
->df_conflict_entry
= dfc
;
377 const char *prefix
= o
->prefix
? o
->prefix
: "";
378 struct traverse_info info
;
380 setup_traverse_info(&info
, prefix
);
381 info
.fn
= unpack_callback
;
384 if (traverse_trees(len
, t
, &info
) < 0)
385 return unpack_failed(o
, NULL
);
388 /* Any left-over entries in the index? */
390 while (o
->pos
< o
->src_index
->cache_nr
) {
391 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
392 if (unpack_index_entry(ce
, o
) < 0)
393 return unpack_failed(o
, NULL
);
397 if (o
->trivial_merges_only
&& o
->nontrivial_merge
)
398 return unpack_failed(o
, "Merge requires file-level merging");
401 ret
= check_updates(o
) ? (-2) : 0;
403 *o
->dst_index
= o
->result
;
407 /* Here come the merge functions */
409 static int reject_merge(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
411 return error(ERRORMSG(o
, would_overwrite
), ce
->name
);
414 static int same(struct cache_entry
*a
, struct cache_entry
*b
)
420 return a
->ce_mode
== b
->ce_mode
&&
421 !hashcmp(a
->sha1
, b
->sha1
);
426 * When a CE gets turned into an unmerged entry, we
427 * want it to be up-to-date
429 static int verify_uptodate(struct cache_entry
*ce
,
430 struct unpack_trees_options
*o
)
434 if (o
->index_only
|| o
->reset
|| ce_uptodate(ce
))
437 if (!lstat(ce
->name
, &st
)) {
438 unsigned changed
= ie_match_stat(o
->src_index
, ce
, &st
, CE_MATCH_IGNORE_VALID
);
442 * NEEDSWORK: the current default policy is to allow
443 * submodule to be out of sync wrt the supermodule
444 * index. This needs to be tightened later for
445 * submodules that are marked to be automatically
448 if (S_ISGITLINK(ce
->ce_mode
))
454 return o
->gently
? -1 :
455 error(ERRORMSG(o
, not_uptodate_file
), ce
->name
);
458 static void invalidate_ce_path(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
461 cache_tree_invalidate_path(o
->src_index
->cache_tree
, ce
->name
);
465 * Check that checking out ce->sha1 in subdir ce->name is not
466 * going to overwrite any working files.
468 * Currently, git does not checkout subprojects during a superproject
469 * checkout, so it is not going to overwrite anything.
471 static int verify_clean_submodule(struct cache_entry
*ce
, const char *action
,
472 struct unpack_trees_options
*o
)
477 static int verify_clean_subdirectory(struct cache_entry
*ce
, const char *action
,
478 struct unpack_trees_options
*o
)
481 * we are about to extract "ce->name"; we would not want to lose
482 * anything in the existing directory there.
489 unsigned char sha1
[20];
491 if (S_ISGITLINK(ce
->ce_mode
) &&
492 resolve_gitlink_ref(ce
->name
, "HEAD", sha1
) == 0) {
493 /* If we are not going to update the submodule, then
496 if (!hashcmp(sha1
, ce
->sha1
))
498 return verify_clean_submodule(ce
, action
, o
);
502 * First let's make sure we do not have a local modification
505 namelen
= strlen(ce
->name
);
506 for (i
= o
->pos
; i
< o
->src_index
->cache_nr
; i
++) {
507 struct cache_entry
*ce2
= o
->src_index
->cache
[i
];
508 int len
= ce_namelen(ce2
);
510 strncmp(ce
->name
, ce2
->name
, namelen
) ||
511 ce2
->name
[namelen
] != '/')
514 * ce2->name is an entry in the subdirectory.
516 if (!ce_stage(ce2
)) {
517 if (verify_uptodate(ce2
, o
))
519 add_entry(o
, ce2
, CE_REMOVE
, 0);
525 * Then we need to make sure that we do not lose a locally
526 * present file that is not ignored.
528 pathbuf
= xmalloc(namelen
+ 2);
529 memcpy(pathbuf
, ce
->name
, namelen
);
530 strcpy(pathbuf
+namelen
, "/");
532 memset(&d
, 0, sizeof(d
));
534 d
.exclude_per_dir
= o
->dir
->exclude_per_dir
;
535 i
= read_directory(&d
, ce
->name
, pathbuf
, namelen
+1, NULL
);
537 return o
->gently
? -1 :
538 error(ERRORMSG(o
, not_uptodate_dir
), ce
->name
);
544 * This gets called when there was no index entry for the tree entry 'dst',
545 * but we found a file in the working tree that 'lstat()' said was fine,
546 * and we're on a case-insensitive filesystem.
548 * See if we can find a case-insensitive match in the index that also
549 * matches the stat information, and assume it's that other file!
551 static int icase_exists(struct unpack_trees_options
*o
, struct cache_entry
*dst
, struct stat
*st
)
553 struct cache_entry
*src
;
555 src
= index_name_exists(o
->src_index
, dst
->name
, ce_namelen(dst
), 1);
556 return src
&& !ie_match_stat(o
->src_index
, src
, st
, CE_MATCH_IGNORE_VALID
);
560 * We do not want to remove or overwrite a working tree file that
561 * is not tracked, unless it is ignored.
563 static int verify_absent(struct cache_entry
*ce
, const char *action
,
564 struct unpack_trees_options
*o
)
568 if (o
->index_only
|| o
->reset
|| !o
->update
)
571 if (has_symlink_or_noent_leading_path(ce
->name
, ce_namelen(ce
)))
574 if (!lstat(ce
->name
, &st
)) {
576 int dtype
= ce_to_dtype(ce
);
577 struct cache_entry
*result
;
580 * It may be that the 'lstat()' succeeded even though
581 * target 'ce' was absent, because there is an old
582 * entry that is different only in case..
584 * Ignore that lstat() if it matches.
586 if (ignore_case
&& icase_exists(o
, ce
, &st
))
589 if (o
->dir
&& excluded(o
->dir
, ce
->name
, &dtype
))
591 * ce->name is explicitly excluded, so it is Ok to
595 if (S_ISDIR(st
.st_mode
)) {
597 * We are checking out path "foo" and
598 * found "foo/." in the working tree.
599 * This is tricky -- if we have modified
600 * files that are in "foo/" we would lose
603 ret
= verify_clean_subdirectory(ce
, action
, o
);
608 * If this removed entries from the index,
609 * what that means is:
611 * (1) the caller unpack_callback() saw path/foo
612 * in the index, and it has not removed it because
613 * it thinks it is handling 'path' as blob with
615 * (2) we will return "ok, we placed a merged entry
616 * in the index" which would cause o->pos to be
617 * incremented by one;
618 * (3) however, original o->pos now has 'path/foo'
619 * marked with "to be removed".
621 * We need to increment it by the number of
622 * deleted entries here.
629 * The previous round may already have decided to
630 * delete this path, which is in a subdirectory that
631 * is being replaced with a blob.
633 result
= index_name_exists(&o
->result
, ce
->name
, ce_namelen(ce
), 0);
635 if (result
->ce_flags
& CE_REMOVE
)
639 return o
->gently
? -1 :
640 error(ERRORMSG(o
, would_lose_untracked
), ce
->name
, action
);
645 static int merged_entry(struct cache_entry
*merge
, struct cache_entry
*old
,
646 struct unpack_trees_options
*o
)
648 int update
= CE_UPDATE
;
652 * See if we can re-use the old CE directly?
653 * That way we get the uptodate stat info.
655 * This also removes the UPDATE flag on a match; otherwise
656 * we will end up overwriting local changes in the work tree.
658 if (same(old
, merge
)) {
659 copy_cache_entry(merge
, old
);
662 if (verify_uptodate(old
, o
))
664 invalidate_ce_path(old
, o
);
668 if (verify_absent(merge
, "overwritten", o
))
670 invalidate_ce_path(merge
, o
);
673 add_entry(o
, merge
, update
, CE_STAGEMASK
);
677 static int deleted_entry(struct cache_entry
*ce
, struct cache_entry
*old
,
678 struct unpack_trees_options
*o
)
680 /* Did it exist in the index? */
682 if (verify_absent(ce
, "removed", o
))
686 if (verify_uptodate(old
, o
))
688 add_entry(o
, ce
, CE_REMOVE
, 0);
689 invalidate_ce_path(ce
, o
);
693 static int keep_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
695 add_entry(o
, ce
, 0, 0);
700 static void show_stage_entry(FILE *o
,
701 const char *label
, const struct cache_entry
*ce
)
704 fprintf(o
, "%s (missing)\n", label
);
706 fprintf(o
, "%s%06o %s %d\t%s\n",
709 sha1_to_hex(ce
->sha1
),
715 int threeway_merge(struct cache_entry
**stages
, struct unpack_trees_options
*o
)
717 struct cache_entry
*index
;
718 struct cache_entry
*head
;
719 struct cache_entry
*remote
= stages
[o
->head_idx
+ 1];
722 int remote_match
= 0;
724 int df_conflict_head
= 0;
725 int df_conflict_remote
= 0;
727 int any_anc_missing
= 0;
728 int no_anc_exists
= 1;
731 for (i
= 1; i
< o
->head_idx
; i
++) {
732 if (!stages
[i
] || stages
[i
] == o
->df_conflict_entry
)
739 head
= stages
[o
->head_idx
];
741 if (head
== o
->df_conflict_entry
) {
742 df_conflict_head
= 1;
746 if (remote
== o
->df_conflict_entry
) {
747 df_conflict_remote
= 1;
751 /* First, if there's a #16 situation, note that to prevent #13
754 if (!same(remote
, head
)) {
755 for (i
= 1; i
< o
->head_idx
; i
++) {
756 if (same(stages
[i
], head
)) {
759 if (same(stages
[i
], remote
)) {
765 /* We start with cases where the index is allowed to match
766 * something other than the head: #14(ALT) and #2ALT, where it
767 * is permitted to match the result instead.
769 /* #14, #14ALT, #2ALT */
770 if (remote
&& !df_conflict_head
&& head_match
&& !remote_match
) {
771 if (index
&& !same(index
, remote
) && !same(index
, head
))
772 return o
->gently
? -1 : reject_merge(index
, o
);
773 return merged_entry(remote
, index
, o
);
776 * If we have an entry in the index cache, then we want to
777 * make sure that it matches head.
779 if (index
&& !same(index
, head
))
780 return o
->gently
? -1 : reject_merge(index
, o
);
784 if (same(head
, remote
))
785 return merged_entry(head
, index
, o
);
787 if (!df_conflict_remote
&& remote_match
&& !head_match
)
788 return merged_entry(head
, index
, o
);
792 if (!head
&& !remote
&& any_anc_missing
)
795 /* Under the new "aggressive" rule, we resolve mostly trivial
796 * cases that we historically had git-merge-one-file resolve.
799 int head_deleted
= !head
&& !df_conflict_head
;
800 int remote_deleted
= !remote
&& !df_conflict_remote
;
801 struct cache_entry
*ce
= NULL
;
810 for (i
= 1; i
< o
->head_idx
; i
++) {
811 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
820 * Deleted in one and unchanged in the other.
822 if ((head_deleted
&& remote_deleted
) ||
823 (head_deleted
&& remote
&& remote_match
) ||
824 (remote_deleted
&& head
&& head_match
)) {
826 return deleted_entry(index
, index
, o
);
827 if (ce
&& !head_deleted
) {
828 if (verify_absent(ce
, "removed", o
))
834 * Added in both, identically.
836 if (no_anc_exists
&& head
&& remote
&& same(head
, remote
))
837 return merged_entry(head
, index
, o
);
841 /* Below are "no merge" cases, which require that the index be
842 * up-to-date to avoid the files getting overwritten with
843 * conflict resolution files.
846 if (verify_uptodate(index
, o
))
850 o
->nontrivial_merge
= 1;
852 /* #2, #3, #4, #6, #7, #9, #10, #11. */
854 if (!head_match
|| !remote_match
) {
855 for (i
= 1; i
< o
->head_idx
; i
++) {
856 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
857 keep_entry(stages
[i
], o
);
865 fprintf(stderr
, "read-tree: warning #16 detected\n");
866 show_stage_entry(stderr
, "head ", stages
[head_match
]);
867 show_stage_entry(stderr
, "remote ", stages
[remote_match
]);
870 if (head
) { count
+= keep_entry(head
, o
); }
871 if (remote
) { count
+= keep_entry(remote
, o
); }
878 * The rule is to "carry forward" what is in the index without losing
879 * information across a "fast forward", favoring a successful merge
880 * over a merge failure when it makes sense. For details of the
881 * "carry forward" rule, please see <Documentation/git-read-tree.txt>.
884 int twoway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
886 struct cache_entry
*current
= src
[0];
887 struct cache_entry
*oldtree
= src
[1];
888 struct cache_entry
*newtree
= src
[2];
890 if (o
->merge_size
!= 2)
891 return error("Cannot do a twoway merge of %d trees",
894 if (oldtree
== o
->df_conflict_entry
)
896 if (newtree
== o
->df_conflict_entry
)
900 if ((!oldtree
&& !newtree
) || /* 4 and 5 */
901 (!oldtree
&& newtree
&&
902 same(current
, newtree
)) || /* 6 and 7 */
903 (oldtree
&& newtree
&&
904 same(oldtree
, newtree
)) || /* 14 and 15 */
905 (oldtree
&& newtree
&&
906 !same(oldtree
, newtree
) && /* 18 and 19 */
907 same(current
, newtree
))) {
908 return keep_entry(current
, o
);
910 else if (oldtree
&& !newtree
&& same(current
, oldtree
)) {
912 return deleted_entry(oldtree
, current
, o
);
914 else if (oldtree
&& newtree
&&
915 same(current
, oldtree
) && !same(current
, newtree
)) {
917 return merged_entry(newtree
, current
, o
);
920 /* all other failures */
922 return o
->gently
? -1 : reject_merge(oldtree
, o
);
924 return o
->gently
? -1 : reject_merge(current
, o
);
926 return o
->gently
? -1 : reject_merge(newtree
, o
);
931 if (oldtree
&& !o
->initial_checkout
) {
933 * deletion of the path was staged;
935 if (same(oldtree
, newtree
))
937 return reject_merge(oldtree
, o
);
939 return merged_entry(newtree
, current
, o
);
941 return deleted_entry(oldtree
, current
, o
);
947 * Keep the index entries at stage0, collapse stage1 but make sure
948 * stage0 does not have anything there.
950 int bind_merge(struct cache_entry
**src
,
951 struct unpack_trees_options
*o
)
953 struct cache_entry
*old
= src
[0];
954 struct cache_entry
*a
= src
[1];
956 if (o
->merge_size
!= 1)
957 return error("Cannot do a bind merge of %d trees\n",
960 return o
->gently
? -1 :
961 error(ERRORMSG(o
, bind_overlap
), a
->name
, old
->name
);
963 return keep_entry(old
, o
);
965 return merged_entry(a
, NULL
, o
);
972 * - take the stat information from stage0, take the data from stage1
974 int oneway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
976 struct cache_entry
*old
= src
[0];
977 struct cache_entry
*a
= src
[1];
979 if (o
->merge_size
!= 1)
980 return error("Cannot do a oneway merge of %d trees",
984 return deleted_entry(old
, old
, o
);
986 if (old
&& same(old
, a
)) {
990 if (lstat(old
->name
, &st
) ||
991 ie_match_stat(o
->src_index
, old
, &st
, CE_MATCH_IGNORE_VALID
))
994 add_entry(o
, old
, update
, 0);
997 return merged_entry(a
, old
, o
);