Skip to content

Commit 713b85c

Browse files
committed
Merge branch 'rs/diff-cleanup-records-fix' into maint
* rs/diff-cleanup-records-fix: diff: resurrect XDF_NEED_MINIMAL with --minimal Revert removal of multi-match discard heuristic in 27af01
2 parents 689b047 + 81b568c commit 713b85c

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Documentation/diff-options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ ifndef::git-format-patch[]
4545
Synonym for `-p --raw`.
4646
endif::git-format-patch[]
4747

48+
--minimal::
49+
Spend extra time to make sure the smallest possible
50+
diff is produced.
51+
4852
--patience::
4953
Generate a diff using the "patience diff" algorithm.
5054

diff.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3385,6 +3385,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
33853385
}
33863386

33873387
/* xdiff options */
3388+
else if (!strcmp(arg, "--minimal"))
3389+
DIFF_XDL_SET(options, NEED_MINIMAL);
3390+
else if (!strcmp(arg, "--no-minimal"))
3391+
DIFF_XDL_CLR(options, NEED_MINIMAL);
33883392
else if (!strcmp(arg, "-w") || !strcmp(arg, "--ignore-all-space"))
33893393
DIFF_XDL_SET(options, IGNORE_WHITESPACE);
33903394
else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))

xdiff/xprepare.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ static int xdl_clean_mmatch(char const *dis, long i, long s, long e) {
383383
* might be potentially discarded if they happear in a run of discardable.
384384
*/
385385
static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xdf2) {
386-
long i, nm, nreff;
386+
long i, nm, nreff, mlim;
387387
xrecord_t **recs;
388388
xdlclass_t *rcrec;
389389
char *dis, *dis1, *dis2;
@@ -396,16 +396,20 @@ static int xdl_cleanup_records(xdlclassifier_t *cf, xdfile_t *xdf1, xdfile_t *xd
396396
dis1 = dis;
397397
dis2 = dis1 + xdf1->nrec + 1;
398398

399+
if ((mlim = xdl_bogosqrt(xdf1->nrec)) > XDL_MAX_EQLIMIT)
400+
mlim = XDL_MAX_EQLIMIT;
399401
for (i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart]; i <= xdf1->dend; i++, recs++) {
400402
rcrec = cf->rcrecs[(*recs)->ha];
401403
nm = rcrec ? rcrec->len2 : 0;
402-
dis1[i] = (nm == 0) ? 0: 1;
404+
dis1[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1;
403405
}
404406

407+
if ((mlim = xdl_bogosqrt(xdf2->nrec)) > XDL_MAX_EQLIMIT)
408+
mlim = XDL_MAX_EQLIMIT;
405409
for (i = xdf2->dstart, recs = &xdf2->recs[xdf2->dstart]; i <= xdf2->dend; i++, recs++) {
406410
rcrec = cf->rcrecs[(*recs)->ha];
407411
nm = rcrec ? rcrec->len1 : 0;
408-
dis2[i] = (nm == 0) ? 0: 1;
412+
dis2[i] = (nm == 0) ? 0: (nm >= mlim) ? 2: 1;
409413
}
410414

411415
for (nreff = 0, i = xdf1->dstart, recs = &xdf1->recs[xdf1->dstart];

0 commit comments

Comments
 (0)