Mercurial > hg
view mercurial/extensions.py @ 8742:a964ab624385
merge: allow merging going backwards
New behavior is generally superior and more correct, except possibly
with regards to missing files. hg up . is now effectively a no-op,
which is probably the desired behavior for people expecting to move to
tip, but may surprise people who were expecting deleted files to
reappear.
case 1: update to .
a-w -> a-w
classic: ancestor a
missing recreated right?
rmed recreated WRONG
added forgotten WRONG
changed preserved RIGHT
conflicted can't happen
backward merge: ancestor a (NO EFFECT)
missing missing wrong?
rm'ed rm'ed RIGHT
added preserved RIGHT
changed preserved RIGHT
conflicted can't happen
case 2: update to ancestor of .
a-b-w -> b-w
\
a
classic: ancestor a
missing recreated right?
rmed recreated wrong?
added forgotten wrong?
changed preserved RIGHT
conflicted preserved wrong?
backwards merge: ancestor b
missing missing or conflict right?
rm'ed missing or conflict right?
changed preserved RIGHT
conflicted merge RIGHT
added preserved right?
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 08 Jun 2009 18:14:44 -0500 |
parents | 46293a0c7e9f |
children | 20a25042fadc |
line wrap: on
line source
# extensions.py - extension handling for mercurial # # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2, incorporated herein by reference. import imp, os import util, cmdutil from i18n import _ _extensions = {} _order = [] def extensions(): for name in _order: module = _extensions[name] if module: yield name, module def find(name): '''return module with given extension name''' try: return _extensions[name] except KeyError: for k, v in _extensions.iteritems(): if k.endswith('.' + name) or k.endswith('/' + name): return v raise KeyError(name) def loadpath(path, module_name): module_name = module_name.replace('.', '_') path = os.path.expanduser(path) if os.path.isdir(path): # module/__init__.py style d, f = os.path.split(path.rstrip('/')) fd, fpath, desc = imp.find_module(f, [d]) return imp.load_module(module_name, fd, fpath, desc) else: return imp.load_source(module_name, path) def load(ui, name, path): if name.startswith('hgext.') or name.startswith('hgext/'): shortname = name[6:] else: shortname = name if shortname in _extensions: return _extensions[shortname] = None if path: # the module will be loaded in sys.modules # choose an unique name so that it doesn't # conflicts with other modules mod = loadpath(path, 'hgext.%s' % name) else: def importh(name): mod = __import__(name) components = name.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod try: mod = importh("hgext.%s" % name) except ImportError: mod = importh(name) _extensions[shortname] = mod _order.append(shortname) uisetup = getattr(mod, 'uisetup', None) if uisetup: uisetup(ui) def loadall(ui): result = ui.configitems("extensions") for (name, path) in result: if path: if path[0] == '!': continue try: load(ui, name, path) except KeyboardInterrupt: raise except Exception, inst: if path: ui.warn(_("*** failed to import extension %s from %s: %s\n") % (name, path, inst)) else: ui.warn(_("*** failed to import extension %s: %s\n") % (name, inst)) if ui.traceback(): return 1 def wrapcommand(table, command, wrapper): aliases, entry = cmdutil.findcmd(command, table) for alias, e in table.iteritems(): if e is entry: key = alias break origfn = entry[0] def wrap(*args, **kwargs): return util.checksignature(wrapper)( util.checksignature(origfn), *args, **kwargs) wrap.__doc__ = getattr(origfn, '__doc__') wrap.__module__ = getattr(origfn, '__module__') newentry = list(entry) newentry[0] = wrap table[key] = tuple(newentry) return entry def wrapfunction(container, funcname, wrapper): def wrap(*args, **kwargs): return wrapper(origfn, *args, **kwargs) origfn = getattr(container, funcname) setattr(container, funcname, wrap) return origfn