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