X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=read-tree.c;h=5580f15ba2c89f9fd1ed35de0b0183487d024bf8;hb=8e1618f9612a78ea09b2a926797c781fe06027c9;hp=e3b9c0d9fa1cb5a03d1a3a08f992074293285904;hpb=9cac9d368934f68e75810df95211a6522d4d139e;p=git.git diff --git a/read-tree.c b/read-tree.c index e3b9c0d9..5580f15b 100644 --- a/read-tree.c +++ b/read-tree.c @@ -15,6 +15,7 @@ static int update = 0; static int index_only = 0; static int nontrivial_merge = 0; static int trivial_merges_only = 0; +static int aggressive = 0; static int head_idx = -1; static int merge_size = 0; @@ -294,17 +295,20 @@ static int unpack_trees(merge_fn_t fn) { int indpos = 0; unsigned len = object_list_length(trees); - struct tree_entry_list **posns = - xmalloc(len * sizeof(struct tree_entry_list *)); + struct tree_entry_list **posns; int i; struct object_list *posn = trees; merge_size = len; - for (i = 0; i < len; i++) { - posns[i] = ((struct tree *) posn->item)->entries; - posn = posn->next; + + if (len) { + posns = xmalloc(len * sizeof(struct tree_entry_list *)); + for (i = 0; i < len; i++) { + posns[i] = ((struct tree *) posn->item)->entries; + posn = posn->next; + } + if (unpack_trees_rec(posns, len, "", fn, &indpos)) + return -1; } - if (unpack_trees_rec(posns, len, "", fn, &indpos)) - return -1; if (trivial_merges_only && nontrivial_merge) die("Merge requires file-level merging"); @@ -421,11 +425,14 @@ static int threeway_merge(struct cache_entry **stages) int df_conflict_remote = 0; int any_anc_missing = 0; + int no_anc_exists = 1; int i; for (i = 1; i < head_idx; i++) { if (!stages[i]) any_anc_missing = 1; + else + no_anc_exists = 0; } index = stages[0]; @@ -486,6 +493,29 @@ static int threeway_merge(struct cache_entry **stages) if (!head && !remote && any_anc_missing) return 0; + /* Under the new "aggressive" rule, we resolve mostly trivial + * cases that we historically had git-merge-one-file resolve. + */ + if (aggressive) { + int head_deleted = !head && !df_conflict_head; + int remote_deleted = !remote && !df_conflict_remote; + /* + * Deleted in both. + * Deleted in one and unchanged in the other. + */ + if ((head_deleted && remote_deleted) || + (head_deleted && remote && remote_match) || + (remote_deleted && head && head_match)) + return 0; + + /* + * Added in both, identically. + */ + if (no_anc_exists && head && remote && same(head, remote)) + return merged_entry(head, index); + + } + /* Below are "no merge" cases, which require that the index be * up-to-date to avoid the files getting overwritten with * conflict resolution files. @@ -674,6 +704,11 @@ int main(int argc, char **argv) continue; } + if (!strcmp(arg, "--aggressive")) { + aggressive = 1; + continue; + } + /* "-m" stands for "merge", meaning we start in stage 1 */ if (!strcmp(arg, "-m")) { if (stage || merge)