Skip to content

Commit 307ab20

Browse files
committed
xdiff: PATIENCE/HISTOGRAM are not independent option bits
Because the default Myers, patience and histogram algorithms cannot be in effect at the same time, XDL_PATIENCE_DIFF and XDL_HISTOGRAM_DIFF are not independent bits. Instead of wasting one bit per algorithm, define a few macros to access the few bits they occupy and update the code that access them. Signed-off-by: Junio C Hamano <[email protected]>
1 parent e5b0662 commit 307ab20

8 files changed

+24
-20
lines changed

diff.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3400,9 +3400,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
34003400
else if (!strcmp(arg, "--ignore-space-at-eol"))
34013401
DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
34023402
else if (!strcmp(arg, "--patience"))
3403-
DIFF_XDL_SET(options, PATIENCE_DIFF);
3403+
options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
34043404
else if (!strcmp(arg, "--histogram"))
3405-
DIFF_XDL_SET(options, HISTOGRAM_DIFF);
3405+
options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
34063406

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

diff.h

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
8888
#define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag)
8989
#define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag)
9090

91+
#define DIFF_WITH_ALG(opts, flag) (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag)
92+
9193
enum diff_words_type {
9294
DIFF_WORDS_NONE = 0,
9395
DIFF_WORDS_PORCELAIN,

merge-recursive.c

+2-2
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +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_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)
36+
3537
#define XDF_PATIENCE_DIFF (1 << 5)
3638
#define XDF_HISTOGRAM_DIFF (1 << 6)
37-
#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)
39+
#define XDF_DIFF_ALGORITHM_MASK (XDF_PATIENCE_DIFF | XDF_HISTOGRAM_DIFF)
40+
#define XDF_DIFF_ALG(x) ((x) & XDF_DIFF_ALGORITHM_MASK)
3841

3942
#define XDL_EMIT_FUNCNAMES (1 << 0)
4043
#define XDL_EMIT_COMMON (1 << 1)

xdiff/xdiffi.c

+2-2
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

+1-1
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

+1-1
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

+10-11
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)