merge-recursive --patience
Teach the merge-recursive strategy a --patience option to use the "patience diff" algorithm, which tends to improve results when cherry-picking a patch that reorders functions at the same time as refactoring them. To support this, struct merge_options and ll_merge_options gain an xdl_opts member, so programs can use arbitrary xdiff flags (think "XDF_IGNORE_WHITESPACE") in a git-aware merge. git merge and git rebase can be passed the -Xpatience option to use this. [jn: split from --ignore-space patch; with documentation] Signed-off-by: Justin Frankel <justin@cockos.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Justin Frankel committed
Aug 26, 2010 at 00:50 UTC
58a1ece478c6038a7eb0b6e494d563bd5e6d5978
6 files changed
+14
Documentation/merge-strategies.txt
+7
@@ -40,6 +40,13 @@ the other tree did, declaring 'our' history contains all that happened in it.
40
theirs;;
41
This is opposite of 'ours'.
42
43
+patience;;
44
+ With this option, 'merge-recursive' spends a little extra time
45
+ to avoid mismerges that sometimes occur due to unimportant
46
+ matching lines (e.g., braces from distinct functions). Use
47
+ this when the branches to be merged have diverged wildly.
48
+ See also linkgit:git-diff[1] `--patience`.
49
+
50
renormalize;;
51
This runs a virtual check-out and check-in of all three stages
52
of a file when resolving a three-way merge. This option is
builtin/merge-recursive.c
+1
@@ -2,6 +2,7 @@
2
#include "commit.h"
3
#include "tag.h"
4
#include "merge-recursive.h"
5
+#include "xdiff-interface.h"
6
7
static const char *better_branch_name(const char *branch)
8
{
ll-merge.c
+1
@@ -86,6 +86,7 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
86
memset(&xmp, 0, sizeof(xmp));
87
xmp.level = XDL_MERGE_ZEALOUS;
88
xmp.favor = opts->variant;
89
+ xmp.xpp.flags = opts->xdl_opts;
90
if (git_xmerge_style >= 0)
91
xmp.style = git_xmerge_style;
92
if (marker_size > 0)
ll-merge.h
+1
@@ -9,6 +9,7 @@ struct ll_merge_options {
9
unsigned virtual_ancestor : 1;
10
unsigned variant : 2; /* favor ours, favor theirs, or union merge */
11
unsigned renormalize : 1;
12
+ long xdl_opts;
13
};
14
15
int ll_merge(mmbuffer_t *result_buf,
merge-recursive.c
+3
@@ -613,6 +613,7 @@ static int merge_3way(struct merge_options *o,
613
int merge_status;
614
615
ll_opts.renormalize = o->renormalize;
616
+ ll_opts.xdl_opts = o->xdl_opts;
617
618
if (o->call_depth) {
619
ll_opts.virtual_ancestor = 1;
@@ -1512,6 +1513,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
1513
o->subtree_shift = "";
1514
else if (!prefixcmp(s, "subtree="))
1515
o->subtree_shift = s + strlen("subtree=");
1516
+ else if (!strcmp(s, "patience"))
1517
+ o->xdl_opts |= XDF_PATIENCE_DIFF;
1518
else if (!strcmp(s, "renormalize"))
1519
o->renormalize = 1;
1520
else if (!strcmp(s, "no-renormalize"))
merge-recursive.h
+1
@@ -15,6 +15,7 @@ struct merge_options {
15
const char *subtree_shift;
16
unsigned buffer_output : 1;
17
unsigned renormalize : 1;
18
+ long xdl_opts;
19
int verbosity;
20
int diff_rename_limit;
21
int merge_rename_limit;