merge-recursive: avoid losing output and leaking memory holding that output
[git] / merge-recursive.h
1 #ifndef MERGE_RECURSIVE_H
2 #define MERGE_RECURSIVE_H
3
4 #include "string-list.h"
5 #include "unpack-trees.h"
6
7 struct commit;
8
9 struct repository;
10
11 struct merge_options {
12         struct repository *repo;
13
14         /* ref names used in console messages and conflict markers */
15         const char *ancestor;
16         const char *branch1;
17         const char *branch2;
18
19         /* rename related options */
20         int detect_renames;
21         enum {
22                 MERGE_DIRECTORY_RENAMES_NONE = 0,
23                 MERGE_DIRECTORY_RENAMES_CONFLICT = 1,
24                 MERGE_DIRECTORY_RENAMES_TRUE = 2
25         } detect_directory_renames;
26         int rename_limit;
27         int rename_score;
28         int show_rename_progress;
29
30         /* xdiff-related options (patience, ignore whitespace, ours/theirs) */
31         long xdl_opts;
32         enum {
33                 MERGE_RECURSIVE_NORMAL = 0,
34                 MERGE_RECURSIVE_OURS,
35                 MERGE_RECURSIVE_THEIRS
36         } recursive_variant;
37
38         /* console output related options */
39         int verbosity;
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 */
43
44         /* miscellaneous control options */
45         const char *subtree_shift;
46         unsigned renormalize : 1;
47
48         /* internal fields used by the implementation (do NOT set these) */
49         int call_depth;
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;
55 };
56
57 void init_merge_options(struct merge_options *opt, struct repository *repo);
58
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);
61
62 /*
63  * RETURN VALUES: All the merge_* functions below return a value as follows:
64  *   > 0     Merge was clean
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.
68  */
69
70 /*
71  * rename-detecting three-way merge, no recursion.
72  *
73  * Outputs:
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
79  */
80 int merge_trees(struct merge_options *opt,
81                 struct tree *head,
82                 struct tree *merge,
83                 struct tree *merge_base);
84
85 /*
86  * merge_recursive is like merge_trees() but with recursive ancestor
87  * consolidation and, if the commit is clean, creation of a commit.
88  *
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.
94  *
95  * Outputs:
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
101  */
102 int merge_recursive(struct merge_options *opt,
103                     struct commit *h1,
104                     struct commit *h2,
105                     struct commit_list *merge_bases,
106                     struct commit **result);
107
108 /*
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.
112  *
113  * Outputs:
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
119  */
120 int merge_recursive_generic(struct merge_options *opt,
121                             const struct object_id *head,
122                             const struct object_id *merge,
123                             int num_merge_bases,
124                             const struct object_id **merge_bases,
125                             struct commit **result);
126
127 #endif