Skip to content

Commit 58a1ece

Browse files
justinfrankelgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 712516b commit 58a1ece

File tree

6 files changed

+14
-0
lines changed

6 files changed

+14
-0
lines changed

Documentation/merge-strategies.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ the other tree did, declaring 'our' history contains all that happened in it.
4040
theirs;;
4141
This is opposite of 'ours'.
4242

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+
4350
renormalize;;
4451
This runs a virtual check-out and check-in of all three stages
4552
of a file when resolving a three-way merge. This option is

builtin/merge-recursive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "commit.h"
33
#include "tag.h"
44
#include "merge-recursive.h"
5+
#include "xdiff-interface.h"
56

67
static const char *better_branch_name(const char *branch)
78
{

ll-merge.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
8686
memset(&xmp, 0, sizeof(xmp));
8787
xmp.level = XDL_MERGE_ZEALOUS;
8888
xmp.favor = opts->variant;
89+
xmp.xpp.flags = opts->xdl_opts;
8990
if (git_xmerge_style >= 0)
9091
xmp.style = git_xmerge_style;
9192
if (marker_size > 0)

ll-merge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct ll_merge_options {
99
unsigned virtual_ancestor : 1;
1010
unsigned variant : 2; /* favor ours, favor theirs, or union merge */
1111
unsigned renormalize : 1;
12+
long xdl_opts;
1213
};
1314

1415
int ll_merge(mmbuffer_t *result_buf,

merge-recursive.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ static int merge_3way(struct merge_options *o,
613613
int merge_status;
614614

615615
ll_opts.renormalize = o->renormalize;
616+
ll_opts.xdl_opts = o->xdl_opts;
616617

617618
if (o->call_depth) {
618619
ll_opts.virtual_ancestor = 1;
@@ -1512,6 +1513,8 @@ int parse_merge_opt(struct merge_options *o, const char *s)
15121513
o->subtree_shift = "";
15131514
else if (!prefixcmp(s, "subtree="))
15141515
o->subtree_shift = s + strlen("subtree=");
1516+
else if (!strcmp(s, "patience"))
1517+
o->xdl_opts |= XDF_PATIENCE_DIFF;
15151518
else if (!strcmp(s, "renormalize"))
15161519
o->renormalize = 1;
15171520
else if (!strcmp(s, "no-renormalize"))

merge-recursive.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct merge_options {
1515
const char *subtree_shift;
1616
unsigned buffer_output : 1;
1717
unsigned renormalize : 1;
18+
long xdl_opts;
1819
int verbosity;
1920
int diff_rename_limit;
2021
int merge_rename_limit;

0 commit comments

Comments
 (0)