1 #ifndef MERGE_RECURSIVE_H
2 #define MERGE_RECURSIVE_H
4 #include "string-list.h"
5 #include "unpack-trees.h"
11 struct merge_options {
12 struct repository *repo;
14 /* ref names used in console messages and conflict markers */
19 /* rename related options */
22 MERGE_DIRECTORY_RENAMES_NONE = 0,
23 MERGE_DIRECTORY_RENAMES_CONFLICT = 1,
24 MERGE_DIRECTORY_RENAMES_TRUE = 2
25 } detect_directory_renames;
28 int show_rename_progress;
30 /* xdiff-related options (patience, ignore whitespace, ours/theirs) */
33 MERGE_RECURSIVE_NORMAL = 0,
35 MERGE_RECURSIVE_THEIRS
38 /* console output related options */
40 unsigned buffer_output; /* 1: output at end, 2: keep buffered */
41 struct strbuf obuf; /* output buffer */
43 /* miscellaneous control options */
44 const char *subtree_shift;
45 unsigned renormalize : 1;
47 /* internal fields used by the implementation (do NOT set these) */
49 int needed_rename_limit;
50 struct hashmap current_file_dir_set;
51 struct string_list df_conflict_file_set;
52 struct unpack_trees_options unpack_opts;
53 struct index_state orig_index;
56 void init_merge_options(struct merge_options *opt, struct repository *repo);
58 /* parse the option in s and update the relevant field of opt */
59 int parse_merge_opt(struct merge_options *opt, const char *s);
62 * RETURN VALUES: All the merge_* functions below return a value as follows:
64 * = 0 Merge had conflicts
65 * < 0 Merge hit an unexpected and unrecoverable problem (e.g. disk
66 * full) and aborted merge part-way through.
70 * rename-detecting three-way merge, no recursion.
73 * - See RETURN VALUES above
74 * - No commit is created
75 * - opt->repo->index has the new index
76 * - $GIT_INDEX_FILE is not updated
77 * - The working tree is updated with results of the merge
79 int merge_trees(struct merge_options *opt,
82 struct tree *merge_base);
85 * merge_recursive is like merge_trees() but with recursive ancestor
86 * consolidation and, if the commit is clean, creation of a commit.
88 * NOTE: empirically, about a decade ago it was determined that with more
89 * than two merge bases, optimal behavior was found when the
90 * merge_bases were passed in the order of oldest commit to newest
91 * commit. Also, merge_bases will be consumed (emptied) so make a
92 * copy if you need it.
95 * - See RETURN VALUES above
96 * - If merge is clean, a commit is created and its address written to *result
97 * - opt->repo->index has the new index
98 * - $GIT_INDEX_FILE is not updated
99 * - The working tree is updated with results of the merge
101 int merge_recursive(struct merge_options *opt,
104 struct commit_list *merge_bases,
105 struct commit **result);
108 * merge_recursive_generic can operate on trees instead of commits, by
109 * wrapping the trees into virtual commits, and calling merge_recursive().
110 * It also writes out the in-memory index to disk if the merge is successful.
113 * - See RETURN VALUES above
114 * - If merge is clean, a commit is created and its address written to *result
115 * - opt->repo->index has the new index
116 * - $GIT_INDEX_FILE is updated
117 * - The working tree is updated with results of the merge
119 int merge_recursive_generic(struct merge_options *opt,
120 const struct object_id *head,
121 const struct object_id *merge,
123 const struct object_id **merge_bases,
124 struct commit **result);