Elijah Newren | 17e5574 | 2020-10-27 02:08:07 +0000 | [diff] [blame] | 1 | #ifndef MERGE_ORT_H |
| 2 | #define MERGE_ORT_H |
| 3 | |
| 4 | #include "merge-recursive.h" |
Elijah Newren | fae26ce | 2022-06-18 00:20:50 +0000 | [diff] [blame] | 5 | #include "hash.h" |
Elijah Newren | 17e5574 | 2020-10-27 02:08:07 +0000 | [diff] [blame] | 6 | |
| 7 | struct commit; |
| 8 | struct tree; |
Elijah Newren | 20323d1 | 2022-02-02 02:37:35 +0000 | [diff] [blame] | 9 | struct strmap; |
Elijah Newren | 17e5574 | 2020-10-27 02:08:07 +0000 | [diff] [blame] | 10 | |
| 11 | struct merge_result { |
Elijah Newren | 0c0d705 | 2020-12-13 08:04:12 +0000 | [diff] [blame] | 12 | /* |
| 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 Newren | 17e5574 | 2020-10-27 02:08:07 +0000 | [diff] [blame] | 20 | 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 Newren | 20323d1 | 2022-02-02 02:37:35 +0000 | [diff] [blame] | 29 | * Special messages and conflict notices for various paths |
| 30 | * |
Johannes Schindelin | 2715e8a | 2022-06-18 00:20:55 +0000 | [diff] [blame] | 31 | * This is a map of pathnames to a string_list. It contains various |
Elijah Newren | 20323d1 | 2022-02-02 02:37:35 +0000 | [diff] [blame] | 32 | * warning/conflict/notice messages (possibly multiple per path) |
| 33 | * that callers may want to use. |
| 34 | */ |
| 35 | struct strmap *path_messages; |
| 36 | |
| 37 | /* |
Elijah Newren | 17e5574 | 2020-10-27 02:08:07 +0000 | [diff] [blame] | 38 | * 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 Newren | 19ceb48 | 2021-05-20 06:09:37 +0000 | [diff] [blame] | 43 | /* Also private */ |
| 44 | unsigned _properly_initialized; |
Elijah Newren | 17e5574 | 2020-10-27 02:08:07 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * rename-detecting three-way merge with recursive ancestor consolidation. |
| 49 | * working tree and index are untouched. |
Elijah Newren | 8119214 | 2020-12-16 22:28:02 +0000 | [diff] [blame] | 50 | * |
| 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 Newren | 17e5574 | 2020-10-27 02:08:07 +0000 | [diff] [blame] | 60 | */ |
| 61 | void 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 | */ |
| 71 | void 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 */ |
| 78 | void 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 Newren | a34edae | 2022-06-18 00:20:48 +0000 | [diff] [blame] | 84 | /* |
| 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 | */ |
| 89 | void merge_display_update_messages(struct merge_options *opt, |
Elijah Newren | de90581 | 2022-06-18 00:20:57 +0000 | [diff] [blame] | 90 | int detailed, |
Elijah Newren | a34edae | 2022-06-18 00:20:48 +0000 | [diff] [blame] | 91 | struct merge_result *result); |
| 92 | |
Elijah Newren | fae26ce | 2022-06-18 00:20:50 +0000 | [diff] [blame] | 93 | struct 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 | */ |
| 110 | void merge_get_conflicted_files(struct merge_result *result, |
| 111 | struct string_list *conflicted_files); |
| 112 | |
Elijah Newren | 17e5574 | 2020-10-27 02:08:07 +0000 | [diff] [blame] | 113 | /* Do needed cleanup when not calling merge_switch_to_result() */ |
| 114 | void merge_finalize(struct merge_options *opt, |
| 115 | struct merge_result *result); |
| 116 | |
| 117 | #endif |