diff --git a/hgext/fix.py b/hgext/fix.py --- a/hgext/fix.py +++ b/hgext/fix.py @@ -598,10 +598,18 @@ [(2, 4)] """ ranges = [] - for lines, kind in mdiff.allblocks(content1, content2): + lines2 = mdiff.splitnewlines(content2) + for lines, kind in mdiff.allblocks(content1, content2, lines2=lines2): firstline, lastline = lines[2:4] - if kind == b'!' and firstline != lastline: - ranges.append((firstline + 1, lastline)) + # Produce a line range whenever the two sources differ and EITHER there + # is an addition/modification OR there is an adjacent blank line. + if kind == b'!' and (firstline != lastline or + b'\n' in lines2[firstline - 1: lastline + 1]): + # Generate diffs for blank lines adjacent to the change. + ranges.append(( + firstline + 1 - int(b'\n' in lines2[firstline - 1: firstline]), + lastline + int(b'\n' in lines2[lastline: lastline + 1]), + )) return ranges diff --git a/tests/test-fix.t b/tests/test-fix.t --- a/tests/test-fix.t +++ b/tests/test-fix.t @@ -432,22 +432,23 @@ Test that incremental fixing works on files with additions, deletions, and changes in multiple line ranges. Note that deletions do not generally cause neighboring lines to be fixed, so we don't return a line range for purely -deleted sections. In the future we should support a :deletion config that -allows fixers to know where deletions are located. +deleted sections except in the case of adjacent whitespace. In the future we +should support a :deletion config that allows fixers to unconditionally know +where deletions are located. $ hg init incrementalfixedlines $ cd incrementalfixedlines - $ printf "a\nb\nc\nd\ne\nf\ng\n" > foo.txt + $ printf "a\nb\nc\nd\ne\nf\ng\nh\n\ni\n\n" > foo.txt $ hg commit -Aqm "foo" - $ printf "zz\na\nc\ndd\nee\nff\nf\ngg\n" > foo.txt + $ printf "zz\na\nc\ndd\nee\nff\nf\ngg\nh\n\n\n" > foo.txt $ hg --config "fix.fail:command=echo" \ > --config "fix.fail:linerange={first}:{last}" \ > --config "fix.fail:pattern=foo.txt" \ > fix --working-dir $ cat foo.txt - 1:1 4:6 8:8 + 1:1 4:6 8:8 10:11 $ cd ..