2020-10-27 02:08:07 +00:00
|
|
|
#ifndef MERGE_ORT_H
|
|
|
|
#define MERGE_ORT_H
|
|
|
|
|
|
|
|
#include "merge-recursive.h"
|
2023-04-22 20:17:20 +00:00
|
|
|
#include "hash-ll.h"
|
2020-10-27 02:08:07 +00:00
|
|
|
|
|
|
|
struct commit;
|
|
|
|
struct tree;
|
2022-02-02 02:37:35 +00:00
|
|
|
struct strmap;
|
2020-10-27 02:08:07 +00:00
|
|
|
|
|
|
|
struct merge_result {
|
2020-12-13 08:04:12 +00:00
|
|
|
/*
|
|
|
|
* Whether the merge is clean; possible values:
|
|
|
|
* 1: clean
|
|
|
|
* 0: not clean (merge conflicts)
|
|
|
|
* <0: operation aborted prematurely. (object database
|
|
|
|
* unreadable, disk full, etc.) Worktree may be left in an
|
|
|
|
* inconsistent state if operation failed near the end.
|
|
|
|
*/
|
2020-10-27 02:08:07 +00:00
|
|
|
int clean;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Result of merge. If !clean, represents what would go in worktree
|
|
|
|
* (thus possibly including files containing conflict markers).
|
|
|
|
*/
|
|
|
|
struct tree *tree;
|
|
|
|
|
2022-02-02 02:37:35 +00:00
|
|
|
/*
|
|
|
|
* Special messages and conflict notices for various paths
|
|
|
|
*
|
2022-06-18 00:20:55 +00:00
|
|
|
* This is a map of pathnames to a string_list. It contains various
|
2022-02-02 02:37:35 +00:00
|
|
|
* warning/conflict/notice messages (possibly multiple per path)
|
|
|
|
* that callers may want to use.
|
|
|
|
*/
|
|
|
|
struct strmap *path_messages;
|
|
|
|
|
2020-10-27 02:08:07 +00:00
|
|
|
/*
|
|
|
|
* Additional metadata used by merge_switch_to_result() or future calls
|
|
|
|
* to merge_incore_*(). Includes data needed to update the index (if
|
|
|
|
* !clean) and to print "CONFLICT" messages. Not for external use.
|
|
|
|
*/
|
|
|
|
void *priv;
|
merge-ort: avoid accidental API mis-use
Previously, callers of the merge-ort API could have passed an
uninitialized value for struct merge_result *result. However, we want
to check result to see if it has cached renames from a previous merge
that we can reuse; such values would be found behind result->priv.
However, if result->priv is uninitialized, attempting to access behind
it will give a segfault. So, we need result->priv to be NULL (which
will be the case if the caller does a memset(&result, 0)), or be written
by a previous call to the merge-ort machinery. Documenting this
requirement may help, but despite being the person who introduced this
requirement, I still missed it once and it did not fail in a very clear
way and led to a long debugging session.
Add a _properly_initialized field to merge_result; that value will be
0 if the caller zero'ed the merge_result, it will be set to a very
specific value by a previous run by the merge-ort machinery, and if it's
uninitialized it will most likely either be 0 or some value that does
not match the specific one we'd expect allowing us to throw a much more
meaningful error.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-05-20 06:09:37 +00:00
|
|
|
/* Also private */
|
|
|
|
unsigned _properly_initialized;
|
2020-10-27 02:08:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rename-detecting three-way merge with recursive ancestor consolidation.
|
|
|
|
* working tree and index are untouched.
|
2020-12-16 22:28:02 +00:00
|
|
|
*
|
|
|
|
* merge_bases will be consumed (emptied) so make a copy if you need it.
|
|
|
|
*
|
|
|
|
* NOTE: empirically, the recursive algorithm will perform better if you
|
|
|
|
* pass the merge_bases in the order of oldest commit to the
|
|
|
|
* newest[1][2].
|
|
|
|
*
|
|
|
|
* [1] https://lore.kernel.org/git/nycvar.QRO.7.76.6.1907252055500.21907@tvgsbejvaqbjf.bet/
|
|
|
|
* [2] commit 8918b0c9c2 ("merge-recur: try to merge older merge bases
|
|
|
|
* first", 2006-08-09)
|
2020-10-27 02:08:07 +00:00
|
|
|
*/
|
|
|
|
void merge_incore_recursive(struct merge_options *opt,
|
|
|
|
struct commit_list *merge_bases,
|
|
|
|
struct commit *side1,
|
|
|
|
struct commit *side2,
|
|
|
|
struct merge_result *result);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rename-detecting three-way merge, no recursion.
|
|
|
|
* working tree and index are untouched.
|
|
|
|
*/
|
|
|
|
void merge_incore_nonrecursive(struct merge_options *opt,
|
|
|
|
struct tree *merge_base,
|
|
|
|
struct tree *side1,
|
|
|
|
struct tree *side2,
|
|
|
|
struct merge_result *result);
|
|
|
|
|
|
|
|
/* Update the working tree and index from head to result after incore merge */
|
|
|
|
void merge_switch_to_result(struct merge_options *opt,
|
|
|
|
struct tree *head,
|
|
|
|
struct merge_result *result,
|
|
|
|
int update_worktree_and_index,
|
|
|
|
int display_update_msgs);
|
|
|
|
|
2022-06-18 00:20:48 +00:00
|
|
|
/*
|
|
|
|
* Display messages about conflicts and which files were 3-way merged.
|
|
|
|
* Automatically called by merge_switch_to_result() with stream == stdout,
|
|
|
|
* so only call this when bypassing merge_switch_to_result().
|
|
|
|
*/
|
|
|
|
void merge_display_update_messages(struct merge_options *opt,
|
2022-06-18 00:20:57 +00:00
|
|
|
int detailed,
|
2022-06-18 00:20:48 +00:00
|
|
|
struct merge_result *result);
|
|
|
|
|
2022-06-18 00:20:50 +00:00
|
|
|
struct stage_info {
|
|
|
|
struct object_id oid;
|
|
|
|
int mode;
|
|
|
|
int stage;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Provide a list of path -> {struct stage_info*} mappings for
|
|
|
|
* all conflicted files. Note that each path could appear up to three
|
|
|
|
* times in the list, corresponding to 3 different stage entries. In short,
|
|
|
|
* this basically provides the info that would be printed by `ls-files -u`.
|
|
|
|
*
|
|
|
|
* result should have been populated by a call to
|
|
|
|
* one of the merge_incore_[non]recursive() functions.
|
|
|
|
*
|
|
|
|
* conflicted_files should be empty before calling this function.
|
|
|
|
*/
|
|
|
|
void merge_get_conflicted_files(struct merge_result *result,
|
|
|
|
struct string_list *conflicted_files);
|
|
|
|
|
2020-10-27 02:08:07 +00:00
|
|
|
/* Do needed cleanup when not calling merge_switch_to_result() */
|
|
|
|
void merge_finalize(struct merge_options *opt,
|
|
|
|
struct merge_result *result);
|
|
|
|
|
|
|
|
#endif
|