Commits

Brendan Cully committed 662792b

Borrow wrapcommand from unreleased hg

Comments (0)

Files changed (1)

         if bundle:
             os.unlink(bundle)
 
-diffcmd = commands.table['^diff']
-realdiff = diffcmd[0]
-
-def diff(ui, repo, *pats, **opts):
+def diff(orig, ui, repo, *pats, **opts):
     url = None
     rrev = None
     if pats:
             rrev = opts['rev'][1]
         return rdiff(ui, repo, url, lrev, rrev, *pats, **opts)
     else:
-        return realdiff(ui, repo, *pats, **opts)
+        return orig(ui, repo, *pats, **opts)
 
-diff.__doc__ = realdiff.__doc__
+def wrapcommand(table, command, wrapper):
+    aliases, entry = cmdutil.findcmd(command, table)
+    for alias, e in table.iteritems():
+        if e is entry:
+            key = alias
+            break
 
-rdiffopts = [('', 'reverse', None, _('reverse patch direction'))] + \
-    commands.remoteopts
-diffcmd = list(diffcmd)
-diffcmd[0] = diff
-diffcmd[1] += rdiffopts
-commands.table['^diff'] = tuple(diffcmd)
+    origfn = entry[0]
+    def wrap(*args, **kwargs):
+        return wrapper(origfn, *args, **kwargs)
+
+    wrap.__doc__ = getattr(origfn, '__doc__')
+    if wrapper.__doc__:
+        if wrapper.__doc__.startswith('\n'):
+            wrap.__doc__ += wrapper.__doc__
+        else:
+            wrap.__doc__ = wrapper.__doc__
+
+    newentry = list(entry)
+    newentry[0] = wrap
+    table[key] = tuple(newentry)
+    return entry
+
+def uisetup(ui):
+    rdiffopts = [('', 'reverse', None, _('reverse patch direction'))] + \
+        commands.remoteopts
+
+    entry = wrapcommand(commands.table, 'diff', diff)
+    entry[1].extend(rdiffopts)