changeset 2043:c64300906a32

exthelper: move command declaration into the exthelper This is necessary to allow sub module to declare commands too.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sat, 04 Mar 2017 03:37:32 +0100
parents 206a7b864c05
children d31ad31e456b
files hgext3rd/evolve/__init__.py hgext3rd/evolve/exthelper.py
diffstat 2 files changed, 110 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py	Sat Mar 04 01:43:36 2017 +0100
+++ b/hgext3rd/evolve/__init__.py	Sat Mar 04 03:37:32 2017 +0100
@@ -130,9 +130,6 @@
 
 obsexcmsg = serveronly.obsexcmsg
 
-cmdtable = {}
-command = cmdutil.command(cmdtable)
-
 _pack = struct.pack
 _unpack = struct.unpack
 
@@ -154,6 +151,7 @@
 uisetup = eh.final_uisetup
 extsetup = eh.final_extsetup
 reposetup = eh.final_reposetup
+cmdtable = eh.cmdtable
 
 eh.extsetup(serveronly.extsetup)
 
@@ -816,7 +814,7 @@
         ui.warn(deprecationwarning)
         util.checksignature(fn)(*args, **kwargs)
     newfn.__doc__ = deprecationwarning
-    cmdwrapper = command(oldalias, opts, synopsis)
+    cmdwrapper = eh.command(oldalias, opts, synopsis)
     cmdwrapper(newfn)
 
 @eh.extsetup
@@ -824,7 +822,7 @@
     _deprecatealias('gup', 'next')
     _deprecatealias('gdown', 'previous')
 
-@command('debugrecordpruneparents', [], '')
+@eh.command('debugrecordpruneparents', [], '')
 def cmddebugrecordpruneparents(ui, repo):
     """add parent data to prune markers when possible
 
@@ -861,7 +859,7 @@
     finally:
         lockmod.release(tr, lock, wlock)
 
-@command('debugobsstorestat', [], '')
+@eh.command('debugobsstorestat', [], '')
 def cmddebugobsstorestat(ui, repo):
     """print statistics about obsolescence markers in the repo"""
     def _updateclustermap(nodes, mark, clustersmap):
@@ -1343,24 +1341,26 @@
 
     fm.end()
 
-@command('^evolve|stabilize|solve',
-         [('n', 'dry-run', False,
-             _('do not perform actions, just print what would be done')),
-          ('', 'confirm', False,
-             _('ask for confirmation before performing the action')),
-          ('A', 'any', False,
-              _('also consider troubled changesets unrelated to current working '
-                'directory')),
-          ('r', 'rev', [], _('solves troubles of these revisions')),
-          ('', 'bumped', False, _('solves only bumped changesets')),
-          ('', 'divergent', False, _('solves only divergent changesets')),
-          ('', 'unstable', False, _('solves only unstable changesets (default)')),
-          ('a', 'all', False, _('evolve all troubled changesets related to the '
-                                'current  working directory and its descendants')),
-          ('c', 'continue', False, _('continue an interrupted evolution')),
-          ('l', 'list', False, 'provide details on troubled changesets in the repo'),
-         ] + mergetoolopts,
-         _('[OPTIONS]...'))
+@eh.command(
+    '^evolve|stabilize|solve',
+    [('n', 'dry-run', False,
+      _('do not perform actions, just print what would be done')),
+     ('', 'confirm', False,
+      _('ask for confirmation before performing the action')),
+     ('A', 'any', False,
+      _('also consider troubled changesets unrelated to current working '
+        'directory')),
+     ('r', 'rev', [], _('solves troubles of these revisions')),
+     ('', 'bumped', False, _('solves only bumped changesets')),
+     ('', 'divergent', False, _('solves only divergent changesets')),
+     ('', 'unstable', False, _('solves only unstable changesets (default)')),
+     ('a', 'all', False, _('evolve all troubled changesets related to the '
+                           'current  working directory and its descendants')),
+     ('c', 'continue', False, _('continue an interrupted evolution')),
+     ('l', 'list', False, 'provide details on troubled changesets in the repo'),
+    ] + mergetoolopts,
+    _('[OPTIONS]...')
+)
 def evolve(ui, repo, **opts):
     """solve troubled changesets in your repository
 
@@ -1906,14 +1906,15 @@
 
 shorttemplate = '[{rev}] {desc|firstline}\n'
 
