2007-12-24 16:36:00 +08:00
|
|
|
|
/*
|
|
|
|
|
* Low level 3-way in-core file merge.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LL_MERGE_H
|
|
|
|
|
#define LL_MERGE_H
|
|
|
|
|
|
2018-08-16 01:54:05 +08:00
|
|
|
|
#include "xdiff/xdiff.h"
|
|
|
|
|
|
2019-11-18 05:04:43 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* Calling sequence:
|
|
|
|
|
* ----------------
|
|
|
|
|
*
|
|
|
|
|
* - Prepare a `struct ll_merge_options` to record options.
|
|
|
|
|
* If you have no special requests, skip this and pass `NULL`
|
|
|
|
|
* as the `opts` parameter to use the default options.
|
|
|
|
|
*
|
|
|
|
|
* - Allocate an mmbuffer_t variable for the result.
|
|
|
|
|
*
|
|
|
|
|
* - Allocate and fill variables with the file's original content
|
|
|
|
|
* and two modified versions (using `read_mmfile`, for example).
|
|
|
|
|
*
|
|
|
|
|
* - Call `ll_merge()`.
|
|
|
|
|
*
|
|
|
|
|
* - Read the merged content from `result_buf.ptr` and `result_buf.size`.
|
|
|
|
|
*
|
|
|
|
|
* - Release buffers when finished. A simple
|
|
|
|
|
* `free(ancestor.ptr); free(ours.ptr); free(theirs.ptr);
|
|
|
|
|
* free(result_buf.ptr);` will do.
|
|
|
|
|
*
|
|
|
|
|
* If the modifications do not merge cleanly, `ll_merge` will return a
|
|
|
|
|
* nonzero value and `result_buf` will generally include a description of
|
|
|
|
|
* the conflict bracketed by markers such as the traditional `<<<<<<<`
|
|
|
|
|
* and `>>>>>>>`.
|
|
|
|
|
*
|
|
|
|
|
* The `ancestor_label`, `our_label`, and `their_label` parameters are
|
|
|
|
|
* used to label the different sides of a conflict if the merge driver
|
|
|
|
|
* supports this.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2018-09-21 23:57:27 +08:00
|
|
|
|
struct index_state;
|
|
|
|
|
|
2019-11-18 05:04:43 +08:00
|
|
|
|
/**
|
|
|
|
|
* This describes the set of options the calling program wants to affect
|
|
|
|
|
* the operation of a low-level (single file) merge.
|
|
|
|
|
*/
|
2010-08-26 13:49:53 +08:00
|
|
|
|
struct ll_merge_options {
|
2019-11-18 05:04:43 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Behave as though this were part of a merge between common ancestors in
|
|
|
|
|
* a recursive merge (merges of binary files may need to be handled
|
|
|
|
|
* differently in such cases, for example). If a helper program is
|
|
|
|
|
* specified by the `[merge "<driver>"] recursive` configuration, it will
|
|
|
|
|
* be used.
|
|
|
|
|
*/
|
2010-08-26 13:49:53 +08:00
|
|
|
|
unsigned virtual_ancestor : 1;
|
2019-11-18 05:04:43 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolve local conflicts automatically in favor of one side or the other
|
|
|
|
|
* (as in 'git merge-file' `--ours`/`--theirs`/`--union`). Can be `0`,
|
|
|
|
|
* `XDL_MERGE_FAVOR_OURS`, `XDL_MERGE_FAVOR_THEIRS`,
|
|
|
|
|
* or `XDL_MERGE_FAVOR_UNION`.
|
|
|
|
|
*/
|
|
|
|
|
unsigned variant : 2;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resmudge and clean the "base", "theirs" and "ours" files before merging.
|
|
|
|
|
* Use this when the merge is likely to have overlapped with a change in
|
|
|
|
|
* smudge/clean or end-of-line normalization rules.
|
|
|
|
|
*/
|
2010-08-26 13:49:53 +08:00
|
|
|
|
unsigned renormalize : 1;
|
2019-11-18 05:04:43 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Increase the length of conflict markers so that nested conflicts
|
|
|
|
|
* can be differentiated.
|
|
|
|
|
*/
|
2018-11-08 12:40:24 +08:00
|
|
|
|
unsigned extra_marker_size;
|
2019-11-18 05:04:43 +08:00
|
|
|
|
|
2024-03-15 01:05:05 +08:00
|
|
|
|
/* Override the global conflict style. */
|
|
|
|
|
int conflict_style;
|
|
|
|
|
|
2019-11-18 05:04:43 +08:00
|
|
|
|
/* Extra xpparam_t flags as defined in xdiff/xdiff.h. */
|
2010-08-26 13:50:45 +08:00
|
|
|
|
long xdl_opts;
|
2010-08-26 13:49:53 +08:00
|
|
|
|
};
|
2010-08-05 19:17:38 +08:00
|
|
|
|
|
2024-03-15 01:05:05 +08:00
|
|
|
|
#define LL_MERGE_OPTIONS_INIT { .conflict_style = -1 }
|
2024-03-15 01:05:04 +08:00
|
|
|
|
|
2022-02-02 10:37:30 +08:00
|
|
|
|
enum ll_merge_result {
|
|
|
|
|
LL_MERGE_ERROR = -1,
|
|
|
|
|
LL_MERGE_OK = 0,
|
|
|
|
|
LL_MERGE_CONFLICT,
|
|
|
|
|
LL_MERGE_BINARY_CONFLICT,
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-18 05:04:43 +08:00
|
|
|
|
/**
|
|
|
|
|
* Perform a three-way single-file merge in core. This is a thin wrapper
|
|
|
|
|
* around `xdl_merge` that takes the path and any merge backend specified in
|
|
|
|
|
* `.gitattributes` or `.git/info/attributes` into account.
|
|
|
|
|
* Returns 0 for a clean merge.
|
|
|
|
|
*/
|
2022-02-02 10:37:30 +08:00
|
|
|
|
enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
|
2007-12-24 16:36:00 +08:00
|
|
|
|
const char *path,
|
2010-03-21 08:38:58 +08:00
|
|
|
|
mmfile_t *ancestor, const char *ancestor_label,
|
2007-12-24 16:36:00 +08:00
|
|
|
|
mmfile_t *ours, const char *our_label,
|
|
|
|
|
mmfile_t *theirs, const char *their_label,
|
2018-09-21 23:57:27 +08:00
|
|
|
|
struct index_state *istate,
|
2010-08-26 13:49:53 +08:00
|
|
|
|
const struct ll_merge_options *opts);
|
2007-12-24 16:36:00 +08:00
|
|
|
|
|
2018-09-21 23:57:27 +08:00
|
|
|
|
int ll_merge_marker_size(struct index_state *istate, const char *path);
|
2019-09-03 06:39:44 +08:00
|
|
|
|
void reset_merge_attributes(void);
|
2010-01-17 15:28:46 +08:00
|
|
|
|
|
2007-12-24 16:36:00 +08:00
|
|
|
|
#endif
|