Skip to content

Commit 18b26b1

Browse files
committed
Merge branch 'jk/no-diff-emit-common'
"git merge-tree" used to mishandle "both sides added" conflict with its own "create a fake ancestor file that has the common parts of what both sides have added and do a 3-way merge" logic; this has been updated to use the usual "3-way merge with an empty blob as the fake common ancestor file" approach used in the rest of the system. * jk/no-diff-emit-common: xdiff: drop XDL_EMIT_COMMON merge-tree: drop generate_common strategy merge-one-file: use empty blob for add/add base
2 parents dede296 + 907681e commit 18b26b1

File tree

4 files changed

+3
-57
lines changed

4 files changed

+3
-57
lines changed

git-merge-one-file.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ case "${1:-.}${2:-.}${3:-.}" in
120120
case "$1" in
121121
'')
122122
echo "Added $4 in both, but differently."
123-
orig=$(git-unpack-file $2)
124-
create_virtual_base "$orig" "$src2"
123+
orig=$(git-unpack-file e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)
125124
;;
126125
*)
127126
echo "Auto-merging $4"

merge-blobs.c

+2-36
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,6 @@ static void *three_way_filemerge(const char *path, mmfile_t *base, mmfile_t *our
4848
return res.ptr;
4949
}
5050

51-
static int common_outf(void *priv_, mmbuffer_t *mb, int nbuf)
52-
{
53-
int i;
54-
mmfile_t *dst = priv_;
55-
56-
for (i = 0; i < nbuf; i++) {
57-
memcpy(dst->ptr + dst->size, mb[i].ptr, mb[i].size);
58-
dst->size += mb[i].size;
59-
}
60-
return 0;
61-
}
62-
63-
static int generate_common_file(mmfile_t *res, mmfile_t *f1, mmfile_t *f2)
64-
{
65-
unsigned long size = f1->size < f2->size ? f1->size : f2->size;
66-
void *ptr = xmalloc(size);
67-
xpparam_t xpp;
68-
xdemitconf_t xecfg;
69-
xdemitcb_t ecb;
70-
71-
memset(&xpp, 0, sizeof(xpp));
72-
xpp.flags = 0;
73-
memset(&xecfg, 0, sizeof(xecfg));
74-
xecfg.ctxlen = 3;
75-
xecfg.flags = XDL_EMIT_COMMON;
76-
ecb.outf = common_outf;
77-
78-
res->ptr = ptr;
79-
res->size = 0;
80-
81-
ecb.priv = res;
82-
return xdi_diff(f1, f2, &xpp, &xecfg, &ecb);
83-
}
84-
8551
void *merge_blobs(const char *path, struct blob *base, struct blob *our, struct blob *their, unsigned long *size)
8652
{
8753
void *res = NULL;
@@ -112,8 +78,8 @@ void *merge_blobs(const char *path, struct blob *base, struct blob *our, struct
11278
if (fill_mmfile_blob(&common, base) < 0)
11379
goto out_free_f2_f1;
11480
} else {
115-
if (generate_common_file(&common, &f1, &f2) < 0)
116-
goto out_free_f2_f1;
81+
common.ptr = xstrdup("");
82+
common.size = 0;
11783
}
11884
res = three_way_filemerge(path, &common, &f1, &f2, size);
11985
free_mmfile(&common);

xdiff/xdiff.h

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ extern "C" {
4242
#define XDF_IGNORE_BLANK_LINES (1 << 7)
4343

4444
#define XDL_EMIT_FUNCNAMES (1 << 0)
45-
#define XDL_EMIT_COMMON (1 << 1)
4645
#define XDL_EMIT_FUNCCONTEXT (1 << 2)
4746

4847
#define XDL_MMB_READONLY (1 << 0)

xdiff/xemit.c

-18
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,6 @@ static long def_ff(const char *rec, long len, char *buf, long sz, void *priv)
120120
return -1;
121121
}
122122

123-
static int xdl_emit_common(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
124-
xdemitconf_t const *xecfg) {
125-
xdfile_t *xdf = &xe->xdf2;
126-
const char *rchg = xdf->rchg;
127-
long ix;
128-
129-
for (ix = 0; ix < xdf->nrec; ix++) {
130-
if (rchg[ix])
131-
continue;
132-
if (xdl_emit_record(xdf, ix, "", ecb))
133-
return -1;
134-
}
135-
return 0;
136-
}
137-
138123
struct func_line {
139124
long len;
140125
char buf[80];
@@ -170,9 +155,6 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
170155
long funclineprev = -1;
171156
struct func_line func_line = { 0 };
172157

173-
if (xecfg->flags & XDL_EMIT_COMMON)
174-
return xdl_emit_common(xe, xscr, ecb, xecfg);
175-
176158
for (xch = xscr; xch; xch = xche->next) {
177159
xche = xdl_get_hunk(&xch, xecfg);
178160
if (!xch)

0 commit comments

Comments
 (0)