-@command('^previous',
-         [('B', 'move-bookmark', False,
-             _('move active bookmark after update')),
-          ('', 'merge', False, _('bring uncommitted change along')),
-          ('', 'no-topic', False, _('ignore topic and move topologically')),
-          ('n', 'dry-run', False,
-             _('do not perform actions, just print what would be done'))],
-         '[OPTION]...')
+@eh.command(
+    '^previous',
+    [('B', 'move-bookmark', False,
+        _('move active bookmark after update')),
+     ('', 'merge', False, _('bring uncommitted change along')),
+     ('', 'no-topic', False, _('ignore topic and move topologically')),
+     ('n', 'dry-run', False,
+        _('do not perform actions, just print what would be done'))],
+    '[OPTION]...')
 def cmdprevious(ui, repo, **opts):
     """update to parent revision
 
@@ -1976,15 +1977,16 @@
     finally:
         lockmod.release(wlock)
 
-@command('^next',
-         [('B', 'move-bookmark', False,
-             _('move active bookmark after update')),
-          ('', 'merge', False, _('bring uncommitted change along')),
-          ('', 'evolve', False, _('evolve the next changeset if necessary')),
-          ('', 'no-topic', False, _('ignore topic and move topologically')),
-          ('n', 'dry-run', False,
-              _('do not perform actions, just print what would be done'))],
-         '[OPTION]...')
+@eh.command(
+    '^next',
+    [('B', 'move-bookmark', False,
+        _('move active bookmark after update')),
+     ('', 'merge', False, _('bring uncommitted change along')),
+     ('', 'evolve', False, _('evolve the next changeset if necessary')),
+     ('', 'no-topic', False, _('ignore topic and move topologically')),
+     ('n', 'dry-run', False,
+      _('do not perform actions, just print what would be done'))],
+    '[OPTION]...')
 def cmdnext(ui, repo, **opts):
     """update to next child revision
 
@@ -2131,19 +2133,20 @@
         metadata['user'] = user
     return metadata
 
-@command('^prune|obsolete',
-         [('n', 'new', [], _("successor changeset (DEPRECATED)")),
-          ('s', 'succ', [], _("successor changeset")),
-          ('r', 'rev', [], _("revisions to prune")),
-          ('k', 'keep', None, _("does not modify working copy during prune")),
-          ('', 'biject', False, _("do a 1-1 map between rev and successor ranges")),
-          ('', 'fold', False,
-             _("record a fold (multiple precursors, one successors)")),
-          ('', 'split', False,
-             _("record a split (on precursor, multiple successors)")),
-          ('B', 'bookmark', [], _("remove revs only reachable from given"
-                                  " bookmark"))] + metadataopts,
-         _('[OPTION] [-r] REV...'))
+@eh.command(
+    '^prune|obsolete',
+    [('n', 'new', [], _("successor changeset (DEPRECATED)")),
+     ('s', 'succ', [], _("successor changeset")),
+     ('r', 'rev', [], _("revisions to prune")),
+     ('k', 'keep', None, _("does not modify working copy during prune")),
+     ('', 'biject', False, _("do a 1-1 map between rev and successor ranges")),
+     ('', 'fold', False,
+      _("record a fold (multiple precursors, one successors)")),
+     ('', 'split', False,
+      _("record a split (on precursor, multiple successors)")),
+     ('B', 'bookmark', [], _("remove revs only reachable from given"
+                             " bookmark"))] + metadataopts,
+    _('[OPTION] [-r] REV...'))
 # XXX -U  --noupdate option to prevent wc update and or bookmarks update ?
 def cmdprune(ui, repo, *revs, **opts):
     """hide changesets by marking them obsolete
@@ -2314,15 +2317,16 @@
     finally:
         lockmod.release(tr, lock, wlock)
 
-@command('amend|refresh',
-         [('A', 'addremove', None,
-           _('mark new/missing files as added/removed before committing')),
-          ('e', 'edit', False, _('invoke editor on commit messages')),
-          ('', 'close-branch', None,
-           _('mark a branch as closed, hiding it from the branch list')),
-          ('s', 'secret', None, _('use the secret phase for committing')),
-         ] + walkopts + commitopts + commitopts2 + commitopts3 + interactiveopt,
-         _('[OPTION]... [FILE]...'))
+@eh.command(
+    'amend|refresh',
+    [('A', 'addremove', None,
+      _('mark new/missing files as added/removed before committing')),
+     ('e', 'edit', False, _('invoke editor on commit messages')),
+     ('', 'close-branch', None,
+      _('mark a branch as closed, hiding it from the branch list')),
+     ('s', 'secret', None, _('use the secret phase for committing')),
+    ] + walkopts + commitopts + commitopts2 + commitopts3 + interactiveopt,
+    _('[OPTION]... [FILE]...'))
 def amend(ui, repo, *pats, **opts):
     """combine a changeset with updates and replace it with a new one
 
@@ -2454,11 +2458,12 @@
             src = None
         ds.copy(src, dst)
 
-@command('^uncommit',
-         [('a', 'all', None, _('uncommit all changes when no arguments given')),
-          ('r', 'rev', '', _('revert commit content to REV instead')),
-          ] + commands.walkopts,
-         _('[OPTION]... [NAME]'))
+@eh.command(
+    '^uncommit',
+    [('a', 'all', None, _('uncommit all changes when no arguments given')),
+     ('r', 'rev', '', _('revert commit content to REV instead')),
+     ] + commands.walkopts,
+    _('[OPTION]... [NAME]'))
 def uncommit(ui, repo, *pats, **opts):
     """move changes from parent revision to working directory
 
@@ -2568,10 +2573,11 @@
     finally:
         lockmod.release(tr, lock, wlock)
 
-@command('^split',
-         [('r', 'rev', [], _("revision to split")),
-         ] + commitopts + commitopts2,
-         _('hg split [OPTION]... [-r] REV'))
+@eh.command(
+    '^split',
+    [('r', 'rev', [], _("revision to split")),
+    ] + commitopts + commitopts2,
+    _('hg split [OPTION]... [-r] REV'))
 def cmdsplit(ui, repo, *revs, **opts):
     """split a changeset into smaller changesets
 
