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
|ADD_CACHE_SKIP_DFCHECK
);
56 /* Unlink the last component and attempt to remove leading
57 * directories, in case this unlink is the removal of the
58 * last entry in the directory -- empty directories are removed.
60 static void unlink_entry(struct cache_entry
*ce
)
63 char *name
= ce
->name
;
65 if (has_symlink_or_noent_leading_path(ce_namelen(ce
), ce
->name
))
72 cp
= strrchr(name
, '/');
88 static struct checkout state
;
89 static int check_updates(struct unpack_trees_options
*o
)
91 unsigned cnt
= 0, total
= 0;
92 struct progress
*progress
= NULL
;
93 struct index_state
*index
= &o
->result
;
97 if (o
->update
&& o
->verbose_update
) {
98 for (total
= cnt
= 0; cnt
< index
->cache_nr
; cnt
++) {
99 struct cache_entry
*ce
= index
->cache
[cnt
];
100 if (ce
->ce_flags
& (CE_UPDATE
| CE_REMOVE
))
104 progress
= start_progress_delay("Checking out files",
109 git_attr_set_direction(GIT_ATTR_CHECKOUT
, &o
->result
);
110 for (i
= 0; i
< index
->cache_nr
; i
++) {
111 struct cache_entry
*ce
= index
->cache
[i
];
113 if (ce
->ce_flags
& CE_REMOVE
) {
114 display_progress(progress
, ++cnt
);
117 remove_index_entry_at(&o
->result
, i
);
123 for (i
= 0; i
< index
->cache_nr
; i
++) {
124 struct cache_entry
*ce
= index
->cache
[i
];
126 if (ce
->ce_flags
& CE_UPDATE
) {
127 display_progress(progress
, ++cnt
);
128 ce
->ce_flags
&= ~CE_UPDATE
;
130 errs
|= checkout_entry(ce
, &state
, NULL
);
134 stop_progress(&progress
);
135 git_attr_set_direction(GIT_ATTR_CHECKIN
, NULL
);
139 static inline int call_unpack_fn(struct cache_entry
**src
, struct unpack_trees_options
*o
)
141 int ret
= o
->fn(src
, o
);
147 static int unpack_index_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
149 struct cache_entry
*src
[5] = { ce
, };
153 if (o
->skip_unmerged
) {
154 add_entry(o
, ce
, 0, 0);
158 return call_unpack_fn(src
, o
);
161 int traverse_trees_recursive(int n
, unsigned long dirmask
, unsigned long df_conflicts
, struct name_entry
*names
, struct traverse_info
*info
)
164 struct tree_desc t
[MAX_UNPACK_TREES
];
165 struct traverse_info newinfo
;
166 struct name_entry
*p
;
175 newinfo
.pathlen
+= tree_entry_len(p
->path
, p
->sha1
) + 1;
176 newinfo
.conflicts
|= df_conflicts
;
178 for (i
= 0; i
< n
; i
++, dirmask
>>= 1) {
179 const unsigned char *sha1
= NULL
;
181 sha1
= names
[i
].sha1
;
182 fill_tree_descriptor(t
+i
, sha1
);
184 return traverse_trees(n
, t
, &newinfo
);
188 * Compare the traverse-path to the cache entry without actually
189 * having to generate the textual representation of the traverse
192 * NOTE! This *only* compares up to the size of the traverse path
193 * itself - the caller needs to do the final check for the cache
194 * entry having more data at the end!
196 static int do_compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
198 int len
, pathlen
, ce_len
;
202 int cmp
= do_compare_entry(ce
, info
->prev
, &info
->name
);
206 pathlen
= info
->pathlen
;
207 ce_len
= ce_namelen(ce
);
209 /* If ce_len < pathlen then we must have previously hit "name == directory" entry */
210 if (ce_len
< pathlen
)
214 ce_name
= ce
->name
+ pathlen
;
216 len
= tree_entry_len(n
->path
, n
->sha1
);
217 return df_name_compare(ce_name
, ce_len
, S_IFREG
, n
->path
, len
, n
->mode
);
220 static int compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
222 int cmp
= do_compare_entry(ce
, info
, n
);
227 * Even if the beginning compared identically, the ce should
228 * compare as bigger than a directory leading up to it!
230 return ce_namelen(ce
) > traverse_path_len(info
, n
);
233 static struct cache_entry
*create_ce_entry(const struct traverse_info
*info
, const struct name_entry
*n
, int stage
)
235 int len
= traverse_path_len(info
, n
);
236 struct cache_entry
*ce
= xcalloc(1, cache_entry_size(len
));
238 ce
->ce_mode
= create_ce_mode(n
->mode
);
239 ce
->ce_flags
= create_ce_flags(len
, stage
);
240 hashcpy(ce
->sha1
, n
->sha1
);
241 make_traverse_path(ce
->name
, info
, n
);
246 static int unpack_nondirectories(int n
, unsigned long mask
,
247 unsigned long dirmask
,
248 struct cache_entry
**src
,
249 const struct name_entry
*names
,
250 const struct traverse_info
*info
)
253 struct unpack_trees_options
*o
= info
->data
;
254 unsigned long conflicts
;
256 /* Do we have *only* directories? Nothing to do */
257 if (mask
== dirmask
&& !src
[0])
260 conflicts
= info
->conflicts
;
263 conflicts
|= dirmask
;
266 * Ok, we've filled in up to any potential index entry in src[0],
269 for (i
= 0; i
< n
; i
++) {
271 unsigned int bit
= 1ul << i
;
272 if (conflicts
& bit
) {
273 src
[i
+ o
->merge
] = o
->df_conflict_entry
;
280 else if (i
+ 1 < o
->head_idx
)
282 else if (i
+ 1 > o
->head_idx
)
286 src
[i
+ o
->merge
] = create_ce_entry(info
, names
+ i
, stage
);
290 return call_unpack_fn(src
, o
);
293 for (i
= 0; i
< n
; i
++)
294 add_entry(o
, src
[i
], 0, 0);
298 static int unpack_callback(int n
, unsigned long mask
, unsigned long dirmask
, struct name_entry
*names
, struct traverse_info
*info
)
300 struct cache_entry
*src
[MAX_UNPACK_TREES
+ 1] = { NULL
, };
301 struct unpack_trees_options
*o
= info
->data
;
302 const struct name_entry
*p
= names
;
304 /* Find first entry with a real name (we could use "mask" too) */
308 /* Are we supposed to look at the index too? */
310 while (o
->pos
< o
->src_index
->cache_nr
) {
311 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
312 int cmp
= compare_entry(ce
, info
, p
);
314 if (unpack_index_entry(ce
, o
) < 0)
322 * If we skip unmerged index entries, we'll skip this
323 * entry *and* the tree entries associated with it!
325 if (o
->skip_unmerged
) {
326 add_entry(o
, ce
, 0, 0);
336 if (unpack_nondirectories(n
, mask
, dirmask
, src
, names
, info
) < 0)
339 /* Now handle any directories.. */
341 unsigned long conflicts
= mask
& ~dirmask
;
347 if (traverse_trees_recursive(n
, dirmask
, conflicts
,
356 static int unpack_failed(struct unpack_trees_options
*o
, const char *message
)
358 discard_index(&o
->result
);
361 return error("%s", message
);
368 * N-way merge "len" trees. Returns 0 on success, -1 on failure to manipulate the
369 * resulting index, -2 on failure to reflect the changes to the work tree.
371 int unpack_trees(unsigned len
, struct tree_desc
*t
, struct unpack_trees_options
*o
)
374 static struct cache_entry
*dfc
;
376 if (len
> MAX_UNPACK_TREES
)
377 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES
);
378 memset(&state
, 0, sizeof(state
));
382 state
.refresh_cache
= 1;
384 memset(&o
->result
, 0, sizeof(o
->result
));
385 o
->result
.initialized
= 1;
387 o
->result
.timestamp
= o
->src_index
->timestamp
;
391 dfc
= xcalloc(1, cache_entry_size(0));
392 o
->df_conflict_entry
= dfc
;
395 const char *prefix
= o
->prefix
? o
->prefix
: "";
396 struct traverse_info info
;
398 setup_traverse_info(&info
, prefix
);
399 info
.fn
= unpack_callback
;
402 if (traverse_trees(len
, t
, &info
) < 0)
403 return unpack_failed(o
, NULL
);
406 /* Any left-over entries in the index? */
408 while (o
->pos
< o
->src_index
->cache_nr
) {
409 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
410 if (unpack_index_entry(ce
, o
) < 0)
411 return unpack_failed(o
, NULL
);
415 if (o
->trivial_merges_only
&& o
->nontrivial_merge
)
416 return unpack_failed(o
, "Merge requires file-level merging");
419 ret
= check_updates(o
) ? (-2) : 0;
421 *o
->dst_index
= o
->result
;
425 /* Here come the merge functions */
427 static int reject_merge(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
429 return error(ERRORMSG(o
, would_overwrite
), ce
->name
);
432 static int same(struct cache_entry
*a
, struct cache_entry
*b
)
438 return a
->ce_mode
== b
->ce_mode
&&
439 !hashcmp(a
->sha1
, b
->sha1
);
444 * When a CE gets turned into an unmerged entry, we
445 * want it to be up-to-date
447 static int verify_uptodate(struct cache_entry
*ce
,
448 struct unpack_trees_options
*o
)
452 if (o
->index_only
|| o
->reset
)
455 if (!lstat(ce
->name
, &st
)) {
456 unsigned changed
= ie_match_stat(o
->src_index
, ce
, &st
, CE_MATCH_IGNORE_VALID
);
460 * NEEDSWORK: the current default policy is to allow
461 * submodule to be out of sync wrt the supermodule
462 * index. This needs to be tightened later for
463 * submodules that are marked to be automatically
466 if (S_ISGITLINK(ce
->ce_mode
))
472 return o
->gently
? -1 :
473 error(ERRORMSG(o
, not_uptodate_file
), ce
->name
);
476 static void invalidate_ce_path(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
479 cache_tree_invalidate_path(o
->src_index
->cache_tree
, ce
->name
);
483 * Check that checking out ce->sha1 in subdir ce->name is not
484 * going to overwrite any working files.
486 * Currently, git does not checkout subprojects during a superproject
487 * checkout, so it is not going to overwrite anything.
489 static int verify_clean_submodule(struct cache_entry
*ce
, const char *action
,
490 struct unpack_trees_options
*o
)
495 static int verify_clean_subdirectory(struct cache_entry
*ce
, const char *action
,
496 struct unpack_trees_options
*o
)
499 * we are about to extract "ce->name"; we would not want to lose
500 * anything in the existing directory there.
507 unsigned char sha1
[20];
509 if (S_ISGITLINK(ce
->ce_mode
) &&
510 resolve_gitlink_ref(ce
->name
, "HEAD", sha1
) == 0) {
511 /* If we are not going to update the submodule, then
514 if (!hashcmp(sha1
, ce
->sha1
))
516 return verify_clean_submodule(ce
, action
, o
);
520 * First let's make sure we do not have a local modification
523 namelen
= strlen(ce
->name
);
524 for (i
= o
->pos
; i
< o
->src_index
->cache_nr
; i
++) {
525 struct cache_entry
*ce2
= o
->src_index
->cache
[i
];
526 int len
= ce_namelen(ce2
);
528 strncmp(ce
->name
, ce2
->name
, namelen
) ||
529 ce2
->name
[namelen
] != '/')
532 * ce2->name is an entry in the subdirectory.
534 if (!ce_stage(ce2
)) {
535 if (verify_uptodate(ce2
, o
))
537 add_entry(o
, ce2
, CE_REMOVE
, 0);
543 * Then we need to make sure that we do not lose a locally
544 * present file that is not ignored.
546 pathbuf
= xmalloc(namelen
+ 2);
547 memcpy(pathbuf
, ce
->name
, namelen
);
548 strcpy(pathbuf
+namelen
, "/");
550 memset(&d
, 0, sizeof(d
));
552 d
.exclude_per_dir
= o
->dir
->exclude_per_dir
;
553 i
= read_directory(&d
, ce
->name
, pathbuf
, namelen
+1, NULL
);
555 return o
->gently
? -1 :
556 error(ERRORMSG(o
, not_uptodate_dir
), ce
->name
);
562 * This gets called when there was no index entry for the tree entry 'dst',
563 * but we found a file in the working tree that 'lstat()' said was fine,
564 * and we're on a case-insensitive filesystem.
566 * See if we can find a case-insensitive match in the index that also
567 * matches the stat information, and assume it's that other file!
569 static int icase_exists(struct unpack_trees_options
*o
, struct cache_entry
*dst
, struct stat
*st
)
571 struct cache_entry
*src
;
573 src
= index_name_exists(o
->src_index
, dst
->name
, ce_namelen(dst
), 1);
574 return src
&& !ie_match_stat(o
->src_index
, src
, st
, CE_MATCH_IGNORE_VALID
);
578 * We do not want to remove or overwrite a working tree file that
579 * is not tracked, unless it is ignored.
581 static int verify_absent(struct cache_entry
*ce
, const char *action
,
582 struct unpack_trees_options
*o
)
586 if (o
->index_only
|| o
->reset
|| !o
->update
)
589 if (has_symlink_or_noent_leading_path(ce_namelen(ce
), ce
->name
))
592 if (!lstat(ce
->name
, &st
)) {
594 int dtype
= ce_to_dtype(ce
);
595 struct cache_entry
*result
;
598 * It may be that the 'lstat()' succeeded even though
599 * target 'ce' was absent, because there is an old
600 * entry that is different only in case..
602 * Ignore that lstat() if it matches.
604 if (ignore_case
&& icase_exists(o
, ce
, &st
))
607 if (o
->dir
&& excluded(o
->dir
, ce
->name
, &dtype
))
609 * ce->name is explicitly excluded, so it is Ok to
613 if (S_ISDIR(st
.st_mode
)) {
615 * We are checking out path "foo" and
616 * found "foo/." in the working tree.
617 * This is tricky -- if we have modified
618 * files that are in "foo/" we would lose
621 ret
= verify_clean_subdirectory(ce
, action
, o
);
626 * If this removed entries from the index,
627 * what that means is:
629 * (1) the caller unpack_callback() saw path/foo
630 * in the index, and it has not removed it because
631 * it thinks it is handling 'path' as blob with
633 * (2) we will return "ok, we placed a merged entry
634 * in the index" which would cause o->pos to be
635 * incremented by one;
636 * (3) however, original o->pos now has 'path/foo'
637 * marked with "to be removed".
639 * We need to increment it by the number of
640 * deleted entries here.
647 * The previous round may already have decided to
648 * delete this path, which is in a subdirectory that
649 * is being replaced with a blob.
651 result
= index_name_exists(&o
->result
, ce
->name
, ce_namelen(ce
), 0);
653 if (result
->ce_flags
& CE_REMOVE
)
657 return o
->gently
? -1 :
658 error(ERRORMSG(o
, would_lose_untracked
), ce
->name
, action
);
663 static int merged_entry(struct cache_entry
*merge
, struct cache_entry
*old
,
664 struct unpack_trees_options
*o
)
666 int update
= CE_UPDATE
;
670 * See if we can re-use the old CE directly?
671 * That way we get the uptodate stat info.
673 * This also removes the UPDATE flag on a match; otherwise
674 * we will end up overwriting local changes in the work tree.
676 if (same(old
, merge
)) {
677 copy_cache_entry(merge
, old
);
680 if (verify_uptodate(old
, o
))
682 invalidate_ce_path(old
, o
);
686 if (verify_absent(merge
, "overwritten", o
))
688 invalidate_ce_path(merge
, o
);
691 add_entry(o
, merge
, update
, CE_STAGEMASK
);
695 static int deleted_entry(struct cache_entry
*ce
, struct cache_entry
*old
,
696 struct unpack_trees_options
*o
)
698 /* Did it exist in the index? */
700 if (verify_absent(ce
, "removed", o
))
704 if (verify_uptodate(old
, o
))
706 add_entry(o
, ce
, CE_REMOVE
, 0);
707 invalidate_ce_path(ce
, o
);
711 static int keep_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
713 add_entry(o
, ce
, 0, 0);
718 static void show_stage_entry(FILE *o
,
719 const char *label
, const struct cache_entry
*ce
)
722 fprintf(o
, "%s (missing)\n", label
);
724 fprintf(o
, "%s%06o %s %d\t%s\n",
727 sha1_to_hex(ce
->sha1
),
733 int threeway_merge(struct cache_entry
**stages
, struct unpack_trees_options
*o
)
735 struct cache_entry
*index
;
736 struct cache_entry
*head
;
737 struct cache_entry
*remote
= stages
[o
->head_idx
+ 1];
740 int remote_match
= 0;
742 int df_conflict_head
= 0;
743 int df_conflict_remote
= 0;
745 int any_anc_missing
= 0;
746 int no_anc_exists
= 1;
749 for (i
= 1; i
< o
->head_idx
; i
++) {
750 if (!stages
[i
] || stages
[i
] == o
->df_conflict_entry
)
757 head
= stages
[o
->head_idx
];
759 if (head
== o
->df_conflict_entry
) {
760 df_conflict_head
= 1;
764 if (remote
== o
->df_conflict_entry
) {
765 df_conflict_remote
= 1;
769 /* First, if there's a #16 situation, note that to prevent #13
772 if (!same(remote
, head
)) {
773 for (i
= 1; i
< o
->head_idx
; i
++) {
774 if (same(stages
[i
], head
)) {
777 if (same(stages
[i
], remote
)) {
783 /* We start with cases where the index is allowed to match
784 * something other than the head: #14(ALT) and #2ALT, where it
785 * is permitted to match the result instead.
787 /* #14, #14ALT, #2ALT */
788 if (remote
&& !df_conflict_head
&& head_match
&& !remote_match
) {
789 if (index
&& !same(index
, remote
) && !same(index
, head
))
790 return o
->gently
? -1 : reject_merge(index
, o
);
791 return merged_entry(remote
, index
, o
);
794 * If we have an entry in the index cache, then we want to
795 * make sure that it matches head.
797 if (index
&& !same(index
, head
))
798 return o
->gently
? -1 : reject_merge(index
, o
);
802 if (same(head
, remote
))
803 return merged_entry(head
, index
, o
);
805 if (!df_conflict_remote
&& remote_match
&& !head_match
)
806 return merged_entry(head
, index
, o
);
810 if (!head
&& !remote
&& any_anc_missing
)
813 /* Under the new "aggressive" rule, we resolve mostly trivial
814 * cases that we historically had git-merge-one-file resolve.
817 int head_deleted
= !head
&& !df_conflict_head
;
818 int remote_deleted
= !remote
&& !df_conflict_remote
;
819 struct cache_entry
*ce
= NULL
;
828 for (i
= 1; i
< o
->head_idx
; i
++) {
829 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
838 * Deleted in one and unchanged in the other.
840 if ((head_deleted
&& remote_deleted
) ||
841 (head_deleted
&& remote
&& remote_match
) ||
842 (remote_deleted
&& head
&& head_match
)) {
844 return deleted_entry(index
, index
, o
);
845 if (ce
&& !head_deleted
) {
846 if (verify_absent(ce
, "removed", o
))
852 * Added in both, identically.
854 if (no_anc_exists
&& head
&& remote
&& same(head
, remote
))
855 return merged_entry(head
, index
, o
);
859 /* Below are "no merge" cases, which require that the index be
860 * up-to-date to avoid the files getting overwritten with
861 * conflict resolution files.
864 if (verify_uptodate(index
, o
))
868 o
->nontrivial_merge
= 1;
870 /* #2, #3, #4, #6, #7, #9, #10, #11. */
872 if (!head_match
|| !remote_match
) {
873 for (i
= 1; i
< o
->head_idx
; i
++) {
874 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
875 keep_entry(stages
[i
], o
);
883 fprintf(stderr
, "read-tree: warning #16 detected\n");
884 show_stage_entry(stderr
, "head ", stages
[head_match
]);
885 show_stage_entry(stderr
, "remote ", stages
[remote_match
]);
888 if (head
) { count
+= keep_entry(head
, o
); }
889 if (remote
) { count
+= keep_entry(remote
, o
); }
896 * The rule is to "carry forward" what is in the index without losing
897 * information across a "fast forward", favoring a successful merge
898 * over a merge failure when it makes sense. For details of the
899 * "carry forward" rule, please see <Documentation/git-read-tree.txt>.
902 int twoway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
904 struct cache_entry
*current
= src
[0];
905 struct cache_entry
*oldtree
= src
[1];
906 struct cache_entry
*newtree
= src
[2];
908 if (o
->merge_size
!= 2)
909 return error("Cannot do a twoway merge of %d trees",
912 if (oldtree
== o
->df_conflict_entry
)
914 if (newtree
== o
->df_conflict_entry
)
918 if ((!oldtree
&& !newtree
) || /* 4 and 5 */
919 (!oldtree
&& newtree
&&
920 same(current
, newtree
)) || /* 6 and 7 */
921 (oldtree
&& newtree
&&
922 same(oldtree
, newtree
)) || /* 14 and 15 */
923 (oldtree
&& newtree
&&
924 !same(oldtree
, newtree
) && /* 18 and 19 */
925 same(current
, newtree
))) {
926 return keep_entry(current
, o
);
928 else if (oldtree
&& !newtree
&& same(current
, oldtree
)) {
930 return deleted_entry(oldtree
, current
, o
);
932 else if (oldtree
&& newtree
&&
933 same(current
, oldtree
) && !same(current
, newtree
)) {
935 return merged_entry(newtree
, current
, o
);
938 /* all other failures */
940 return o
->gently
? -1 : reject_merge(oldtree
, o
);
942 return o
->gently
? -1 : reject_merge(current
, o
);
944 return o
->gently
? -1 : reject_merge(newtree
, o
);
949 if (oldtree
&& !o
->initial_checkout
) {
951 * deletion of the path was staged;
953 if (same(oldtree
, newtree
))
955 return reject_merge(oldtree
, o
);
957 return merged_entry(newtree
, current
, o
);
959 return deleted_entry(oldtree
, current
, o
);
965 * Keep the index entries at stage0, collapse stage1 but make sure
966 * stage0 does not have anything there.
968 int bind_merge(struct cache_entry
**src
,
969 struct unpack_trees_options
*o
)
971 struct cache_entry
*old
= src
[0];
972 struct cache_entry
*a
= src
[1];
974 if (o
->merge_size
!= 1)
975 return error("Cannot do a bind merge of %d trees\n",
978 return o
->gently
? -1 :
979 error(ERRORMSG(o
, bind_overlap
), a
->name
, old
->name
);
981 return keep_entry(old
, o
);
983 return merged_entry(a
, NULL
, o
);
990 * - take the stat information from stage0, take the data from stage1
992 int oneway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
994 struct cache_entry
*old
= src
[0];
995 struct cache_entry
*a
= src
[1];
997 if (o
->merge_size
!= 1)
998 return error("Cannot do a oneway merge of %d trees",
1002 return deleted_entry(old
, old
, o
);
1004 if (old
&& same(old
, a
)) {
1008 if (lstat(old
->name
, &st
) ||
1009 ie_match_stat(o
->src_index
, old
, &st
, CE_MATCH_IGNORE_VALID
))
1010 update
|= CE_UPDATE
;
1012 add_entry(o
, old
, update
, 0);
1015 return merged_entry(a
, old
, o
);