Merge https://github.com/j6t/git-gui
[alt-git.git] / merge-recursive.h
blob0b91f28f9022793920c01edd5bb2520fbdad7984
1 #ifndef MERGE_RECURSIVE_H
2 #define MERGE_RECURSIVE_H
4 #include "strbuf.h"
6 struct commit;
7 struct commit_list;
8 struct object_id;
9 struct repository;
10 struct tree;
12 struct merge_options_internal;
13 struct merge_options {
14 struct repository *repo;
16 /* ref names used in console messages and conflict markers */
17 const char *ancestor;
18 const char *branch1;
19 const char *branch2;
21 /* rename related options */
22 int detect_renames;
23 enum {
24 MERGE_DIRECTORY_RENAMES_NONE = 0,
25 MERGE_DIRECTORY_RENAMES_CONFLICT = 1,
26 MERGE_DIRECTORY_RENAMES_TRUE = 2
27 } detect_directory_renames;
28 int rename_limit;
29 int rename_score;
30 int show_rename_progress;
32 /* xdiff-related options (patience, ignore whitespace, ours/theirs) */
33 long xdl_opts;
34 int conflict_style;
35 enum {
36 MERGE_VARIANT_NORMAL = 0,
37 MERGE_VARIANT_OURS,
38 MERGE_VARIANT_THEIRS
39 } recursive_variant;
41 /* console output related options */
42 int verbosity;
43 unsigned buffer_output; /* 1: output at end, 2: keep buffered */
44 struct strbuf obuf; /* output buffer; if buffer_output == 2, caller
45 * must handle and call strbuf_release */
47 /* miscellaneous control options */
48 const char *subtree_shift;
49 unsigned renormalize : 1;
50 unsigned record_conflict_msgs_as_headers : 1;
51 const char *msg_header_prefix;
53 /* internal fields used by the implementation */
54 struct merge_options_internal *priv;
57 /* for use by porcelain commands */
58 void init_ui_merge_options(struct merge_options *opt, struct repository *repo);
59 /* for use by plumbing commands */
60 void init_basic_merge_options(struct merge_options *opt, struct repository *repo);
62 void copy_merge_options(struct merge_options *dst, struct merge_options *src);
63 void clear_merge_options(struct merge_options *opt);
65 /* parse the option in s and update the relevant field of opt */
66 int parse_merge_opt(struct merge_options *opt, const char *s);
69 * RETURN VALUES: All the merge_* functions below return a value as follows:
70 * > 0 Merge was clean
71 * = 0 Merge had conflicts
72 * < 0 Merge hit an unexpected and unrecoverable problem (e.g. disk
73 * full) and aborted merge part-way through.
77 * rename-detecting three-way merge, no recursion.
79 * Outputs:
80 * - See RETURN VALUES above
81 * - opt->repo->index has the new index
82 * - new index NOT written to disk
83 * - The working tree is updated with results of the merge
85 int merge_trees(struct merge_options *opt,
86 struct tree *head,
87 struct tree *merge,
88 struct tree *merge_base);
91 * merge_recursive is like merge_trees() but with recursive ancestor
92 * consolidation.
94 * NOTE: empirically, about a decade ago it was determined that with more
95 * than two merge bases, optimal behavior was found when the
96 * merge_bases were passed in the order of oldest commit to newest
97 * commit. Also, merge_bases will be consumed (emptied) so make a
98 * copy if you need it.
100 * Outputs:
101 * - See RETURN VALUES above
102 * - *result is treated as scratch space for temporary recursive merges
103 * - opt->repo->index has the new index
104 * - new index NOT written to disk
105 * - The working tree is updated with results of the merge
107 int merge_recursive(struct merge_options *opt,
108 struct commit *h1,
109 struct commit *h2,
110 const struct commit_list *merge_bases,
111 struct commit **result);
114 * merge_recursive_generic can operate on trees instead of commits, by
115 * wrapping the trees into virtual commits, and calling merge_recursive().
116 * It also writes out the in-memory index to disk if the merge is successful.
118 * Outputs:
119 * - See RETURN VALUES above
120 * - *result is treated as scratch space for temporary recursive merges
121 * - opt->repo->index has the new index
122 * - new index also written to $GIT_INDEX_FILE on disk
123 * - The working tree is updated with results of the merge
125 int merge_recursive_generic(struct merge_options *opt,
126 const struct object_id *head,
127 const struct object_id *merge,
128 int num_merge_bases,
129 const struct object_id *merge_bases,
130 struct commit **result);
132 #endif