]> git.scripts.mit.edu Git - git.git/blob - merge-recursive.h
The sixteenth batch
[git.git] / merge-recursive.h
1 #ifndef MERGE_RECURSIVE_H
2 #define MERGE_RECURSIVE_H
3
4 #include "strbuf.h"
5
6 struct commit;
7 struct commit_list;
8 struct object_id;
9 struct repository;
10 struct tree;
11
12 struct merge_options_internal;
13 struct merge_options {
14         struct repository *repo;
15
16         /* ref names used in console messages and conflict markers */
17         const char *ancestor;
18         const char *branch1;
19         const char *branch2;
20
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;
31
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;
40
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 */
46
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;
52
53         /* internal fields used by the implementation */
54         struct merge_options_internal *priv;
55 };
56
57 void init_merge_options(struct merge_options *opt, struct repository *repo);
58
59 void copy_merge_options(struct merge_options *dst, struct merge_options *src);
60 void clear_merge_options(struct merge_options *opt);
61
62 /* parse the option in s and update the relevant field of opt */
63 int parse_merge_opt(struct merge_options *opt, const char *s);
64
65 /*
66  * RETURN VALUES: All the merge_* functions below return a value as follows:
67  *   > 0     Merge was clean
68  *   = 0     Merge had conflicts
69  *   < 0     Merge hit an unexpected and unrecoverable problem (e.g. disk
70  *             full) and aborted merge part-way through.
71  */
72
73 /*
74  * rename-detecting three-way merge, no recursion.
75  *
76  * Outputs:
77  *   - See RETURN VALUES above
78  *   - opt->repo->index has the new index
79  *   - new index NOT written to disk
80  *   - The working tree is updated with results of the merge
81  */
82 int merge_trees(struct merge_options *opt,
83                 struct tree *head,
84                 struct tree *merge,
85                 struct tree *merge_base);
86
87 /*
88  * merge_recursive is like merge_trees() but with recursive ancestor
89  * consolidation.
90  *
91  * NOTE: empirically, about a decade ago it was determined that with more
92  *       than two merge bases, optimal behavior was found when the
93  *       merge_bases were passed in the order of oldest commit to newest
94  *       commit.  Also, merge_bases will be consumed (emptied) so make a
95  *       copy if you need it.
96  *
97  * Outputs:
98  *   - See RETURN VALUES above
99  *   - *result is treated as scratch space for temporary recursive merges
100  *   - opt->repo->index has the new index
101  *   - new index NOT written to disk
102  *   - The working tree is updated with results of the merge
103  */
104 int merge_recursive(struct merge_options *opt,
105                     struct commit *h1,
106                     struct commit *h2,
107                     struct commit_list *merge_bases,
108                     struct commit **result);
109
110 /*
111  * merge_recursive_generic can operate on trees instead of commits, by
112  * wrapping the trees into virtual commits, and calling merge_recursive().
113  * It also writes out the in-memory index to disk if the merge is successful.
114  *
115  * Outputs:
116  *   - See RETURN VALUES above
117  *   - *result is treated as scratch space for temporary recursive merges
118  *   - opt->repo->index has the new index
119  *   - new index also written to $GIT_INDEX_FILE on disk
120  *   - The working tree is updated with results of the merge
121  */
122 int merge_recursive_generic(struct merge_options *opt,
123                             const struct object_id *head,
124                             const struct object_id *merge,
125                             int num_merge_bases,
126                             const struct object_id **merge_bases,
127                             struct commit **result);
128
129 #endif