@matheusbsbs / matheus-bagliano / commits / e1b3a2cad7
Fork 0

Build-in merge-recursive

This makes write_tree_from_memory(), which writes the active cache as a tree and returns the struct tree for it, available to other code. It also makes available merge_trees(), which does the internal merge of two trees with a known base, and merge_recursive(), which does the recursive internal merge of two commits with a list of common ancestors. The first two of these will be used by checkout -m, and the third is presumably useful in general, although the implementation of checkout -m which entirely matches the behavior of the shell version does not use it (since it ignores the difference of ancestry between the old branch and the new branch). Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>

Daniel Barkalow committed Feb 7, 2008 at 11:40 UTC e1b3a2cad79a8138d18593c6eb3c46906ad2ee42
5 files changed +46 -22
Makefile
+1 -1
@@ -256,7 +256,6 @@ PROGRAMS = \
256 git-upload-pack$X \
257 git-pack-redundant$X git-var$X \
258 git-merge-tree$X git-imap-send$X \
259 - git-merge-recursive$X \
259 $(EXTRA_PROGRAMS)
260
261 # Empty...
@@ -360,6 +359,7 @@ BUILTIN_OBJS = \
359 builtin-merge-base.o \
360 builtin-merge-file.o \
361 builtin-merge-ours.o \
362 + builtin-merge-recursive.o \
363 builtin-mv.o \
364 builtin-name-rev.o \
365 builtin-pack-objects.o \
builtin-merge-recursive.c renamed
+23 -21
@@ -7,6 +7,7 @@
7 #include "cache-tree.h"
8 #include "commit.h"
9 #include "blob.h"
10 +#include "builtin.h"
11 #include "tree-walk.h"
12 #include "diff.h"
13 #include "diffcore.h"
@@ -17,6 +18,7 @@
18 #include "xdiff-interface.h"
19 #include "interpolate.h"
20 #include "attr.h"
21 +#include "merge-recursive.h"
22
23 static int subtree_merge;
24
@@ -232,7 +234,7 @@ static int unmerged_index(void)
234 return 0;
235 }
236
235 -static struct tree *git_write_tree(void)
237 +struct tree *write_tree_from_memory(void)
238 {
239 struct tree *result = NULL;
240
@@ -1495,12 +1497,12 @@ static int process_entry(const char *path, struct stage_data *entry,
1497 return clean_merge;
1498 }
1499
1498 -static int merge_trees(struct tree *head,
1499 - struct tree *merge,
1500 - struct tree *common,
1501 - const char *branch1,
1502 - const char *branch2,
1503 - struct tree **result)
1500 +int merge_trees(struct tree *head,
1501 + struct tree *merge,
1502 + struct tree *common,
1503 + const char *branch1,
1504 + const char *branch2,
1505 + struct tree **result)
1506 {
1507 int code, clean;
1508
@@ -1552,7 +1554,7 @@ static int merge_trees(struct tree *head,
1554 clean = 1;
1555
1556 if (index_only)
1555 - *result = git_write_tree();
1557 + *result = write_tree_from_memory();
1558
1559 return clean;
1560 }
@@ -1572,12 +1574,12 @@ static struct commit_list *reverse_commit_list(struct commit_list *list)
1574 * Merge the commits h1 and h2, return the resulting virtual
1575 * commit object and a flag indicating the cleanness of the merge.
1576 */
1575 -static int merge(struct commit *h1,
1576 - struct commit *h2,
1577 - const char *branch1,
1578 - const char *branch2,
1579 - struct commit_list *ca,
1580 - struct commit **result)
1577 +int merge_recursive(struct commit *h1,
1578 + struct commit *h2,
1579 + const char *branch1,
1580 + const char *branch2,
1581 + struct commit_list *ca,
1582 + struct commit **result)
1583 {
1584 struct commit_list *iter;
1585 struct commit *merged_common_ancestors;
@@ -1622,11 +1624,11 @@ static int merge(struct commit *h1,
1624 * "conflicts" were already resolved.
1625 */
1626 discard_cache();
1625 - merge(merged_common_ancestors, iter->item,
1626 - "Temporary merge branch 1",
1627 - "Temporary merge branch 2",
1628 - NULL,
1629 - &merged_common_ancestors);
1627 + merge_recursive(merged_common_ancestors, iter->item,
1628 + "Temporary merge branch 1",
1629 + "Temporary merge branch 2",
1630 + NULL,
1631 + &merged_common_ancestors);
1632 call_depth--;
1633
1634 if (!merged_common_ancestors)
@@ -1695,7 +1697,7 @@ static int merge_config(const char *var, const char *value)
1697 return git_default_config(var, value);
1698 }
1699
1698 -int main(int argc, char *argv[])
1700 +int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
1701 {
1702 static const char *bases[20];
1703 static unsigned bases_count = 0;
@@ -1749,7 +1751,7 @@ int main(int argc, char *argv[])
1751 struct commit *ancestor = get_ref(bases[i]);
1752 ca = commit_list_insert(ancestor, &ca);
1753 }
1752 - clean = merge(h1, h2, branch1, branch2, ca, &result);
1754 + clean = merge_recursive(h1, h2, branch1, branch2, ca, &result);
1755
1756 if (active_cache_changed &&
1757 (write_cache(index_fd, active_cache, active_nr) ||
builtin.h
+1
@@ -57,6 +57,7 @@ extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
57 extern int cmd_merge_base(int argc, const char **argv, const char *prefix);
58 extern int cmd_merge_ours(int argc, const char **argv, const char *prefix);
59 extern int cmd_merge_file(int argc, const char **argv, const char *prefix);
60 +extern int cmd_merge_recursive(int argc, const char **argv, const char *prefix);
61 extern int cmd_mv(int argc, const char **argv, const char *prefix);
62 extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
63 extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
git.c
+1
@@ -330,6 +330,7 @@ static void handle_internal_command(int argc, const char **argv)
330 { "merge-base", cmd_merge_base, RUN_SETUP },
331 { "merge-file", cmd_merge_file },
332 { "merge-ours", cmd_merge_ours, RUN_SETUP },
333 + { "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },
334 { "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE },
335 { "name-rev", cmd_name_rev, RUN_SETUP },
336 { "pack-objects", cmd_pack_objects, RUN_SETUP },
merge-recursive.h new
+20
@@ -0,0 +1,20 @@
1 +#ifndef MERGE_RECURSIVE_H
2 +#define MERGE_RECURSIVE_H
3 +
4 +int merge_recursive(struct commit *h1,
5 + struct commit *h2,
6 + const char *branch1,
7 + const char *branch2,
8 + struct commit_list *ancestors,
9 + struct commit **result);
10 +
11 +int merge_trees(struct tree *head,
12 + struct tree *merge,
13 + struct tree *common,
14 + const char *branch1,
15 + const char *branch2,
16 + struct tree **result);
17 +
18 +struct tree *write_tree_from_memory(void);
19 +
20 +#endif