@matheusbsbs / matheus-bagliano / commits / 1b1fdf8c2f
Fork 0

read-tree --aggressive

A new flag --aggressive resolves what we traditionally resolved with external git-merge-one-file inside index while read-tree 3-way merge works. git-merge-octopus and git-merge-resolve use this flag before running git-merge-index with git-merge-one-file. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 3, 2006 at 22:04 UTC 1b1fdf8c2f935e2195d3ca5c37e578bd9146a82f
3 files changed +34 -2
git-merge-octopus.sh
+1 -1
@@ -90,7 +90,7 @@ do
90 NON_FF_MERGE=1
91
92 echo "Trying simple merge with $SHA1"
93 - git-read-tree -u -m $common $MRT $SHA1 || exit 2
93 + git-read-tree -u -m --aggressive $common $MRT $SHA1 || exit 2
94 next=$(git-write-tree 2>/dev/null)
95 if test $? -ne 0
96 then
git-merge-resolve.sh
+1 -1
@@ -38,7 +38,7 @@ then
38 fi
39
40 git-update-index --refresh 2>/dev/null
41 -git-read-tree -u -m $bases $head $remotes || exit 2
41 +git-read-tree -u -m --aggressive $bases $head $remotes || exit 2
42 echo "Trying simple merge."
43 if result_tree=$(git-write-tree 2>/dev/null)
44 then
read-tree.c
+32
@@ -15,6 +15,7 @@ static int update = 0;
15 static int index_only = 0;
16 static int nontrivial_merge = 0;
17 static int trivial_merges_only = 0;
18 +static int aggressive = 0;
19
20 static int head_idx = -1;
21 static int merge_size = 0;
@@ -424,11 +425,14 @@ static int threeway_merge(struct cache_entry **stages)
425 int df_conflict_remote = 0;
426
427 int any_anc_missing = 0;
428 + int no_anc_exists = 1;
429 int i;
430
431 for (i = 1; i < head_idx; i++) {
432 if (!stages[i])
433 any_anc_missing = 1;
434 + else
435 + no_anc_exists = 0;
436 }
437
438 index = stages[0];
@@ -489,6 +493,29 @@ static int threeway_merge(struct cache_entry **stages)
493 if (!head && !remote && any_anc_missing)
494 return 0;
495
496 + /* Under the new "aggressive" rule, we resolve mostly trivial
497 + * cases that we historically had git-merge-one-file resolve.
498 + */
499 + if (aggressive) {
500 + int head_deleted = !head && !df_conflict_head;
501 + int remote_deleted = !remote && !df_conflict_remote;
502 + /*
503 + * Deleted in both.
504 + * Deleted in one and unchanged in the other.
505 + */
506 + if ((head_deleted && remote_deleted) ||
507 + (head_deleted && remote && remote_match) ||
508 + (remote_deleted && head && head_match))
509 + return 0;
510 +
511 + /*
512 + * Added in both, identically.
513 + */
514 + if (no_anc_exists && head && remote && same(head, remote))
515 + return merged_entry(head, index);
516 +
517 + }
518 +
519 /* Below are "no merge" cases, which require that the index be
520 * up-to-date to avoid the files getting overwritten with
521 * conflict resolution files.
@@ -677,6 +704,11 @@ int main(int argc, char **argv)
704 continue;
705 }
706
707 + if (!strcmp(arg, "--aggressive")) {
708 + aggressive = 1;
709 + continue;
710 + }
711 +
712 /* "-m" stands for "merge", meaning we start in stage 1 */
713 if (!strcmp(arg, "-m")) {
714 if (stage || merge)