Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/merge-ll.h # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / merge-ll.h` 116 lines · 3500 bytes Raw Blame History 1 /* 2 * Low level 3-way in-core file merge. 3 */ 4 5 #ifndef LL_MERGE_H 6 #define LL_MERGE_H 7 8 #include "xdiff/xdiff.h" 9 10 /** 11 * 12 * Calling sequence: 13 * ---------------- 14 * 15 * - Prepare a `struct ll_merge_options` to record options. 16 * If you have no special requests, skip this and pass `NULL` 17 * as the `opts` parameter to use the default options. 18 * 19 * - Allocate an mmfile_t variable for the result. 20 * 21 * - Allocate and fill variables with the file's original content 22 * and two modified versions (using `read_mmfile`, for example). 23 * 24 * - Call `ll_merge()`. 25 * 26 * - Read the merged content from `result_buf.ptr` and `result_buf.size`. 27 * 28 * - Release buffers when finished. A simple 29 * `free(ancestor.ptr); free(ours.ptr); free(theirs.ptr); 30 * free(result_buf.ptr);` will do. 31 * 32 * If the modifications do not merge cleanly, `ll_merge` will return a 33 * nonzero value and `result_buf` will generally include a description of 34 * the conflict bracketed by markers such as the traditional `<<<<<<<` 35 * and `>>>>>>>`. 36 * 37 * The `ancestor_label`, `our_label`, and `their_label` parameters are 38 * used to label the different sides of a conflict if the merge driver 39 * supports this. 40 */ 41 42 43 struct index_state; 44 45 /** 46 * This describes the set of options the calling program wants to affect 47 * the operation of a low-level (single file) merge. 48 */ 49 struct ll_merge_options { 50 51 /** 52 * Behave as though this were part of a merge between common ancestors in 53 * a recursive merge (merges of binary files may need to be handled 54 * differently in such cases, for example). If a helper program is 55 * specified by the `[merge ""] recursive` configuration, it will 56 * be used. 57 */ 58 unsigned virtual_ancestor : 1; 59 60 /** 61 * Resolve local conflicts automatically in favor of one side or the other 62 * (as in 'git merge-file' `--ours`/`--theirs`/`--union`). Can be `0`, 63 * `XDL_MERGE_FAVOR_OURS`, `XDL_MERGE_FAVOR_THEIRS`, 64 * or `XDL_MERGE_FAVOR_UNION`. 65 */ 66 unsigned variant : 2; 67 68 /** 69 * Resmudge and clean the "base", "theirs" and "ours" files before merging. 70 * Use this when the merge is likely to have overlapped with a change in 71 * smudge/clean or end-of-line normalization rules. 72 */ 73 unsigned renormalize : 1; 74 75 /** 76 * Increase the length of conflict markers so that nested conflicts 77  * can be differentiated. 78 */ 79 unsigned extra_marker_size; 80 81 /* Override the global conflict style. */ 82 int conflict_style; 83 84 /* Extra xpparam_t flags as defined in xdiff/xdiff.h. */ 85 long xdl_opts; 86 }; 87 88 #define LL_MERGE_OPTIONS_INIT { .conflict_style = -1 } 89 90 enum ll_merge_result { 91 LL_MERGE_ERROR = -1, 92 LL_MERGE_OK = 0, 93 LL_MERGE_CONFLICT, 94 LL_MERGE_BINARY_CONFLICT, 95 }; 96 97 /** 98 * Perform a three-way single-file merge in core. This is a thin wrapper 99 * around `xdl_merge` that takes the path and any merge backend specified in 100 * `.gitattributes` or `.git/info/attributes` into account. 101 * Returns 0 for a clean merge. 102 */ 103 enum ll_merge_result ll_merge(mmfile_t *result_buf, 104 const char *path, 105 mmfile_t *ancestor, const char *ancestor_label, 106 mmfile_t *ours, const char *our_label, 107 mmfile_t *theirs, const char *their_label, 108 struct index_state *istate, 109 const struct ll_merge_options *opts); 110 111 int ll_merge_marker_size(struct index_state *istate, const char *path); 112 int is_conflict_marker_line(const char *line, unsigned long len, int marker_size); 113 int has_conflict_markers(struct index_state *istate, const char *path); 114 void reset_merge_attributes(void); 115 116 #endif