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; if buffer_output == 2, caller
42 * must handle and call strbuf_release */
44 /* miscellaneous control options */
45 const char *subtree_shift;
46 unsigned renormalize : 1;
48 /* internal fields used by the implementation (do NOT set these) */
50 int needed_rename_limit;
51 struct hashmap current_file_dir_set;
52 struct string_list df_conflict_file_set;
53 struct unpack_trees_options unpack_opts;
54 struct index_state orig_index;
57 void init_merge_options(struct merge_options *opt, struct repository *repo);
59 /* parse the option in s and update the relevant field of opt */
60 int parse_merge_opt(struct merge_options *opt, const char *s);
63 * RETURN VALUES: All the merge_* functions below return a value as follows:
65 * = 0 Merge had conflicts
66 * < 0 Merge hit an unexpected and unrecoverable problem (e.g. disk
67 * full) and aborted merge part-way through.
71 * rename-detecting three-way merge, no recursion.
74 * - See RETURN VALUES above
75 * - No commit is created
76 * - opt->repo->index has the new index
77 * - $GIT_INDEX_FILE is not updated
78 * - The working tree is updated with results of the merge
80 int merge_trees(struct merge_options *opt,
83 struct tree *merge_base);
86 * merge_recursive is like merge_trees() but with recursive ancestor
87 * consolidation and, if the commit is clean, creation of a commit.
89 * NOTE: empirically, about a decade ago it was determined that with more
90 * than two merge bases, optimal behavior was found when the
91 * merge_bases were passed in the order of oldest commit to newest
92 * commit. Also, merge_bases will be consumed (emptied) so make a
93 * copy if you need it.
96 * - See RETURN VALUES above
97 * - If merge is clean, a commit is created and its address written to *result
98 * - opt->repo->index has the new index
99 * - $GIT_INDEX_FILE is not updated
100 * - The working tree is updated with results of the merge
102 int merge_recursive(struct merge_options *opt,
105 struct commit_list *merge_bases,
106 struct commit **result);
109 * merge_recursive_generic can operate on trees instead of commits, by
110 * wrapping the trees into virtual commits, and calling merge_recursive().
111 * It also writes out the in-memory index to disk if the merge is successful.
114 * - See RETURN VALUES above
115 * - If merge is clean, a commit is created and its address written to *result
116 * - opt->repo->index has the new index
117 * - $GIT_INDEX_FILE is updated
118 * - The working tree is updated with results of the merge
120 int merge_recursive_generic(struct merge_options *opt,
121 const struct object_id *head,
122 const struct object_id *merge,
124 const struct object_id **merge_bases,
125 struct commit **result);