2007-12-24 11:36:00 +03:00
|
|
|
|
/*
|
|
|
|
|
* Low level 3-way in-core file merge.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef LL_MERGE_H
|
|
|
|
|
#define LL_MERGE_H
|
|
|
|
|
|
2018-08-15 20:54:05 +03:00
|
|
|
|
#include "xdiff/xdiff.h"
|
|
|
|
|
|
2019-11-18 00:04:43 +03: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 18:57:27 +03:00
|
|
|
|
struct index_state;
|
|
|
|
|
|
2019-11-18 00:04:43 +03: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 09:49:53 +04:00
|
|
|
|
struct ll_merge_options {
|
2019-11-18 00:04:43 +03: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 09:49:53 +04:00
|
|
|
|
unsigned virtual_ancestor : 1;
|
2019-11-18 00:04:43 +03: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 09:49:53 +04:00
|
|
|
|
unsigned renormalize : 1;
|
2019-11-18 00:04:43 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Increase the length of conflict markers so that nested conflicts
|
|
|
|
|
* can be differentiated.
|
|
|
|
|
*/
|
2018-11-08 07:40:24 +03:00
|
|
|
|
unsigned extra_marker_size;
|
2019-11-18 00:04:43 +03:00
|
|
|
|
|
|
|
|
|
/* Extra xpparam_t flags as defined in xdiff/xdiff.h. */
|
2010-08-26 09:50:45 +04:00
|
|
|
|
long xdl_opts;
|
2010-08-26 09:49:53 +04:00
|
|
|
|
};
|
2010-08-05 15:17:38 +04:00
|
|
|
|
|
2022-02-02 05:37:30 +03:00
|
|
|
|
enum ll_merge_result {
|
|
|
|
|
LL_MERGE_ERROR = -1,
|
|
|
|
|
LL_MERGE_OK = 0,
|
|
|
|
|
LL_MERGE_CONFLICT,
|
|
|
|
|
LL_MERGE_BINARY_CONFLICT,
|
|
|
|
|
};
|
|
|
|
|
|
2019-11-18 00:04:43 +03: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 05:37:30 +03:00
|
|
|
|
enum ll_merge_result ll_merge(mmbuffer_t *result_buf,
|
2007-12-24 11:36:00 +03:00
|
|
|
|
const char *path,
|
2010-03-21 03:38:58 +03:00
|
|
|
|
mmfile_t *ancestor, const char *ancestor_label,
|
2007-12-24 11:36:00 +03:00
|
|
|
|
mmfile_t *ours, const char *our_label,
|
|
|
|
|
mmfile_t *theirs, const char *their_label,
|
2018-09-21 18:57:27 +03:00
|
|
|
|
struct index_state *istate,
|
2010-08-26 09:49:53 +04:00
|
|
|
|
const struct ll_merge_options *opts);
|
2007-12-24 11:36:00 +03:00
|
|
|
|
|
2018-09-21 18:57:27 +03:00
|
|
|
|
int ll_merge_marker_size(struct index_state *istate, const char *path);
|
2019-09-03 01:39:44 +03:00
|
|
|
|
void reset_merge_attributes(void);
|
2010-01-17 10:28:46 +03:00
|
|
|
|
|
2007-12-24 11:36:00 +03:00
|
|
|
|
#endif
|