Heads up: PR 1818 might change @root logic

32 views
Skip to first unread message

Edward K. Ream

unread,
Feb 16, 2021, 4:17:18 PM2/16/21
to leo-editor
PR #1818 deletes c.trimTrailingLines. The old version was:

def trimTrailingLines(self, p):
    body = p.b
    lines = body.split('\n')
    i = len(lines) - 1; changed = False
    while i >= 0:
        line = lines[i]
        j = g.skip_ws(line, 0)
        if j + 1 == len(line):
            del lines[i]
            i -= 1; changed = True
        else: break
    if changed:
        p.b = ''.join(body) + '\n'  # Add back one last newline.
        # Don't set the dirty bit: it would just be annoying.

Notice a bug: the code doesn't use the lines array at all! 

The new code simply ignores this method, but that is not exactly equivalent to the old code.

So now there is a dilemma. The old code is very bad, but even seemingly minor changes in the @root logic could be troublesome.

I am tempted, at last, to remove @root. It is, on purpose, not documented. Otoh, I don't want to inconvenience people who might be still using @root.

So for now, I am just going warn about the change. If you are affected by the new code, please let me know.

Edward


Edward K. Ream

unread,
Feb 17, 2021, 7:42:38 AM2/17/21
to leo-editor
On Tuesday, February 16, 2021 at 3:17:18 PM UTC-6 Edward K. Ream wrote:
PR #1818 deletes c.trimTrailingLines.
...
The new code simply ignores this method, but that is not exactly equivalent to the old code.

Rev 45e888 in devel ensures that the new code does nothing but move c.trimTrailingLines to be a local helper method of tangleCommands.skip_body. The "diff-branches/revs (one file)" script (in leoPy.leo) verifies leoTangle.py is exactly the same in the master and devel branches, except for the moved method.

Here is that script:

import os
import leo.commands.editFileCommands as efc
path = os.path.join(g.app.loadDir, '..', '..')
os.chdir(path)
efc.GitDiffController(c).diff_two_branches(
    branch1='master', # old branch/rev
    branch2='devel', # new branch/rev
    fn='leo/core/leoTangle.py',
    directory=None)


The should prove that new code should work exactly the same as the old, regardless of how weird trimTrailingLines is.

Summary

Leo's @root logic should now work exactly as before. As a result, the question of whether to retire support for @root is less urgent.

Nevertheless, I would like to retire support for @root.  Unless I hear protests, Leo 6.4 will not support @root.

If you use @root, now is the time to make a pitch for retaining it.

Edward
Reply all
Reply to author
Forward
0 new messages