]> rtime.felk.cvut.cz Git - git.git/blobdiff - builtin-merge-recursive.c
Merge branch 'jc/cherry-pick' (early part)
[git.git] / builtin-merge-recursive.c
similarity index 97%
rename from merge-recursive.c
rename to builtin-merge-recursive.c
index d09f66e5f3ea769a414982dc1c1063e8aa737455..5a0a7b529765fa229318af86a68e58a92e287154 100644 (file)
@@ -7,6 +7,7 @@
 #include "cache-tree.h"
 #include "commit.h"
 #include "blob.h"
+#include "builtin.h"
 #include "tree-walk.h"
 #include "diff.h"
 #include "diffcore.h"
@@ -15,6 +16,9 @@
 #include "path-list.h"
 #include "xdiff-interface.h"
 #include "ll-merge.h"
+#include "interpolate.h"
+#include "attr.h"
+#include "merge-recursive.h"
 
 static int subtree_merge;
 
@@ -219,22 +223,11 @@ static int git_merge_trees(int index_only,
        return rc;
 }
 
-static int unmerged_index(void)
-{
-       int i;
-       for (i = 0; i < active_nr; i++) {
-               struct cache_entry *ce = active_cache[i];
-               if (ce_stage(ce))
-                       return 1;
-       }
-       return 0;
-}
-
-static struct tree *git_write_tree(void)
+struct tree *write_tree_from_memory(void)
 {
        struct tree *result = NULL;
 
-       if (unmerged_index()) {
+       if (unmerged_cache()) {
                int i;
                output(0, "There are unmerged index entries:");
                for (i = 0; i < active_nr; i++) {
@@ -1141,12 +1134,12 @@ static int process_entry(const char *path, struct stage_data *entry,
        return clean_merge;
 }
 
-static int merge_trees(struct tree *head,
-                      struct tree *merge,
-                      struct tree *common,
-                      const char *branch1,
-                      const char *branch2,
-                      struct tree **result)
+int merge_trees(struct tree *head,
+               struct tree *merge,
+               struct tree *common,
+               const char *branch1,
+               const char *branch2,
+               struct tree **result)
 {
        int code, clean;
 
@@ -1168,7 +1161,7 @@ static int merge_trees(struct tree *head,
                    sha1_to_hex(head->object.sha1),
                    sha1_to_hex(merge->object.sha1));
 
-       if (unmerged_index()) {
+       if (unmerged_cache()) {
                struct path_list *entries, *re_head, *re_merge;
                int i;
                path_list_clear(&current_file_set, 1);
@@ -1198,7 +1191,7 @@ static int merge_trees(struct tree *head,
                clean = 1;
 
        if (index_only)
-               *result = git_write_tree();
+               *result = write_tree_from_memory();
 
        return clean;
 }
@@ -1218,12 +1211,12 @@ static struct commit_list *reverse_commit_list(struct commit_list *list)
  * Merge the commits h1 and h2, return the resulting virtual
  * commit object and a flag indicating the cleanness of the merge.
  */
-static int merge(struct commit *h1,
-                struct commit *h2,
-                const char *branch1,
-                const char *branch2,
-                struct commit_list *ca,
-                struct commit **result)
+int merge_recursive(struct commit *h1,
+                   struct commit *h2,
+                   const char *branch1,
+                   const char *branch2,
+                   struct commit_list *ca,
+                   struct commit **result)
 {
        struct commit_list *iter;
        struct commit *merged_common_ancestors;
@@ -1268,11 +1261,11 @@ static int merge(struct commit *h1,
                 * "conflicts" were already resolved.
                 */
                discard_cache();
-               merge(merged_common_ancestors, iter->item,
-                     "Temporary merge branch 1",
-                     "Temporary merge branch 2",
-                     NULL,
-                     &merged_common_ancestors);
+               merge_recursive(merged_common_ancestors, iter->item,
+                               "Temporary merge branch 1",
+                               "Temporary merge branch 2",
+                               NULL,
+                               &merged_common_ancestors);
                call_depth--;
 
                if (!merged_common_ancestors)
@@ -1343,7 +1336,7 @@ static int merge_config(const char *var, const char *value)
        return git_default_config(var, value);
 }
 
-int main(int argc, char *argv[])
+int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
 {
        static const char *bases[20];
        static unsigned bases_count = 0;
@@ -1397,7 +1390,7 @@ int main(int argc, char *argv[])
                struct commit *ancestor = get_ref(bases[i]);
                ca = commit_list_insert(ancestor, &ca);
        }
-       clean = merge(h1, h2, branch1, branch2, ca, &result);
+       clean = merge_recursive(h1, h2, branch1, branch2, ca, &result);
 
        if (active_cache_changed &&
            (write_cache(index_fd, active_cache, active_nr) ||