{"thread":{"id":"11876","subject":"[PATCH 6/9] Build-in merge-recursive","startedAt":"2008-02-04T18:35:59Z","lastAt":"2008-02-04T18:35:59Z","messageCount":1,"participants":["Daniel Barkalow"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"67401","messageId":"alpine.LNX.1.00.0802041335220.13593@iabervon.org","threadId":"11876","inReplyTo":null,"subject":"[PATCH 6/9] Build-in merge-recursive","fromName":"Daniel Barkalow","fromEmail":"barkalow@iabervon.org","sentAt":"2008-02-04T18:35:59Z","receivedAt":"2008-02-04T18:35:59Z","isPatch":true,"sender":{"key":"barkalow@iabervon.org","avatar":"https://avatars.githubusercontent.com/u/55364219?v=4"},"body":"This makes write_tree_from_memory(), which writes the active cache as\na tree and returns the struct tree for it, available to other code. It\nalso makes available merge_trees(), which does the internal merge of\ntwo trees with a known base, and merge_recursive(), which does the\nrecursive internal merge of two commits with a list of common\nancestors.\n\nThe first two of these will be used by checkout -m, and the third is\npresumably useful in general, although the implementation of checkout\n-m which entirely matches the behavior of the shell version does not\nuse it (since it ignores the difference of ancestry between the old\nbranch and the new branch).\n\nSigned-off-by: Daniel Barkalow <barkalow@iabervon.org>\n---\n Makefile                                       |    2 +-\n merge-recursive.c => builtin-merge-recursive.c |   44 ++++++++++++-----------\n builtin.h                                      |    1 +\n git.c                                          |    1 +\n merge-recursive.h                              |   20 +++++++++++\n 5 files changed, 46 insertions(+), 22 deletions(-)\n rename merge-recursive.c => builtin-merge-recursive.c (98%)\n create mode 100644 merge-recursive.h\n\ndiff --git a/Makefile b/Makefile\nindex 91a460f..85ec1c6 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -258,7 +258,6 @@ PROGRAMS = \\\n \tgit-upload-pack$X \\\n \tgit-pack-redundant$X git-var$X \\\n \tgit-merge-tree$X git-imap-send$X \\\n-\tgit-merge-recursive$X \\\n \t$(EXTRA_PROGRAMS)\n \n # Empty...\n@@ -362,6 +361,7 @@ BUILTIN_OBJS = \\\n \tbuiltin-merge-base.o \\\n \tbuiltin-merge-file.o \\\n \tbuiltin-merge-ours.o \\\n+\tbuiltin-merge-recursive.o \\\n \tbuiltin-mv.o \\\n \tbuiltin-name-rev.o \\\n \tbuiltin-pack-objects.o \\\ndiff --git a/merge-recursive.c b/builtin-merge-recursive.c\nsimilarity index 98%\nrename from merge-recursive.c\nrename to builtin-merge-recursive.c\nindex bdf03b1..45d4601 100644\n--- a/merge-recursive.c\n+++ b/builtin-merge-recursive.c\n@@ -7,6 +7,7 @@\n #include \"cache-tree.h\"\n #include \"commit.h\"\n #include \"blob.h\"\n+#include \"builtin.h\"\n #include \"tree-walk.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n@@ -17,6 +18,7 @@\n #include \"xdiff-interface.h\"\n #include \"interpolate.h\"\n #include \"attr.h\"\n+#include \"merge-recursive.h\"\n \n static int subtree_merge;\n \n@@ -232,7 +234,7 @@ static int unmerged_index(void)\n \treturn 0;\n }\n \n-static struct tree *git_write_tree(void)\n+struct tree *write_tree_from_memory(void)\n {\n \tstruct tree *result = NULL;\n \n@@ -1495,12 +1497,12 @@ static int process_entry(const char *path, struct stage_data *entry,\n \treturn clean_merge;\n }\n \n-static int merge_trees(struct tree *head,\n-\t\t       struct tree *merge,\n-\t\t       struct tree *common,\n-\t\t       const char *branch1,\n-\t\t       const char *branch2,\n-\t\t       struct tree **result)\n+int merge_trees(struct tree *head,\n+\t\tstruct tree *merge,\n+\t\tstruct tree *common,\n+\t\tconst char *branch1,\n+\t\tconst char *branch2,\n+\t\tstruct tree **result)\n {\n \tint code, clean;\n \n@@ -1552,7 +1554,7 @@ static int merge_trees(struct tree *head,\n \t\tclean = 1;\n \n \tif (index_only)\n-\t\t*result = git_write_tree();\n+\t\t*result = write_tree_from_memory();\n \n \treturn clean;\n }\n@@ -1572,12 +1574,12 @@ static struct commit_list *reverse_commit_list(struct commit_list *list)\n  * Merge the commits h1 and h2, return the resulting virtual\n  * commit object and a flag indicating the cleanness of the merge.\n  */\n-static int merge(struct commit *h1,\n-\t\t struct commit *h2,\n-\t\t const char *branch1,\n-\t\t const char *branch2,\n-\t\t struct commit_list *ca,\n-\t\t struct commit **result)\n+int merge_recursive(struct commit *h1,\n+\t\t    struct commit *h2,\n+\t\t    const char *branch1,\n+\t\t    const char *branch2,\n+\t\t    struct commit_list *ca,\n+\t\t    struct commit **result)\n {\n \tstruct commit_list *iter;\n \tstruct commit *merged_common_ancestors;\n@@ -1622,11 +1624,11 @@ static int merge(struct commit *h1,\n \t\t * \"conflicts\" were already resolved.\n \t\t */\n \t\tdiscard_cache();\n-\t\tmerge(merged_common_ancestors, iter->item,\n-\t\t      \"Temporary merge branch 1\",\n-\t\t      \"Temporary merge branch 2\",\n-\t\t      NULL,\n-\t\t      &merged_common_ancestors);\n+\t\tmerge_recursive(merged_common_ancestors, iter->item,\n+\t\t\t\t\"Temporary merge branch 1\",\n+\t\t\t\t\"Temporary merge branch 2\",\n+\t\t\t\tNULL,\n+\t\t\t\t&merged_common_ancestors);\n \t\tcall_depth--;\n \n \t\tif (!merged_common_ancestors)\n@@ -1695,7 +1697,7 @@ static int merge_config(const char *var, const char *value)\n \treturn git_default_config(var, value);\n }\n \n-int main(int argc, char *argv[])\n+int cmd_merge_recursive(int argc, const char **argv, const char *prefix)\n {\n \tstatic const char *bases[20];\n \tstatic unsigned bases_count = 0;\n@@ -1749,7 +1751,7 @@ int main(int argc, char *argv[])\n \t\tstruct commit *ancestor = get_ref(bases[i]);\n \t\tca = commit_list_insert(ancestor, &ca);\n \t}\n-\tclean = merge(h1, h2, branch1, branch2, ca, &result);\n+\tclean = merge_recursive(h1, h2, branch1, branch2, ca, &result);\n \n \tif (active_cache_changed &&\n \t    (write_cache(index_fd, active_cache, active_nr) ||\ndiff --git a/builtin.h b/builtin.h\nindex cb675c4..428160d 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -57,6 +57,7 @@ extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);\n extern int cmd_merge_base(int argc, const char **argv, const char *prefix);\n extern int cmd_merge_ours(int argc, const char **argv, const char *prefix);\n extern int cmd_merge_file(int argc, const char **argv, const char *prefix);\n+extern int cmd_merge_recursive(int argc, const char **argv, const char *prefix);\n extern int cmd_mv(int argc, const char **argv, const char *prefix);\n extern int cmd_name_rev(int argc, const char **argv, const char *prefix);\n extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);\ndiff --git a/git.c b/git.c\nindex c8b7e74..57c9712 100644\n--- a/git.c\n+++ b/git.c\n@@ -339,6 +339,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"merge-base\", cmd_merge_base, RUN_SETUP },\n \t\t{ \"merge-file\", cmd_merge_file },\n \t\t{ \"merge-ours\", cmd_merge_ours, RUN_SETUP },\n+\t\t{ \"merge-recursive\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"mv\", cmd_mv, RUN_SETUP | NEED_WORK_TREE },\n \t\t{ \"name-rev\", cmd_name_rev, RUN_SETUP },\n \t\t{ \"pack-objects\", cmd_pack_objects, RUN_SETUP },\ndiff --git a/merge-recursive.h b/merge-recursive.h\nnew file mode 100644\nindex 0000000..f37630a\n--- /dev/null\n+++ b/merge-recursive.h\n@@ -0,0 +1,20 @@\n+#ifndef MERGE_RECURSIVE_H\n+#define MERGE_RECURSIVE_H\n+\n+int merge_recursive(struct commit *h1,\n+\t\t    struct commit *h2,\n+\t\t    const char *branch1,\n+\t\t    const char *branch2,\n+\t\t    struct commit_list *ancestors,\n+\t\t    struct commit **result);\n+\n+int merge_trees(struct tree *head,\n+\t\tstruct tree *merge,\n+\t\tstruct tree *common,\n+\t\tconst char *branch1,\n+\t\tconst char *branch2,\n+\t\tstruct tree **result);\n+\n+struct tree *write_tree_from_memory(void);\n+\n+#endif\n-- \n1.5.4\n"}]}