Show More
@@ -268,14 +268,23 b' def _unidiff(t1, t2, l1, l2, opts=defaul' | |||||
268 | # them into diff output. |
|
268 | # them into diff output. | |
269 | # |
|
269 | # | |
270 | hunk = None |
|
270 | hunk = None | |
|
271 | ignoredlines = 0 | |||
271 | for s, stype in allblocks(t1, t2, opts, l1, l2): |
|
272 | for s, stype in allblocks(t1, t2, opts, l1, l2): | |
|
273 | a1, a2, b1, b2 = s | |||
272 | if stype != '!': |
|
274 | if stype != '!': | |
|
275 | if stype == '~': | |||
|
276 | # The diff context lines are based on t1 content. When | |||
|
277 | # blank lines are ignored, the new lines offsets must | |||
|
278 | # be adjusted as if equivalent blocks ('~') had the | |||
|
279 | # same sizes on both sides. | |||
|
280 | ignoredlines += (b2 - b1) - (a2 - a1) | |||
273 | continue |
|
281 | continue | |
274 | delta = [] |
|
282 | delta = [] | |
275 | a1, a2, b1, b2 = s |
|
|||
276 | old = l1[a1:a2] |
|
283 | old = l1[a1:a2] | |
277 | new = l2[b1:b2] |
|
284 | new = l2[b1:b2] | |
278 |
|
285 | |||
|
286 | b1 -= ignoredlines | |||
|
287 | b2 -= ignoredlines | |||
279 | astart = contextstart(a1) |
|
288 | astart = contextstart(a1) | |
280 | bstart = contextstart(b1) |
|
289 | bstart = contextstart(b1) | |
281 | prev = None |
|
290 | prev = None |
@@ -455,3 +455,46 b' Do not ignore all newlines, only blank l' | |||||
455 | +hello |
|
455 | +hello | |
456 | +world |
|
456 | +world | |
457 | goodbye world |
|
457 | goodbye world | |
|
458 | ||||
|
459 | Test hunk offsets adjustments with --ignore-blank-lines | |||
|
460 | ||||
|
461 | $ hg revert -aC | |||
|
462 | reverting foo | |||
|
463 | $ printf '\nb\nx\nd\n' > a | |||
|
464 | $ printf 'b\ny\nd\n' > b | |||
|
465 | $ hg add a b | |||
|
466 | $ hg ci -m add | |||
|
467 | $ hg cat -r . a > b | |||
|
468 | $ hg cat -r . b > a | |||
|
469 | $ hg diff -B --nodates a > ../diffa | |||
|
470 | $ cat ../diffa | |||
|
471 | diff -r 0e66aa54f318 a | |||
|
472 | --- a/a | |||
|
473 | +++ b/a | |||
|
474 | @@ -1,4 +1,4 @@ | |||
|
475 | ||||
|
476 | b | |||
|
477 | -x | |||
|
478 | +y | |||
|
479 | d | |||
|
480 | $ hg diff -B --nodates b > ../diffb | |||
|
481 | $ cat ../diffb | |||
|
482 | diff -r 0e66aa54f318 b | |||
|
483 | --- a/b | |||
|
484 | +++ b/b | |||
|
485 | @@ -1,3 +1,3 @@ | |||
|
486 | b | |||
|
487 | -y | |||
|
488 | +x | |||
|
489 | d | |||
|
490 | $ hg revert -aC | |||
|
491 | reverting a | |||
|
492 | reverting b | |||
|
493 | $ hg import --no-commit ../diffa | |||
|
494 | applying ../diffa | |||
|
495 | $ hg revert -aC | |||
|
496 | reverting a | |||
|
497 | $ hg import --no-commit ../diffb | |||
|
498 | applying ../diffb | |||
|
499 | $ hg revert -aC | |||
|
500 | reverting b |
General Comments 0
You need to be logged in to leave comments.
Login now