@@ -2675,15 +2681,16 @@
     kwargs['biject'] = False
     return cmdprune(ui, repo, *revs, **kwargs)
 
-@command('^touch',
-         [('r', 'rev', [], 'revision to update'),
-          ('D', 'duplicate', False,
-           'do not mark the new revision as successor of the old one'),
-          ('A', 'allowdivergence', False,
-           'mark the new revision as successor of the old one potentially creating '
-           'divergence')],
-         # allow to choose the seed ?
-         _('[-r] revs'))
+@eh.command(
+    '^touch',
+    [('r', 'rev', [], 'revision to update'),
+     ('D', 'duplicate', False,
+      'do not mark the new revision as successor of the old one'),
+     ('A', 'allowdivergence', False,
+      'mark the new revision as successor of the old one potentially creating '
+      'divergence')],
+    # allow to choose the seed ?
+    _('[-r] revs'))
 def touch(ui, repo, *revs, **opts):
     """create successors that are identical to their predecessors except
     for the changeset ID
@@ -2761,12 +2768,13 @@
     finally:
         lockmod.release(tr, lock, wlock)
 
-@command('^fold|squash',
-         [('r', 'rev', [], _("revision to fold")),
-          ('', 'exact', None, _("only fold specified revisions")),
-          ('', 'from', None, _("fold revisions linearly to working copy parent"))
-         ] + commitopts + commitopts2,
-         _('hg fold [OPTION]... [-r] REV'))
+@eh.command(
+    '^fold|squash',
+    [('r', 'rev', [], _("revision to fold")),
+     ('', 'exact', None, _("only fold specified revisions")),
+     ('', 'from', None, _("fold revisions linearly to working copy parent"))
+    ] + commitopts + commitopts2,
+    _('hg fold [OPTION]... [-r] REV'))
 def fold(ui, repo, *revs, **opts):
     """fold multiple revisions into a single one
 
@@ -2874,11 +2882,12 @@
     finally:
         lockmod.release(lock, wlock)
 
-@command('^metaedit',
-         [('r', 'rev', [], _("revision to edit")),
-          ('', 'fold', None, _("also fold specified revisions into one")),
-         ] + commitopts + commitopts2,
-         _('hg metaedit [OPTION]... [-r] [REV]'))
+@eh.command(
+    '^metaedit',
+    [('r', 'rev', [], _("revision to edit")),
+     ('', 'fold', None, _("also fold specified revisions into one")),
+    ] + commitopts + commitopts2,
+    _('hg metaedit [OPTION]... [-r] [REV]'))
 def metaedit(ui, repo, *revs, **opts):
     """edit commit information
 
@@ -3426,9 +3435,10 @@
     return serveronly._getobsmarkersstream(self._repo, heads=heads,
                                            common=common)
 
-@command('debugobsrelsethashtree',
-         [('', 'v0', None, 'hash on marker format "0"'),
-          ('', 'v1', None, 'hash on marker format "1" (default)')], _(''))
+@eh.command(
+    'debugobsrelsethashtree',
+    [('', 'v0', None, 'hash on marker format "0"'),
+     ('', 'v1', None, 'hash on marker format "1" (default)')], _(''))
 def debugobsrelsethashtree(ui, repo, v0=False, v1=False):
     """display Obsolete markers, Relevant Set, Hash Tree
     changeset-node obsrelsethashtree-node
@@ -3463,7 +3473,7 @@
             hint = _('You should run `hg debugobsconvert`')
             raise error.Abort(msg, hint=hint)
 
-@command(
+@eh.command(
     'debugobsconvert',
     [('', 'new-format', _bestformat, _('Destination format for markers.'))],
     '')
--- a/hgext3rd/evolve/exthelper.py	Sat Mar 04 01:43:36 2017 +0100
+++ b/hgext3rd/evolve/exthelper.py	Sat Mar 04 03:37:32 2017 +0100
@@ -3,6 +3,7 @@
 #####################################################################
 
 from mercurial import (
+    cmdutil,
     commands,
     extensions,
     revset,
@@ -28,6 +29,8 @@
         self._extcommandwrappers = []
         self._functionwrappers = []
         self._duckpunchers = []
+        self.cmdtable = {}
+        self.command = cmdutil.command(self.cmdtable)
 
     def merge(self, other):
         """merge the data collected by another exthelper into this one"""
@@ -40,6 +43,7 @@
         self._extcommandwrappers.extend(other._extcommandwrappers)
         self._functionwrappers.extend(other._functionwrappers)
         self._duckpunchers.extend(other._duckpunchers)
+        self.cmdtable.update(other.cmdtable)
 
     def final_uisetup(self, ui):
         """Method to be used as the extension uisetup