]> git.ipfire.org Git - thirdparty/git.git/blame - merge-recursive.h
merge-recursive: avoid losing output and leaking memory holding that output
[thirdparty/git.git] / merge-recursive.h
CommitLineData
e1b3a2ca
DB
1#ifndef MERGE_RECURSIVE_H
2#define MERGE_RECURSIVE_H
3
696ee23c 4#include "string-list.h"
ef3ca954
EN
5#include "unpack-trees.h"
6
7struct commit;
696ee23c 8
0d6caa2d
NTND
9struct repository;
10
8a2fce18 11struct merge_options {
a779fb82
EN
12 struct repository *repo;
13
14 /* ref names used in console messages and conflict markers */
4c5868f4 15 const char *ancestor;
8a2fce18
MV
16 const char *branch1;
17 const char *branch2;
a779fb82
EN
18
19 /* rename related options */
20 int detect_renames;
8e012516
DS
21 enum {
22 MERGE_DIRECTORY_RENAMES_NONE = 0,
23 MERGE_DIRECTORY_RENAMES_CONFLICT = 1,
24 MERGE_DIRECTORY_RENAMES_TRUE = 2
25 } detect_directory_renames;
8599ab45 26 int rename_limit;
10ae7526 27 int rename_score;
99bfc669 28 int show_rename_progress;
a779fb82
EN
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 */
e95e481f
EN
41 struct strbuf obuf; /* output buffer; if buffer_output == 2, caller
42 * must handle and call strbuf_release */
a779fb82
EN
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) */
5033639c 49 int call_depth;
a779fb82 50 int needed_rename_limit;
fc65b00d 51 struct hashmap current_file_dir_set;
70cc3d36 52 struct string_list df_conflict_file_set;
64b1abe9 53 struct unpack_trees_options unpack_opts;
a35edc84 54 struct index_state orig_index;
ea625cb0
EN
55};
56
7c0a6c8e
EN
57void init_merge_options(struct merge_options *opt, struct repository *repo);
58
59/* parse the option in s and update the relevant field of opt */
60int parse_merge_opt(struct merge_options *opt, const char *s);
61
7fe40b88 62/*
7c0a6c8e
EN
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.
7fe40b88 68 */
e95ab70a 69
7c0a6c8e
EN
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 */
80int merge_trees(struct merge_options *opt,
81 struct tree *head,
82 struct tree *merge,
83 struct tree *merge_base);
85b46030 84
b4db8a2b
EN
85/*
86 * merge_recursive is like merge_trees() but with recursive ancestor
7c0a6c8e 87 * consolidation and, if the commit is clean, creation of a commit.
b4db8a2b
EN
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
ff1bfa2c
EN
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.
7c0a6c8e
EN
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
b4db8a2b 101 */
c749ab1d 102int merge_recursive(struct merge_options *opt,
8a2fce18 103 struct commit *h1,
e1b3a2ca 104 struct commit *h2,
ff1bfa2c 105 struct commit_list *merge_bases,
e1b3a2ca
DB
106 struct commit **result);
107
b4db8a2b 108/*
7c0a6c8e
EN
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
8a2fce18 119 */
c749ab1d 120int merge_recursive_generic(struct merge_options *opt,
4e8161a8 121 const struct object_id *head,
122 const struct object_id *merge,
ff1bfa2c
EN
123 int num_merge_bases,
124 const struct object_id **merge_bases,
8a2fce18
MV
125 struct commit **result);
126
e1b3a2ca 127#endif