aboutsummaryrefslogtreecommitdiff
path: root/xdiff/xmerge.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-06-20 00:17:27 -0700
committerJunio C Hamano <gitster@pobox.com>2009-11-29 23:11:46 -0800
commit73eb40eeaaebc5ebae283c06286b96b4aea00143 (patch)
tree79b7e3d0bcc3c57e8dcec293fb95286cd4342189 /xdiff/xmerge.c
parent44148f2daf6e1ac3fe087dd07da2930411b3bcf2 (diff)
downloadgit-73eb40eeaaebc5ebae283c06286b96b4aea00143.tar.gz
git-73eb40eeaaebc5ebae283c06286b96b4aea00143.tar.xz
git-merge-file --ours, --theirs
Sometimes people want their conflicting merges autoresolved by favouring upstream changes. The standard answer they are given is to run "git diff --name-only | xargs git checkout MERGE_HEAD --" in such a case. This is to accept automerge results for the paths that are fully resolved automatically, while taking their version of the file in full for paths that have conflicts. This is problematic on two counts. One is that this is not exactly what these people want. It discards all changes they did on their branch for any paths that conflicted. They usually want to salvage as much automerge result as possible in a conflicted file, and want to take the upstream change only in the conflicted part. This patch teaches two new modes of operation to the lowest-lever merge machinery, xdl_merge(). Instead of leaving the conflicted lines from both sides enclosed in <<<, ===, and >>> markers, the conflicts are resolved favouring our side or their side of changes. A larger problem is that this tends to encourage a bad workflow by allowing people to record such a mixed up half-merged result as a full commit without auditing. This commit does not tackle this issue at all. In git, we usually give long enough rope to users with strange wishes as long as the risky features are not enabled by default, and this is such a risky feature. Signed-off-by: Avery Pennarun <apenwarr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'xdiff/xmerge.c')
-rw-r--r--xdiff/xmerge.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 1cb65a951..b2ddc7537 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -214,11 +214,15 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
xdfenv_t *xe2, const char *name2,
+ int favor,
xdmerge_t *m, char *dest, int style)
{
int size, i;
for (size = i = 0; m; m = m->next) {
+ if (favor && !m->mode)
+ m->mode = favor;
+
if (m->mode == 0)
size = fill_conflict_hunk(xe1, name1, xe2, name2,
size, i, style, m, dest);
@@ -391,6 +395,7 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
int i0, i1, i2, chg0, chg1, chg2;
int level = flags & XDL_MERGE_LEVEL_MASK;
int style = flags & XDL_MERGE_STYLE_MASK;
+ int favor = XDL_MERGE_FAVOR(flags);
if (style == XDL_MERGE_DIFF3) {
/*
@@ -523,14 +528,14 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
/* output */
if (result) {
int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2,
- changes, NULL, style);
+ favor, changes, NULL, style);
result->ptr = xdl_malloc(size);
if (!result->ptr) {
xdl_cleanup_merge(changes);
return -1;
}
result->size = size;
- xdl_fill_merge_buffer(xe1, name1, xe2, name2, changes,
+ xdl_fill_merge_buffer(xe1, name1, xe2, name2, favor, changes,
result->ptr, style);
}
return xdl_cleanup_merge(changes);