[PATCH] alias: implement register_aliases for functionally easy aliasing

Peter Ruibal ruibalp at gmail.com
Fri Aug 29 02:54:20 CDT 2008


I committed this changeset to my private mercurial branch in order to make
it easier for my extensions to register aliases, and thought someone
upstream might find it useful.  :)

It splits a "register_aliases(ui, aliases)" function out of the the
"uisetup(ui)" function in alias.py.  This is to make it easier for your own
extensions to register aliases while minimizing code duplication.

aliases is a dict of {"cmd": "tcmd --opts", ...}  much like the [alias]
section contains cmd=tcmd --opts.

For example, you could have the following uisetup in your extension:

def uisetup(ui):
    try:
        import mercurial.extensions
        alias = mercurial.extensions.find('alias')
        alias.register_aliases({
            'qpromote': 'qdelete --rev',
            'new':     'add',
            'unedit':  'revert',
            'changes': 'log',
        })
    except KeyError:
        ui.warn("alias extension is required to add aliases.  Please add
alias= to your [extensions] section in mercurial.ini")

If any changes to the patch are necessary for inclusion in mercurial, I
would be more than willing to make them and resubmit this as necessary if
requested... Otherwise, someone might find this useful as-is to add to their
hg hg patchqueue

Regards,
-- 
Peter Ruibal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://selenic.com/pipermail/mercurial-devel/attachments/20080829/b56c86e7/attachment.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alias-register-aliases.patch
Type: application/octet-stream
Size: 1151 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20080829/b56c86e7/attachment.obj 


More information about the Mercurial-devel mailing list