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
)))
64 if (unlink_or_warn(ce
->name
))
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",
91 git_attr_set_direction(GIT_ATTR_CHECKOUT
, &o
->result
);
92 for (i
= 0; i
< index
->cache_nr
; i
++) {
93 struct cache_entry
*ce
= index
->cache
[i
];
95 if (ce
->ce_flags
& CE_REMOVE
) {
96 display_progress(progress
, ++cnt
);
101 remove_marked_cache_entries(&o
->result
);
102 remove_scheduled_dirs();
104 for (i
= 0; i
< index
->cache_nr
; i
++) {
105 struct cache_entry
*ce
= index
->cache
[i
];
107 if (ce
->ce_flags
& CE_UPDATE
) {
108 display_progress(progress
, ++cnt
);
109 ce
->ce_flags
&= ~CE_UPDATE
;
111 errs
|= checkout_entry(ce
, &state
, NULL
);
115 stop_progress(&progress
);
117 git_attr_set_direction(GIT_ATTR_CHECKIN
, NULL
);
121 static inline int call_unpack_fn(struct cache_entry
**src
, struct unpack_trees_options
*o
)
123 int ret
= o
->fn(src
, o
);
129 static int unpack_index_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
131 struct cache_entry
*src
[5] = { ce
, };
135 if (o
->skip_unmerged
) {
136 add_entry(o
, ce
, 0, 0);
140 return call_unpack_fn(src
, o
);
143 int traverse_trees_recursive(int n
, unsigned long dirmask
, unsigned long df_conflicts
, struct name_entry
*names
, struct traverse_info
*info
)
146 struct tree_desc t
[MAX_UNPACK_TREES
];
147 struct traverse_info newinfo
;
148 struct name_entry
*p
;
157 newinfo
.pathlen
+= tree_entry_len(p
->path
, p
->sha1
) + 1;
158 newinfo
.conflicts
|= df_conflicts
;
160 for (i
= 0; i
< n
; i
++, dirmask
>>= 1) {
161 const unsigned char *sha1
= NULL
;
163 sha1
= names
[i
].sha1
;
164 fill_tree_descriptor(t
+i
, sha1
);
166 return traverse_trees(n
, t
, &newinfo
);
170 * Compare the traverse-path to the cache entry without actually
171 * having to generate the textual representation of the traverse
174 * NOTE! This *only* compares up to the size of the traverse path
175 * itself - the caller needs to do the final check for the cache
176 * entry having more data at the end!
178 static int do_compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
180 int len
, pathlen
, ce_len
;
184 int cmp
= do_compare_entry(ce
, info
->prev
, &info
->name
);
188 pathlen
= info
->pathlen
;
189 ce_len
= ce_namelen(ce
);
191 /* If ce_len < pathlen then we must have previously hit "name == directory" entry */
192 if (ce_len
< pathlen
)
196 ce_name
= ce
->name
+ pathlen
;
198 len
= tree_entry_len(n
->path
, n
->sha1
);
199 return df_name_compare(ce_name
, ce_len
, S_IFREG
, n
->path
, len
, n
->mode
);
202 static int compare_entry(const struct cache_entry
*ce
, const struct traverse_info
*info
, const struct name_entry
*n
)
204 int cmp
= do_compare_entry(ce
, info
, n
);
209 * Even if the beginning compared identically, the ce should
210 * compare as bigger than a directory leading up to it!
212 return ce_namelen(ce
) > traverse_path_len(info
, n
);
215 static struct cache_entry
*create_ce_entry(const struct traverse_info
*info
, const struct name_entry
*n
, int stage
)
217 int len
= traverse_path_len(info
, n
);
218 struct cache_entry
*ce
= xcalloc(1, cache_entry_size(len
));
220 ce
->ce_mode
= create_ce_mode(n
->mode
);
221 ce
->ce_flags
= create_ce_flags(len
, stage
);
222 hashcpy(ce
->sha1
, n
->sha1
);
223 make_traverse_path(ce
->name
, info
, n
);
228 static int unpack_nondirectories(int n
, unsigned long mask
,
229 unsigned long dirmask
,
230 struct cache_entry
**src
,
231 const struct name_entry
*names
,
232 const struct traverse_info
*info
)
235 struct unpack_trees_options
*o
= info
->data
;
236 unsigned long conflicts
;
238 /* Do we have *only* directories? Nothing to do */
239 if (mask
== dirmask
&& !src
[0])
242 conflicts
= info
->conflicts
;
245 conflicts
|= dirmask
;
248 * Ok, we've filled in up to any potential index entry in src[0],
251 for (i
= 0; i
< n
; i
++) {
253 unsigned int bit
= 1ul << i
;
254 if (conflicts
& bit
) {
255 src
[i
+ o
->merge
] = o
->df_conflict_entry
;
262 else if (i
+ 1 < o
->head_idx
)
264 else if (i
+ 1 > o
->head_idx
)
268 src
[i
+ o
->merge
] = create_ce_entry(info
, names
+ i
, stage
);
272 return call_unpack_fn(src
, o
);
274 for (i
= 0; i
< n
; i
++)
275 if (src
[i
] && src
[i
] != o
->df_conflict_entry
)
276 add_entry(o
, src
[i
], 0, 0);
280 static int unpack_callback(int n
, unsigned long mask
, unsigned long dirmask
, struct name_entry
*names
, struct traverse_info
*info
)
282 struct cache_entry
*src
[MAX_UNPACK_TREES
+ 1] = { NULL
, };
283 struct unpack_trees_options
*o
= info
->data
;
284 const struct name_entry
*p
= names
;
286 /* Find first entry with a real name (we could use "mask" too) */
290 /* Are we supposed to look at the index too? */
292 while (o
->pos
< o
->src_index
->cache_nr
) {
293 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
294 int cmp
= compare_entry(ce
, info
, p
);
296 if (unpack_index_entry(ce
, o
) < 0)
304 * If we skip unmerged index entries, we'll skip this
305 * entry *and* the tree entries associated with it!
307 if (o
->skip_unmerged
) {
308 add_entry(o
, ce
, 0, 0);
318 if (unpack_nondirectories(n
, mask
, dirmask
, src
, names
, info
) < 0)
321 /* Now handle any directories.. */
323 unsigned long conflicts
= mask
& ~dirmask
;
330 /* special case: "diff-index --cached" looking at a tree */
331 if (o
->diff_index_cached
&&
332 n
== 1 && dirmask
== 1 && S_ISDIR(names
->mode
)) {
334 matches
= cache_tree_matches_traversal(o
->src_index
->cache_tree
,
337 * Everything under the name matches. Adjust o->pos to
338 * skip the entire hierarchy.
346 if (traverse_trees_recursive(n
, dirmask
, conflicts
,
355 static int unpack_failed(struct unpack_trees_options
*o
, const char *message
)
357 discard_index(&o
->result
);
360 return error("%s", message
);
367 * N-way merge "len" trees. Returns 0 on success, -1 on failure to manipulate the
368 * resulting index, -2 on failure to reflect the changes to the work tree.
370 int unpack_trees(unsigned len
, struct tree_desc
*t
, struct unpack_trees_options
*o
)
373 static struct cache_entry
*dfc
;
375 if (len
> MAX_UNPACK_TREES
)
376 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES
);
377 memset(&state
, 0, sizeof(state
));
381 state
.refresh_cache
= 1;
383 memset(&o
->result
, 0, sizeof(o
->result
));
384 o
->result
.initialized
= 1;
386 o
->result
.timestamp
.sec
= o
->src_index
->timestamp
.sec
;
387 o
->result
.timestamp
.nsec
= o
->src_index
->timestamp
.nsec
;
392 dfc
= xcalloc(1, cache_entry_size(0));
393 o
->df_conflict_entry
= dfc
;
396 const char *prefix
= o
->prefix
? o
->prefix
: "";
397 struct traverse_info info
;
399 setup_traverse_info(&info
, prefix
);
400 info
.fn
= unpack_callback
;
403 if (traverse_trees(len
, t
, &info
) < 0)
404 return unpack_failed(o
, NULL
);
407 /* Any left-over entries in the index? */
409 while (o
->pos
< o
->src_index
->cache_nr
) {
410 struct cache_entry
*ce
= o
->src_index
->cache
[o
->pos
];
411 if (unpack_index_entry(ce
, o
) < 0)
412 return unpack_failed(o
, NULL
);
416 if (o
->trivial_merges_only
&& o
->nontrivial_merge
)
417 return unpack_failed(o
, "Merge requires file-level merging");
420 ret
= check_updates(o
) ? (-2) : 0;
422 *o
->dst_index
= o
->result
;
426 /* Here come the merge functions */
428 static int reject_merge(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
430 return error(ERRORMSG(o
, would_overwrite
), ce
->name
);
433 static int same(struct cache_entry
*a
, struct cache_entry
*b
)
439 return a
->ce_mode
== b
->ce_mode
&&
440 !hashcmp(a
->sha1
, b
->sha1
);
445 * When a CE gets turned into an unmerged entry, we
446 * want it to be up-to-date
448 static int verify_uptodate(struct cache_entry
*ce
,
449 struct unpack_trees_options
*o
)
453 if (o
->index_only
|| o
->reset
|| ce_uptodate(ce
))
456 if (!lstat(ce
->name
, &st
)) {
457 unsigned changed
= ie_match_stat(o
->src_index
, ce
, &st
, CE_MATCH_IGNORE_VALID
);
461 * NEEDSWORK: the current default policy is to allow
462 * submodule to be out of sync wrt the supermodule
463 * index. This needs to be tightened later for
464 * submodules that are marked to be automatically
467 if (S_ISGITLINK(ce
->ce_mode
))
473 return o
->gently
? -1 :
474 error(ERRORMSG(o
, not_uptodate_file
), ce
->name
);
477 static void invalidate_ce_path(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
480 cache_tree_invalidate_path(o
->src_index
->cache_tree
, ce
->name
);
484 * Check that checking out ce->sha1 in subdir ce->name is not
485 * going to overwrite any working files.
487 * Currently, git does not checkout subprojects during a superproject
488 * checkout, so it is not going to overwrite anything.
490 static int verify_clean_submodule(struct cache_entry
*ce
, const char *action
,
491 struct unpack_trees_options
*o
)
496 static int verify_clean_subdirectory(struct cache_entry
*ce
, const char *action
,
497 struct unpack_trees_options
*o
)
500 * we are about to extract "ce->name"; we would not want to lose
501 * anything in the existing directory there.
508 unsigned char sha1
[20];
510 if (S_ISGITLINK(ce
->ce_mode
) &&
511 resolve_gitlink_ref(ce
->name
, "HEAD", sha1
) == 0) {
512 /* If we are not going to update the submodule, then
515 if (!hashcmp(sha1
, ce
->sha1
))
517 return verify_clean_submodule(ce
, action
, o
);
521 * First let's make sure we do not have a local modification
524 namelen
= strlen(ce
->name
);
525 for (i
= o
->pos
; i
< o
->src_index
->cache_nr
; i
++) {
526 struct cache_entry
*ce2
= o
->src_index
->cache
[i
];
527 int len
= ce_namelen(ce2
);
529 strncmp(ce
->name
, ce2
->name
, namelen
) ||
530 ce2
->name
[namelen
] != '/')
533 * ce2->name is an entry in the subdirectory.
535 if (!ce_stage(ce2
)) {
536 if (verify_uptodate(ce2
, o
))
538 add_entry(o
, ce2
, CE_REMOVE
, 0);
544 * Then we need to make sure that we do not lose a locally
545 * present file that is not ignored.
547 pathbuf
= xmalloc(namelen
+ 2);
548 memcpy(pathbuf
, ce
->name
, namelen
);
549 strcpy(pathbuf
+namelen
, "/");
551 memset(&d
, 0, sizeof(d
));
553 d
.exclude_per_dir
= o
->dir
->exclude_per_dir
;
554 i
= read_directory(&d
, ce
->name
, pathbuf
, namelen
+1, NULL
);
556 return o
->gently
? -1 :
557 error(ERRORMSG(o
, not_uptodate_dir
), ce
->name
);
563 * This gets called when there was no index entry for the tree entry 'dst',
564 * but we found a file in the working tree that 'lstat()' said was fine,
565 * and we're on a case-insensitive filesystem.
567 * See if we can find a case-insensitive match in the index that also
568 * matches the stat information, and assume it's that other file!
570 static int icase_exists(struct unpack_trees_options
*o
, struct cache_entry
*dst
, struct stat
*st
)
572 struct cache_entry
*src
;
574 src
= index_name_exists(o
->src_index
, dst
->name
, ce_namelen(dst
), 1);
575 return src
&& !ie_match_stat(o
->src_index
, src
, st
, CE_MATCH_IGNORE_VALID
);
579 * We do not want to remove or overwrite a working tree file that
580 * is not tracked, unless it is ignored.
582 static int verify_absent(struct cache_entry
*ce
, const char *action
,
583 struct unpack_trees_options
*o
)
587 if (o
->index_only
|| o
->reset
|| !o
->update
)
590 if (has_symlink_or_noent_leading_path(ce
->name
, ce_namelen(ce
)))
593 if (!lstat(ce
->name
, &st
)) {
595 int dtype
= ce_to_dtype(ce
);
596 struct cache_entry
*result
;
599 * It may be that the 'lstat()' succeeded even though
600 * target 'ce' was absent, because there is an old
601 * entry that is different only in case..
603 * Ignore that lstat() if it matches.
605 if (ignore_case
&& icase_exists(o
, ce
, &st
))
608 if (o
->dir
&& excluded(o
->dir
, ce
->name
, &dtype
))
610 * ce->name is explicitly excluded, so it is Ok to
614 if (S_ISDIR(st
.st_mode
)) {
616 * We are checking out path "foo" and
617 * found "foo/." in the working tree.
618 * This is tricky -- if we have modified
619 * files that are in "foo/" we would lose
622 ret
= verify_clean_subdirectory(ce
, action
, o
);
627 * If this removed entries from the index,
628 * what that means is:
630 * (1) the caller unpack_callback() saw path/foo
631 * in the index, and it has not removed it because
632 * it thinks it is handling 'path' as blob with
634 * (2) we will return "ok, we placed a merged entry
635 * in the index" which would cause o->pos to be
636 * incremented by one;
637 * (3) however, original o->pos now has 'path/foo'
638 * marked with "to be removed".
640 * We need to increment it by the number of
641 * deleted entries here.
648 * The previous round may already have decided to
649 * delete this path, which is in a subdirectory that
650 * is being replaced with a blob.
652 result
= index_name_exists(&o
->result
, ce
->name
, ce_namelen(ce
), 0);
654 if (result
->ce_flags
& CE_REMOVE
)
658 return o
->gently
? -1 :
659 error(ERRORMSG(o
, would_lose_untracked
), ce
->name
, action
);
664 static int merged_entry(struct cache_entry
*merge
, struct cache_entry
*old
,
665 struct unpack_trees_options
*o
)
667 int update
= CE_UPDATE
;
671 * See if we can re-use the old CE directly?
672 * That way we get the uptodate stat info.
674 * This also removes the UPDATE flag on a match; otherwise
675 * we will end up overwriting local changes in the work tree.
677 if (same(old
, merge
)) {
678 copy_cache_entry(merge
, old
);
681 if (verify_uptodate(old
, o
))
683 invalidate_ce_path(old
, o
);
687 if (verify_absent(merge
, "overwritten", o
))
689 invalidate_ce_path(merge
, o
);
692 add_entry(o
, merge
, update
, CE_STAGEMASK
);
696 static int deleted_entry(struct cache_entry
*ce
, struct cache_entry
*old
,
697 struct unpack_trees_options
*o
)
699 /* Did it exist in the index? */
701 if (verify_absent(ce
, "removed", o
))
705 if (verify_uptodate(old
, o
))
707 add_entry(o
, ce
, CE_REMOVE
, 0);
708 invalidate_ce_path(ce
, o
);
712 static int keep_entry(struct cache_entry
*ce
, struct unpack_trees_options
*o
)
714 add_entry(o
, ce
, 0, 0);
719 static void show_stage_entry(FILE *o
,
720 const char *label
, const struct cache_entry
*ce
)
723 fprintf(o
, "%s (missing)\n", label
);
725 fprintf(o
, "%s%06o %s %d\t%s\n",
728 sha1_to_hex(ce
->sha1
),
734 int threeway_merge(struct cache_entry
**stages
, struct unpack_trees_options
*o
)
736 struct cache_entry
*index
;
737 struct cache_entry
*head
;
738 struct cache_entry
*remote
= stages
[o
->head_idx
+ 1];
741 int remote_match
= 0;
743 int df_conflict_head
= 0;
744 int df_conflict_remote
= 0;
746 int any_anc_missing
= 0;
747 int no_anc_exists
= 1;
750 for (i
= 1; i
< o
->head_idx
; i
++) {
751 if (!stages
[i
] || stages
[i
] == o
->df_conflict_entry
)
758 head
= stages
[o
->head_idx
];
760 if (head
== o
->df_conflict_entry
) {
761 df_conflict_head
= 1;
765 if (remote
== o
->df_conflict_entry
) {
766 df_conflict_remote
= 1;
770 /* First, if there's a #16 situation, note that to prevent #13
773 if (!same(remote
, head
)) {
774 for (i
= 1; i
< o
->head_idx
; i
++) {
775 if (same(stages
[i
], head
)) {
778 if (same(stages
[i
], remote
)) {
784 /* We start with cases where the index is allowed to match
785 * something other than the head: #14(ALT) and #2ALT, where it
786 * is permitted to match the result instead.
788 /* #14, #14ALT, #2ALT */
789 if (remote
&& !df_conflict_head
&& head_match
&& !remote_match
) {
790 if (index
&& !same(index
, remote
) && !same(index
, head
))
791 return o
->gently
? -1 : reject_merge(index
, o
);
792 return merged_entry(remote
, index
, o
);
795 * If we have an entry in the index cache, then we want to
796 * make sure that it matches head.
798 if (index
&& !same(index
, head
))
799 return o
->gently
? -1 : reject_merge(index
, o
);
803 if (same(head
, remote
))
804 return merged_entry(head
, index
, o
);
806 if (!df_conflict_remote
&& remote_match
&& !head_match
)
807 return merged_entry(head
, index
, o
);
811 if (!head
&& !remote
&& any_anc_missing
)
814 /* Under the new "aggressive" rule, we resolve mostly trivial
815 * cases that we historically had git-merge-one-file resolve.
818 int head_deleted
= !head
&& !df_conflict_head
;
819 int remote_deleted
= !remote
&& !df_conflict_remote
;
820 struct cache_entry
*ce
= NULL
;
829 for (i
= 1; i
< o
->head_idx
; i
++) {
830 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
839 * Deleted in one and unchanged in the other.
841 if ((head_deleted
&& remote_deleted
) ||
842 (head_deleted
&& remote
&& remote_match
) ||
843 (remote_deleted
&& head
&& head_match
)) {
845 return deleted_entry(index
, index
, o
);
846 if (ce
&& !head_deleted
) {
847 if (verify_absent(ce
, "removed", o
))
853 * Added in both, identically.
855 if (no_anc_exists
&& head
&& remote
&& same(head
, remote
))
856 return merged_entry(head
, index
, o
);
860 /* Below are "no merge" cases, which require that the index be
861 * up-to-date to avoid the files getting overwritten with
862 * conflict resolution files.
865 if (verify_uptodate(index
, o
))
869 o
->nontrivial_merge
= 1;
871 /* #2, #3, #4, #6, #7, #9, #10, #11. */
873 if (!head_match
|| !remote_match
) {
874 for (i
= 1; i
< o
->head_idx
; i
++) {
875 if (stages
[i
] && stages
[i
] != o
->df_conflict_entry
) {
876 keep_entry(stages
[i
], o
);
884 fprintf(stderr
, "read-tree: warning #16 detected\n");
885 show_stage_entry(stderr
, "head ", stages
[head_match
]);
886 show_stage_entry(stderr
, "remote ", stages
[remote_match
]);
889 if (head
) { count
+= keep_entry(head
, o
); }
890 if (remote
) { count
+= keep_entry(remote
, o
); }
897 * The rule is to "carry forward" what is in the index without losing
898 * information across a "fast forward", favoring a successful merge
899 * over a merge failure when it makes sense. For details of the
900 * "carry forward" rule, please see <Documentation/git-read-tree.txt>.
903 int twoway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
905 struct cache_entry
*current
= src
[0];
906 struct cache_entry
*oldtree
= src
[1];
907 struct cache_entry
*newtree
= src
[2];
909 if (o
->merge_size
!= 2)
910 return error("Cannot do a twoway merge of %d trees",
913 if (oldtree
== o
->df_conflict_entry
)
915 if (newtree
== o
->df_conflict_entry
)
919 if ((!oldtree
&& !newtree
) || /* 4 and 5 */
920 (!oldtree
&& newtree
&&
921 same(current
, newtree
)) || /* 6 and 7 */
922 (oldtree
&& newtree
&&
923 same(oldtree
, newtree
)) || /* 14 and 15 */
924 (oldtree
&& newtree
&&
925 !same(oldtree
, newtree
) && /* 18 and 19 */
926 same(current
, newtree
))) {
927 return keep_entry(current
, o
);
929 else if (oldtree
&& !newtree
&& same(current
, oldtree
)) {
931 return deleted_entry(oldtree
, current
, o
);
933 else if (oldtree
&& newtree
&&
934 same(current
, oldtree
) && !same(current
, newtree
)) {
936 return merged_entry(newtree
, current
, o
);
939 /* all other failures */
941 return o
->gently
? -1 : reject_merge(oldtree
, o
);
943 return o
->gently
? -1 : reject_merge(current
, o
);
945 return o
->gently
? -1 : reject_merge(newtree
, o
);
950 if (oldtree
&& !o
->initial_checkout
) {
952 * deletion of the path was staged;
954 if (same(oldtree
, newtree
))
956 return reject_merge(oldtree
, o
);
958 return merged_entry(newtree
, current
, o
);
960 return deleted_entry(oldtree
, current
, o
);
966 * Keep the index entries at stage0, collapse stage1 but make sure
967 * stage0 does not have anything there.
969 int bind_merge(struct cache_entry
**src
,
970 struct unpack_trees_options
*o
)
972 struct cache_entry
*old
= src
[0];
973 struct cache_entry
*a
= src
[1];
975 if (o
->merge_size
!= 1)
976 return error("Cannot do a bind merge of %d trees\n",
979 return o
->gently
? -1 :
980 error(ERRORMSG(o
, bind_overlap
), a
->name
, old
->name
);
982 return keep_entry(old
, o
);
984 return merged_entry(a
, NULL
, o
);
991 * - take the stat information from stage0, take the data from stage1
993 int oneway_merge(struct cache_entry
**src
, struct unpack_trees_options
*o
)
995 struct cache_entry
*old
= src
[0];
996 struct cache_entry
*a
= src
[1];
998 if (o
->merge_size
!= 1)
999 return error("Cannot do a oneway merge of %d trees",
1003 return deleted_entry(old
, old
, o
);
1005 if (old
&& same(old
, a
)) {
1009 if (lstat(old
->name
, &st
) ||
1010 ie_match_stat(o
->src_index
, old
, &st
, CE_MATCH_IGNORE_VALID
))
1011 update
|= CE_UPDATE
;
1013 add_entry(o
, old
, update
, 0);
1016 return merged_entry(a
, old
, o
);