[pmwiki-users] prepending comment posts

Patrick R. Michaud pmichaud at pobox.com
Sat Apr 14 01:45:02 CDT 2007


On Sat, Apr 14, 2007 at 07:03:53AM +0100, Hans wrote:
> Oh this looks good! No more diff saving of all downshifted posts!
> But I found a little problem with how diff shows single line text in
> >>frame<< boxes: The lines are changed around.
> 
> in diff:
> Added lines 2-5:
> This is post 5
> >><<
> 
> >>frame<<
> 
> actual page addition:
> [Added lines 1-4:]
> >>frame<<
> This is post 5
> >><<
>

Both additions produce the same result -- the new algorithm just
happens to choose the one that comes later.

To illustrate, if we start with (line numbers for reference)

    1: >>frame<<
    2: this is post 1
    3: >><<

then one can add either of

    2: this is post 2                  1: >>frame<<
    3: >><<                            2: this is post 2
    4:                                 3: >><<
    5: >>frame<<                       4:

to end up with the identical result:

    1: >>frame<<
    2: this is post 2
    3: >><<
    4:
    5: >>frame<<
    6: this is post 1
    7: >><<

The reason is that line 1 and line 5 in the final output are
exactly the same, so the diff algorithm ends up with a choice
as to whether the common line should go at the beginning or
end of the added section.    Another view of what's happening:

    Original                           Updated
    >>frame<<        --unchanged->     >>frame<<
                     ---added---->     this is post 2
                     ---added---->     >><<
                     ---added---->
                     ---added---->     >>frame<<
    this is post 1   --unchanged->     this is post 1
    >><<             --unchanged->     >><<

I'll have to think about it a bit more, but I think that anything
we might do to try to bias the algorithm towards the other
option my just cause other situations to display funny in the
history (or worse, produce an incorrect diff).  So, for now
I'm inclined to go with the new version as it stands rather
than try to tweak it too much further.

At least we're no longer getting the downshifting diffs.  :-)

I've gone ahead and installed the new diff code on the pmwiki.org
main site, we'll run it there for a day to make sure there aren't
any other bugs in it.  However, given the importance of page
history [1], I've already quadruple-checked the new code to 
make sure it's not introducing any new bugs.

Pm

[1]  It's important that page history work properly, because if
a history entry is incorrectly computed or stored then all
versions of the page prior to the incorrect entry are
essentially lost (or at least very difficult to recover).




More information about the pmwiki-users mailing list