Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 8daff71

Browse files
committed
Merge branch 'jc/diff-algo-cleanup' into maint
* jc/diff-algo-cleanup: xdiff: PATIENCE/HISTOGRAM are not independent option bits xdiff: remove XDL_PATCH_* macros
2 parents 07e74b0 + 307ab20 commit 8daff71

File tree

8 files changed

+24
-25
lines changed

8 files changed

+24
-25
lines changed

diff.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3544,9 +3544,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
35443544
else if (!strcmp(arg, "--ignore-space-at-eol"))
35453545
DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
35463546
else if (!strcmp(arg, "--patience"))
3547-
DIFF_XDL_SET(options, PATIENCE_DIFF);
3547+
options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
35483548
else if (!strcmp(arg, "--histogram"))
3549-
DIFF_XDL_SET(options, HISTOGRAM_DIFF);
3549+
options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
35503550

35513551
/* flags options */
35523552
else if (!strcmp(arg, "--binary")) {

diff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
9191
#define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag)
9292
#define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag)
9393

94+
#define DIFF_WITH_ALG(opts, flag) (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag)
95+
9496
enum diff_words_type {
9597
DIFF_WORDS_NONE = 0,
9698
DIFF_WORDS_PORCELAIN,

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,9 +2069,9 @@ int parse_merge_opt(struct merge_options *o, const char *s)
20692069
else if (!prefixcmp(s, "subtree="))
20702070
o->subtree_shift = s + strlen("subtree=");
20712071
else if (!strcmp(s, "patience"))
2072-
o->xdl_opts |= XDF_PATIENCE_DIFF;
2072+
o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
20732073
else if (!strcmp(s, "histogram"))
2074-
o->xdl_opts |= XDF_HISTOGRAM_DIFF;
2074+
o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
20752075
else if (!strcmp(s, "ignore-space-change"))
20762076
o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
20772077
else if (!strcmp(s, "ignore-all-space"))

xdiff/xdiff.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ extern "C" {
3232
#define XDF_IGNORE_WHITESPACE (1 << 2)
3333
#define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)
3434
#define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4)
35-
#define XDF_PATIENCE_DIFF (1 << 5)
36-
#define XDF_HISTOGRAM_DIFF (1 << 6)
3735
#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)
3836

39-
#define XDL_PATCH_NORMAL '-'
40-
#define XDL_PATCH_REVERSE '+'
41-
#define XDL_PATCH_MODEMASK ((1 << 8) - 1)
42-
#define XDL_PATCH_IGNOREBSPACE (1 << 8)
37+
#define XDF_PATIENCE_DIFF (1 << 5)
38+
#define XDF_HISTOGRAM_DIFF (1 << 6)
39+
#define XDF_DIFF_ALGORITHM_MASK (XDF_PATIENCE_DIFF | XDF_HISTOGRAM_DIFF)
40+
#define XDF_DIFF_ALG(x) ((x) & XDF_DIFF_ALGORITHM_MASK)
4341

4442
#define XDL_EMIT_FUNCNAMES (1 << 0)
4543
#define XDL_EMIT_COMMON (1 << 1)

xdiff/xdiffi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
328328
xdalgoenv_t xenv;
329329
diffdata_t dd1, dd2;
330330

331-
if (xpp->flags & XDF_PATIENCE_DIFF)
331+
if (XDF_DIFF_ALG(xpp->flags) == XDF_PATIENCE_DIFF)
332332
return xdl_do_patience_diff(mf1, mf2, xpp, xe);
333333

334-
if (xpp->flags & XDF_HISTOGRAM_DIFF)
334+
if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF)
335335
return xdl_do_histogram_diff(mf1, mf2, xpp, xe);
336336

337337
if (xdl_prepare_env(mf1, mf2, xpp, xe) < 0) {

xdiff/xhistogram.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static int fall_back_to_classic_diff(struct histindex *index,
252252
int line1, int count1, int line2, int count2)
253253
{
254254
xpparam_t xpp;
255-
xpp.flags = index->xpp->flags & ~XDF_HISTOGRAM_DIFF;
255+
xpp.flags = index->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK;
256256

257257
return xdl_fall_back_diff(index->env, &xpp,
258258
line1, count1, line2, count2);

xdiff/xpatience.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static int fall_back_to_classic_diff(struct hashmap *map,
288288
int line1, int count1, int line2, int count2)
289289
{
290290
xpparam_t xpp;
291-
xpp.flags = map->xpp->flags & ~XDF_PATIENCE_DIFF;
291+
xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK;
292292

293293
return xdl_fall_back_diff(map->env, &xpp,
294294
line1, count1, line2, count2);

xdiff/xprepare.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
181181
if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *))))
182182
goto abort;
183183

184-
if (xpp->flags & XDF_HISTOGRAM_DIFF)
184+
if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF)
185185
hbits = hsize = 0;
186186
else {
187187
hbits = xdl_hashbits((unsigned int) narec);
@@ -209,8 +209,8 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
209209
crec->ha = hav;
210210
recs[nrec++] = crec;
211211

212-
if (!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
213-
xdl_classify_record(pass, cf, rhash, hbits, crec) < 0)
212+
if ((XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) &&
213+
xdl_classify_record(pass, cf, rhash, hbits, crec) < 0)
214214
goto abort;
215215
}
216216
}
@@ -273,16 +273,15 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
273273
* (nrecs) will be updated correctly anyway by
274274
* xdl_prepare_ctx().
275275
*/
276-
sample = xpp->flags & XDF_HISTOGRAM_DIFF ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1;
276+
sample = (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF
277+
? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1);
277278

278279
enl1 = xdl_guess_lines(mf1, sample) + 1;
279280
enl2 = xdl_guess_lines(mf2, sample) + 1;
280281

281-
if (!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
282-
xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) {
283-
282+
if (XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF &&
283+
xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0)
284284
return -1;
285-
}
286285

287286
if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {
288287

@@ -296,9 +295,9 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
296295
return -1;
297296
}
298297

299-
if (!(xpp->flags & XDF_PATIENCE_DIFF) &&
300-
!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
301-
xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) {
298+
if ((XDF_DIFF_ALG(xpp->flags) != XDF_PATIENCE_DIFF) &&
299+
(XDF_DIFF_ALG(xpp->flags) != XDF_HISTOGRAM_DIFF) &&
300+
xdl_optimize_ctxs(&cf, &xe->xdf1, &xe->xdf2) < 0) {
302301

303302
xdl_free_ctx(&xe->xdf2);
304303
xdl_free_ctx(&xe->xdf1);

0 commit comments

Comments
 (0)