Source

hgd / hacks.py

Full commit
import os
import sys

libdir = '@LIBDIR@'

if libdir != '@' 'LIBDIR' '@':
    if not os.path.isabs(libdir):
        libdir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                              libdir)
        libdir = os.path.abspath(libdir)
    sys.path.insert(0, libdir)

# enable importing on demand to reduce startup time
try:
    from mercurial import demandimport; demandimport.enable()
except ImportError:
    import sys
    sys.stderr.write("abort: couldn't find mercurial libraries in [%s]\n" %
                     ' '.join(sys.path))
    sys.stderr.write("(check your install and PYTHONPATH)\n")
    sys.exit(-1)

import mercurial.util
import mercurial.dispatch
from mercurial import commands

for fp in (sys.stdin, sys.stdout, sys.stderr):
    mercurial.util.set_binary(fp)


# FIX MERCURIAL'S BROKEN ALIAS ADDING ---------------------------------------------

def _patched_addaliases(ui, cmdtable):
    # aliases are processed after extensions have been loaded, so they
    # may use extension commands. Aliases can also use other alias definitions,
    # but only if they have been defined prior to the current definition.
    for alias, definition in ui.configitems('alias'):
        aliasdef = mercurial.dispatch.cmdalias(alias, definition, cmdtable)
        if not aliasdef.cmd in cmdtable:
            cmdtable[aliasdef.cmd] = (aliasdef, aliasdef.opts, aliasdef.help)
        if aliasdef.norepo:
            commands.norepo += ' %s' % alias
mercurial.dispatch.addaliases = _patched_addaliases