blob: 9dc1bed768a473317dd77c4d1ed93f65b2c4d483 [file] [log] [blame]
Junio C Hamano2db3e752010-09-03 21:33:061merge API
2=========
3
4The merge API helps a program to reconcile two competing sets of
5improvements to some files (e.g., unregistered changes from the work
6tree versus changes involved in switching to a new branch), reporting
7conflicts if found. The library called through this API is
8responsible for a few things.
9
10 * determining which trees to merge (recursive ancestor consolidation);
11
12 * lining up corresponding files in the trees to be merged (rename
13 detection, subtree shifting), reporting edge cases like add/add
14 and rename/rename conflicts to the user;
15
16 * performing a three-way merge of corresponding files, taking
17 path-specific merge drivers (specified in `.gitattributes`)
18 into account.
19
Junio C Hamano39c7a692010-10-27 06:08:5420Data structures
21---------------
22
23* `mmbuffer_t`, `mmfile_t`
24
25These store data usable for use by the xdiff backend, for writing and
26for reading, respectively. See `xdiff/xdiff.h` for the definitions
27and `diff.c` for examples.
28
29* `struct ll_merge_options`
30
31This describes the set of options the calling program wants to affect
32the operation of a low-level (single file) merge. Some options:
33
34`virtual_ancestor`::
35Behave as though this were part of a merge between common
36ancestors in a recursive merge.
37If a helper program is specified by the
38`[merge "<driver>"] recursive` configuration, it will
Junio C Hamano719b8a32012-06-08 18:40:5339be used (see linkgit:gitattributes[5]).
Junio C Hamano39c7a692010-10-27 06:08:5440
41`variant`::
42Resolve local conflicts automatically in favor
43of one side or the other (as in 'git merge-file'
44`--ours`/`--theirs`/`--union`). Can be `0`,
45`XDL_MERGE_FAVOR_OURS`, `XDL_MERGE_FAVOR_THEIRS`, or
46`XDL_MERGE_FAVOR_UNION`.
47
48`renormalize`::
49Resmudge and clean the "base", "theirs" and "ours" files
50before merging. Use this when the merge is likely to have
51overlapped with a change in smudge/clean or end-of-line
52normalization rules.
53
Junio C Hamano2db3e752010-09-03 21:33:0654Low-level (single file) merge
55-----------------------------
56
57`ll_merge`::
58
59Perform a three-way single-file merge in core. This is
60a thin wrapper around `xdl_merge` that takes the path and
61any merge backend specified in `.gitattributes` or
62`.git/info/attributes` into account. Returns 0 for a
63clean merge.
64
Junio C Hamano39c7a692010-10-27 06:08:5465Calling sequence:
Junio C Hamano2db3e752010-09-03 21:33:0666
Junio C Hamano39c7a692010-10-27 06:08:5467* Prepare a `struct ll_merge_options` to record options.
68 If you have no special requests, skip this and pass `NULL`
69 as the `opts` parameter to use the default options.
70
71* Allocate an mmbuffer_t variable for the result.
72
73* Allocate and fill variables with the file's original content
74 and two modified versions (using `read_mmfile`, for example).
75
76* Call `ll_merge()`.
77
78* Read the merged content from `result_buf.ptr` and `result_buf.size`.
79
80* Release buffers when finished. A simple
81 `free(ancestor.ptr); free(ours.ptr); free(theirs.ptr);
82 free(result_buf.ptr);` will do.
Junio C Hamano2db3e752010-09-03 21:33:0683
84If the modifications do not merge cleanly, `ll_merge` will return a
85nonzero value and `result_buf` will generally include a description of
86the conflict bracketed by markers such as the traditional `<<<<<<<`
87and `>>>>>>>`.
88
89The `ancestor_label`, `our_label`, and `their_label` parameters are
90used to label the different sides of a conflict if the merge driver
91supports this.
92
Junio C Hamano2db3e752010-09-03 21:33:0693Everything else
94---------------
95
96Talk about <merge-recursive.h> and merge_file():
97
98 - merge_trees() to merge with rename detection
99 - merge_recursive() for ancestor consolidation
100 - try_merge_command() for other strategies
101 - conflict format
102 - merge options
103
104(Daniel, Miklos, Stephan, JC)