moin icon indicating copy to clipboard operation
moin copied to clipboard

diff confused by removal of extra blank line

Open RogerHaase opened this issue 4 years ago • 2 comments

Create an item with an extra blank line between paragraphs:

111


222

333

update the item and remove the extra blank line

111a

222a

333a

View the item's history and click the diff button. The diff shows 222a as a new line and 333a has replaced 222\n333.

RogerHaase avatar May 08 '20 20:05 RogerHaase

Is this really a bug? I think it's just the way difflib works.

When I run your example directly with difflib, it matches your result.

a = """111


222

333""".splitlines(keepends=True)

b = """111a

222a

333a""".splitlines(keepends=True)

d = difflib.Differ()
r = d.compare(a, b)
pprint(list(r))

s = difflib.SequenceMatcher(a=a, b=b)
pprint(s.get_opcodes())

Maybe the line-oriented approach is not a good match for this use case. When I delete .splitlines(keepends=True), difflib compares character by character (I think..?). Imho, the result is probably more readable, if a certain length before and after the location of the change is displayed and subsequent changes are treated as one.

pktl avatar Dec 15 '20 14:12 pktl

Could be an enhancement rather than a bug, and my example could have been better.

Start a new item with ( 2 blank lines after 111):

111


222

333

444

Then add an 'a' after each line and leave the 2 blank lines after 111 unchanged:

111a


222a

333a

444a

Do a print preview ( shows 'a' added to each paragraph)

Delete one of the blank lines after 111a and do another print preview (shows paragraph mismatch that will continue until a matching paragraph or EOF).

Will change to enhancement and priority 5.

RogerHaase avatar Dec 16 '20 17:12 RogerHaase