Skip to content

Commit f27c170

Browse files
vdyegitster
authored andcommitted
read-tree: make three-way merge sparse-aware
Enable use of 'merged_sparse_dir' in 'threeway_merge'. As with two-way merge, the contents of each conflicted sparse directory are merged without referencing the index, avoiding sparse index expansion. As with two-way merge, the 't/t1092-sparse-checkout-compatibility.sh' test 'read-tree --merge with edit/edit conflicts in sparse directories' confirms that three-way merges with edit/edit changes (both with and without conflicts) inside a sparse directory result in the correct index state or error message. To ensure the index is not unnecessarily expanded, add three-way merge cases to 'sparse index is not expanded: read-tree'. Signed-off-by: Victoria Dye <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab81047 commit f27c170

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

builtin/read-tree.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
234234
break;
235235
case 3:
236236
default:
237-
/*
238-
* TODO: update threeway_merge to handle edit/edit conflicts in
239-
* sparse directories.
240-
*/
241-
ensure_full_index(&the_index);
242237
opts.fn = threeway_merge;
243238
break;
244239
}

t/t1092-sparse-checkout-compatibility.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,9 @@ test_expect_success 'sparse index is not expanded: read-tree' '
14131413
init_repos &&
14141414
14151415
ensure_not_expanded checkout -b test-branch update-folder1 &&
1416-
for MERGE_TREES in "base update-folder2" \
1416+
for MERGE_TREES in "base HEAD update-folder2" \
1417+
"base HEAD rename-base" \
1418+
"base update-folder2" \
14171419
"base rename-base" \
14181420
"update-folder2"
14191421
do

unpack-trees.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,16 +2643,24 @@ int threeway_merge(const struct cache_entry * const *stages,
26432643
*/
26442644
/* #14, #14ALT, #2ALT */
26452645
if (remote && !df_conflict_head && head_match && !remote_match) {
2646-
if (index && !same(index, remote) && !same(index, head))
2647-
return reject_merge(index, o);
2646+
if (index && !same(index, remote) && !same(index, head)) {
2647+
if (S_ISSPARSEDIR(index->ce_mode))
2648+
return merged_sparse_dir(stages, 4, o);
2649+
else
2650+
return reject_merge(index, o);
2651+
}
26482652
return merged_entry(remote, index, o);
26492653
}
26502654
/*
26512655
* If we have an entry in the index cache, then we want to
26522656
* make sure that it matches head.
26532657
*/
2654-
if (index && !same(index, head))
2655-
return reject_merge(index, o);
2658+
if (index && !same(index, head)) {
2659+
if (S_ISSPARSEDIR(index->ce_mode))
2660+
return merged_sparse_dir(stages, 4, o);
2661+
else
2662+
return reject_merge(index, o);
2663+
}
26562664

26572665
if (head) {
26582666
/* #5ALT, #15 */
@@ -2714,11 +2722,21 @@ int threeway_merge(const struct cache_entry * const *stages,
27142722

27152723
}
27162724

2717-
/* Below are "no merge" cases, which require that the index be
2718-
* up-to-date to avoid the files getting overwritten with
2719-
* conflict resolution files.
2720-
*/
2725+
/* Handle "no merge" cases (see t/t1000-read-tree-m-3way.sh) */
27212726
if (index) {
2727+
/*
2728+
* If we've reached the "no merge" cases and we're merging
2729+
* a sparse directory, we may have an "edit/edit" conflict that
2730+
* can be resolved by individually merging directory contents.
2731+
*/
2732+
if (S_ISSPARSEDIR(index->ce_mode))
2733+
return merged_sparse_dir(stages, 4, o);
2734+
2735+
/*
2736+
* If we're not merging a sparse directory, ensure the index is
2737+
* up-to-date to avoid files getting overwritten with conflict
2738+
* resolution files
2739+
*/
27222740
if (verify_uptodate(index, o))
27232741
return -1;
27242742
}

0 commit comments

Comments
 (0)