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 <gitster@pobox.com>

Junio C Hamano committed Feb 19, 2012 at 15:36 UTC 307ab20b333d9b4c818b1ff912e86944d1a3fdc1
8 files changed +24 -20
diff.c
+2 -2
@@ -3400,9 +3400,9 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
3400 else if (!strcmp(arg, "--ignore-space-at-eol"))
3401 DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
3402 else if (!strcmp(arg, "--patience"))
3403 - DIFF_XDL_SET(options, PATIENCE_DIFF);
3403 + options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
3404 else if (!strcmp(arg, "--histogram"))
3405 - DIFF_XDL_SET(options, HISTOGRAM_DIFF);
3405 + options->xdl_opts = DIFF_WITH_ALG(options, HISTOGRAM_DIFF);
3406
3407 /* flags options */
3408 else if (!strcmp(arg, "--binary")) {
diff.h
+2
@@ -88,6 +88,8 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
88 #define DIFF_XDL_SET(opts, flag) ((opts)->xdl_opts |= XDF_##flag)
89 #define DIFF_XDL_CLR(opts, flag) ((opts)->xdl_opts &= ~XDF_##flag)
90
91 +#define DIFF_WITH_ALG(opts, flag) (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag)
92 +
93 enum diff_words_type {
94 DIFF_WORDS_NONE = 0,
95 DIFF_WORDS_PORCELAIN,
merge-recursive.c
+2 -2
@@ -2069,9 +2069,9 @@ int parse_merge_opt(struct merge_options *o, const char *s)
2069 else if (!prefixcmp(s, "subtree="))
2070 o->subtree_shift = s + strlen("subtree=");
2071 else if (!strcmp(s, "patience"))
2072 - o->xdl_opts |= XDF_PATIENCE_DIFF;
2072 + o->xdl_opts = DIFF_WITH_ALG(o, PATIENCE_DIFF);
2073 else if (!strcmp(s, "histogram"))
2074 - o->xdl_opts |= XDF_HISTOGRAM_DIFF;
2074 + o->xdl_opts = DIFF_WITH_ALG(o, HISTOGRAM_DIFF);
2075 else if (!strcmp(s, "ignore-space-change"))
2076 o->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
2077 else if (!strcmp(s, "ignore-all-space"))
xdiff/xdiff.h
+4 -1
@@ -32,9 +32,12 @@ extern "C" {
32 #define XDF_IGNORE_WHITESPACE (1 << 2)
33 #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)
34 #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 +
37 #define XDF_PATIENCE_DIFF (1 << 5)
38 #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)
41
42 #define XDL_EMIT_FUNCNAMES (1 << 0)
43 #define XDL_EMIT_COMMON (1 << 1)
xdiff/xdiffi.c
+2 -2
@@ -328,10 +328,10 @@ int xdl_do_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
328 xdalgoenv_t xenv;
329 diffdata_t dd1, dd2;
330
331 - if (xpp->flags & XDF_PATIENCE_DIFF)
331 + if (XDF_DIFF_ALG(xpp->flags) == XDF_PATIENCE_DIFF)
332 return xdl_do_patience_diff(mf1, mf2, xpp, xe);
333
334 - if (xpp->flags & XDF_HISTOGRAM_DIFF)
334 + if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF)
335 return xdl_do_histogram_diff(mf1, mf2, xpp, xe);
336
337 if (xdl_prepare_env(mf1, mf2, xpp, xe) < 0) {
xdiff/xhistogram.c
+1 -1
@@ -252,7 +252,7 @@ static int fall_back_to_classic_diff(struct histindex *index,
252 int line1, int count1, int line2, int count2)
253 {
254 xpparam_t xpp;
255 - xpp.flags = index->xpp->flags & ~XDF_HISTOGRAM_DIFF;
255 + xpp.flags = index->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK;
256
257 return xdl_fall_back_diff(index->env, &xpp,
258 line1, count1, line2, count2);
xdiff/xpatience.c
+1 -1
@@ -288,7 +288,7 @@ static int fall_back_to_classic_diff(struct hashmap *map,
288 int line1, int count1, int line2, int count2)
289 {
290 xpparam_t xpp;
291 - xpp.flags = map->xpp->flags & ~XDF_PATIENCE_DIFF;
291 + xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK;
292
293 return xdl_fall_back_diff(map->env, &xpp,
294 line1, count1, line2, count2);
xdiff/xprepare.c
+10 -11
@@ -181,7 +181,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
181 if (!(recs = (xrecord_t **) xdl_malloc(narec * sizeof(xrecord_t *))))
182 goto abort;
183
184 - if (xpp->flags & XDF_HISTOGRAM_DIFF)
184 + if (XDF_DIFF_ALG(xpp->flags) == XDF_HISTOGRAM_DIFF)
185 hbits = hsize = 0;
186 else {
187 hbits = xdl_hashbits((unsigned int) narec);
@@ -209,8 +209,8 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
209 crec->ha = hav;
210 recs[nrec++] = crec;
211
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)
214 goto abort;
215 }
216 }
@@ -273,16 +273,15 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
273 * (nrecs) will be updated correctly anyway by
274 * xdl_prepare_ctx().
275 */
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);
278
279 enl1 = xdl_guess_lines(mf1, sample) + 1;
280 enl2 = xdl_guess_lines(mf2, sample) + 1;
281
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)
284 return -1;
285 - }
285
286 if (xdl_prepare_ctx(1, mf1, enl1, xpp, &cf, &xe->xdf1) < 0) {
287
@@ -296,9 +295,9 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
295 return -1;
296 }
297
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) {
301
302 xdl_free_ctx(&xe->xdf2);
303 xdl_free_ctx(&xe->xdf1);