Commit a6ab856
committed
patience diff: remove myers fallback
When the patience_diff() is called on a range of lines that does not
contain any unique context lines it falls back to calling the myers
algorithm on that region. The myers implementation calls
xdl_optimize_ctxs() but because it is called on a subset of the input it
cannot optimize the context lines as well is it does when called on the
whole file. In particular insignificant blank lines that would be
ignored as matches by the myers algorithm when it is run on the whole
file will be considered matches within a smaller region. This has the
unfortunate effect of matching blank lines as context when they are not
meaningful generating sub-optimal diffs.
Instead when there are no unique context lines within a region just find
the leading, trailing and inter-hunk context. This is more in keeping
with the patience algorithm outlined by Bram Cohen[1].
Note that the interhunk context code rarely finds any interhunk
context. In git it finds interhunk context 158 times out of the
8598 hunks where there are no unique lines (there are 368157 hunks
in total). Trailing context is even rarer with just 101 instances
in the 8598 hunk with no unique lines. There are no instances of
Leading context which seems suprising but the leading context is
handled cororectly in tests added in this patch.
[1] https://bramcohen.livejournal.com/73318.html
Signed-off-by: Phillip Wood <[email protected]>1 parent 133d151 commit a6ab856
2 files changed
+112
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
20 | 62 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
303 | 304 | | |
304 | 305 | | |
305 | 306 | | |
306 | | - | |
307 | | - | |
| 307 | + | |
308 | 308 | | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
313 | 313 | | |
314 | | - | |
315 | | - | |
| 314 | + | |
316 | 315 | | |
317 | 316 | | |
318 | 317 | | |
| |||
357 | 356 | | |
358 | 357 | | |
359 | 358 | | |
360 | | - | |
| 359 | + | |
361 | 360 | | |
362 | 361 | | |
363 | | - | |
364 | | - | |
365 | | - | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
366 | 424 | | |
367 | 425 | | |
368 | 426 | | |
| |||
0 commit comments