leo/doc/leoNotes.txt now contains prototypes of several bzr hooks.  See:

    leoPy.leo#Notes-->@file ../doc/leoNotes.txt-->bzr hooks: prototypes

I'll show them in the Post Script.

This is the second time I've played around with bzr hooks.  It's not a fun 
experience.  Both the documentation and the actual bzr hook architecture 
are poor.  The only way to get something that works is with trial and error 
and liberal use of dir to find out what bzr classes actually contain!

This process revealed two big problems:

1. Bzr has no pre_push hook!  This would be the hook that calls just before 
doing a push.  Having a post_push hook seems useless.

2. As I was thinking about this problem, I realized (Doh!) that bzr doesn't 
push actual files--it pushes diffs, or their equivalent.

It's a good thing that I didn't know about these problems initially: I 
would never have had the original Aha ;-)

I did have the feeling, though, that things might not be all that easy.

Several possible ways forward may be possible:

1. A post_commit hook.  This would do the actual "switcheroo" of the 
files.  But that creates it's own problems.  Nancy will see the sentinels 
until (presumably) the post_push hook undid the switcheroo.    And 
switcheroos could well confuse bzr.

2. A completely different alternative would be to create, say, Emacs 
load/save hooks.  The load hook would strip Leo sentinels, the save hook 
would put them back, using the @shadow algorithm.  This might be, in some 
sense, a bit simpler because bzr is not involved.  The implementation would 
require that the leoBridge be installed (not a huge deal).  And the actual 
push/pull hooks would be written in elisp.  Again, not a huge deal: all the 
real work would be done in the bridge.

Of course Point 2 requires load/save hooks for vim, Eclipse, etc.  I 
suspect the work involved would be similar to supporting all kinds of 
SCCS.  Anyway, we only need to do *one* set of load/save hooks as a 
prototype.

Edward

P.S.  Here are the three prototype files.  The traces reveal how little the 
docs help.  I did most of my exploration using the status hook, because bzr 
status can be invoked without affecting the repo.

BTW, it would be reasonable to put all the following code into a single 
file, say leo_push_pull_hooks.py.

===== status_hook.py:

from bzrlib import status

def post_status_hook(args):
    print('status_hook.py: post_status_hook')
    if 0:
        # args.old_tree, args.new_tree, args.to_file,
        # args.versioned, args.show_ids, args.short, args.verbose
        print('\n'.join(
            ['%s %s' % (z,getattr(args,z)) for z in sorted(dir(args))
                if not z.startswith('_')]))

if 0: # disable
    status.StatusHooks().install_named_hook(
        'post_status',post_status_hook,'EKR post_status hook')

===== push_hook.py:

from bzrlib import branch

def post_push_hook(arg):
    print('post_push_hook')
    # print('\n'.join(dir(arg)))
    
if 0: # Disable.
    branch.Branch.hooks.install_named_hook(
        'post_push', post_push_hook,'EKR post_push hook')

===== command_hook.py

from bzrlib import commands
from bzrlib import mutabletree

def pre_command_hook(*args,**keys):
    print('command_hook.py: pre_command_hook')
    
def post_commit_hook(args):
    print('command_hook.py: post_commit_hook')
    if 0:
        print('\n'.join(
            ['%s %s' % (z,getattr(args,z)) for z in sorted(dir(args))
                if not z.startswith('_')]))

if 0: # does not work.
    commands.CommandHooks().install_named_hook(
        'pre_command',pre_command_hook,'EKR pre_command hook')
        
if 0: # works.
    mutabletree.MutableTreeHooks().install_named_hook(
        'post_commit',post_commit_hook,'EKR post_commit hook')

All in all, a pretty miserable experience.

EKR

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to