blob: a994c9a5fcdb040b3ecb80db0489a50c1394ac75 [file] [log] [blame]
Elijah Newren17e55742020-10-27 02:08:07 +00001#ifndef MERGE_ORT_H
2#define MERGE_ORT_H
3
4#include "merge-recursive.h"
Elijah Newrenfae26ce2022-06-18 00:20:50 +00005#include "hash.h"
Elijah Newren17e55742020-10-27 02:08:07 +00006
7struct commit;
8struct tree;
Elijah Newren20323d12022-02-02 02:37:35 +00009struct strmap;
Elijah Newren17e55742020-10-27 02:08:07 +000010
11struct merge_result {
Elijah Newren0c0d7052020-12-13 08:04:12 +000012 /*
13 * Whether the merge is clean; possible values:
14 * 1: clean
15 * 0: not clean (merge conflicts)
16 * <0: operation aborted prematurely. (object database
17 * unreadable, disk full, etc.) Worktree may be left in an
18 * inconsistent state if operation failed near the end.
19 */
Elijah Newren17e55742020-10-27 02:08:07 +000020 int clean;
21
22 /*
23 * Result of merge. If !clean, represents what would go in worktree
24 * (thus possibly including files containing conflict markers).
25 */
26 struct tree *tree;
27
28 /*
Elijah Newren20323d12022-02-02 02:37:35 +000029 * Special messages and conflict notices for various paths
30 *
Johannes Schindelin2715e8a2022-06-18 00:20:55 +000031 * This is a map of pathnames to a string_list. It contains various
Elijah Newren20323d12022-02-02 02:37:35 +000032 * warning/conflict/notice messages (possibly multiple per path)
33 * that callers may want to use.
34 */
35 struct strmap *path_messages;
36
37 /*
Elijah Newren17e55742020-10-27 02:08:07 +000038 * Additional metadata used by merge_switch_to_result() or future calls
39 * to merge_incore_*(). Includes data needed to update the index (if
40 * !clean) and to print "CONFLICT" messages. Not for external use.
41 */
42 void *priv;
Elijah Newren19ceb482021-05-20 06:09:37 +000043 /* Also private */
44 unsigned _properly_initialized;
Elijah Newren17e55742020-10-27 02:08:07 +000045};
46
47/*
48 * rename-detecting three-way merge with recursive ancestor consolidation.
49 * working tree and index are untouched.
Elijah Newren81192142020-12-16 22:28:02 +000050 *
51 * merge_bases will be consumed (emptied) so make a copy if you need it.
52 *
53 * NOTE: empirically, the recursive algorithm will perform better if you
54 * pass the merge_bases in the order of oldest commit to the
55 * newest[1][2].
56 *
57 * [1] https://lore.kernel.org/git/nycvar.QRO.7.76.6.1907252055500.21907@tvgsbejvaqbjf.bet/
58 * [2] commit 8918b0c9c2 ("merge-recur: try to merge older merge bases
59 * first", 2006-08-09)
Elijah Newren17e55742020-10-27 02:08:07 +000060 */
61void merge_incore_recursive(struct merge_options *opt,
62 struct commit_list *merge_bases,
63 struct commit *side1,
64 struct commit *side2,
65 struct merge_result *result);
66
67/*
68 * rename-detecting three-way merge, no recursion.
69 * working tree and index are untouched.
70 */
71void merge_incore_nonrecursive(struct merge_options *opt,
72 struct tree *merge_base,
73 struct tree *side1,
74 struct tree *side2,
75 struct merge_result *result);
76
77/* Update the working tree and index from head to result after incore merge */
78void merge_switch_to_result(struct merge_options *opt,
79 struct tree *head,
80 struct merge_result *result,
81 int update_worktree_and_index,
82 int display_update_msgs);
83
Elijah Newrena34edae2022-06-18 00:20:48 +000084/*
85 * Display messages about conflicts and which files were 3-way merged.
86 * Automatically called by merge_switch_to_result() with stream == stdout,
87 * so only call this when bypassing merge_switch_to_result().
88 */
89void merge_display_update_messages(struct merge_options *opt,
Elijah Newrende905812022-06-18 00:20:57 +000090 int detailed,
Elijah Newrena34edae2022-06-18 00:20:48 +000091 struct merge_result *result);
92
Elijah Newrenfae26ce2022-06-18 00:20:50 +000093struct stage_info {
94 struct object_id oid;
95 int mode;
96 int stage;
97};
98
99/*
100 * Provide a list of path -> {struct stage_info*} mappings for
101 * all conflicted files. Note that each path could appear up to three
102 * times in the list, corresponding to 3 different stage entries. In short,
103 * this basically provides the info that would be printed by `ls-files -u`.
104 *
105 * result should have been populated by a call to
106 * one of the merge_incore_[non]recursive() functions.
107 *
108 * conflicted_files should be empty before calling this function.
109 */
110void merge_get_conflicted_files(struct merge_result *result,
111 struct string_list *conflicted_files);
112
Elijah Newren17e55742020-10-27 02:08:07 +0000113/* Do needed cleanup when not calling merge_switch_to_result() */
114void merge_finalize(struct merge_options *opt,
115 struct merge_result *result);
116
117#endif