changeset 41061:98681293c890

largefiles: port commands to exthelper One subtle change here is that the purge, rebase and transplant extensions are wrapped in extsetup() instead of uisetup().
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 23 Dec 2018 17:26:25 -0500
parents 7250cbaabde0
children 0a7f582f6f1f
files hgext/largefiles/__init__.py hgext/largefiles/lfcommands.py hgext/largefiles/overrides.py hgext/largefiles/uisetup.py
diffstat 4 files changed, 57 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/__init__.py	Sun Dec 23 21:54:56 2018 -0500
+++ b/hgext/largefiles/__init__.py	Sun Dec 23 17:26:25 2018 -0500
@@ -128,6 +128,8 @@
 testedwith = 'ships-with-hg-core'
 
 eh = exthelper.exthelper()
+eh.merge(lfcommands.eh)
+eh.merge(overrides.eh)
 
 eh.configitem('largefiles', 'minsize',
     default=configitems.dynamicdefault,
@@ -139,17 +141,20 @@
     default=None,
 )
 
+cmdtable = eh.cmdtable
 configtable = eh.configtable
+extsetup = eh.finalextsetup
 reposetup = reposetup.reposetup
+uisetup = eh.finaluisetup
 
 def featuresetup(ui, supported):
     # don't die on seeing a repo with the largefiles requirement
     supported |= {'largefiles'}
 
-def uisetup(ui):
+@eh.uisetup
+def _uisetup(ui):
     localrepo.featuresetupfuncs.add(featuresetup)
     hg.wirepeersetupfuncs.append(proto.wirereposetup)
     uisetupmod.uisetup(ui)
 
-cmdtable = lfcommands.cmdtable
 revsetpredicate = overrides.revsetpredicate
--- a/hgext/largefiles/lfcommands.py	Sun Dec 23 21:54:56 2018 -0500
+++ b/hgext/largefiles/lfcommands.py	Sun Dec 23 17:26:25 2018 -0500
@@ -20,12 +20,12 @@
     cmdutil,
     context,
     error,
+    exthelper,
     hg,
     lock,
     match as matchmod,
     node,
     pycompat,
-    registrar,
     scmutil,
     util,
 )
@@ -44,10 +44,9 @@
 
 # -- Commands ----------------------------------------------------------
 
-cmdtable = {}
-command = registrar.command(cmdtable)
+eh = exthelper.exthelper()
 
-@command('lfconvert',
+@eh.command('lfconvert',
     [('s', 'size', '',
       _('minimum size (MB) for files to be converted as largefiles'), 'SIZE'),
     ('', 'to-normal', False,
@@ -560,7 +559,7 @@
             statuswriter(_('%d largefiles updated, %d removed\n') % (updated,
                 removed))
 
-@command('lfpull',
+@eh.command('lfpull',
     [('r', 'rev', [], _('pull largefiles for these revisions'))
     ] + cmdutil.remoteopts,
     _('-r REV... [-e CMD] [--remotecmd CMD] [SOURCE]'))
@@ -599,7 +598,7 @@
         numcached += len(cached)
     ui.status(_("%d largefiles cached\n") % numcached)
 
-@command('debuglfput',
+@eh.command('debuglfput',
     [] + cmdutil.remoteopts,
     _('FILE'))
 def debuglfput(ui, repo, filepath, **kwargs):
--- a/hgext/largefiles/overrides.py	Sun Dec 23 21:54:56 2018 -0500
+++ b/hgext/largefiles/overrides.py	Sun Dec 23 17:26:25 2018 -0500
@@ -18,6 +18,7 @@
     archival,
     cmdutil,
     error,
+    exthelper,
     hg,
     logcmdutil,
     match as matchmod,
@@ -35,6 +36,8 @@
     storefactory,
 )
 
+eh = exthelper.exthelper()
+
 # -- Utility functions: commonly/repeatedly needed functionality ---------------
 
 def composelargefilematcher(match, manifest):
@@ -253,6 +256,11 @@
 
 # -- Wrappers: modify existing commands --------------------------------
 
+@eh.wrapcommand('add',
+    opts=[('', 'large', None, _('add as largefile')),
+          ('', 'normal', None, _('add as normal file')),
+          ('', 'lfsize', '', _('add all files above this size (in megabytes) '
+                               'as largefiles (default: 10)'))])
 def overrideadd(orig, ui, repo, *pats, **opts):
     if opts.get(r'normal') and opts.get(r'large'):
         raise error.Abort(_('--normal cannot be used with --large'))
@@ -286,6 +294,7 @@
     finally:
         repo._repo.lfstatus = False
 
+@eh.wrapcommand('status')
 def overridestatus(orig, ui, repo, *pats, **opts):
     try:
         repo.lfstatus = True
@@ -300,6 +309,7 @@
     finally:
         repo._repo.lfstatus = False
 
+@eh.wrapcommand('log')
 def overridelog(orig, ui, repo, *pats, **opts):
     def overridematchandpats(ctx, pats=(), opts=None, globbed=False,
             default='relpath', badfn=None):
@@ -406,6 +416,13 @@
         restorematchandpatsfn()
         setattr(logcmdutil, '_makenofollowfilematcher', oldmakefilematcher)
 
+@eh.wrapcommand('verify',
+    opts=[('', 'large', None,
+                _('verify that all largefiles in current revision exists')),
+          ('', 'lfa', None,
+                _('verify largefiles in all revisions, not just current')),
+          ('', 'lfc', None,
+                _('verify local largefile contents, not just existence'))])
 def overrideverify(orig, ui, repo, *pats, **opts):
     large = opts.pop(r'large', False)
     all = opts.pop(r'lfa', False)
@@ -416,6 +433,8 @@
         result = result or lfcommands.verifylfiles(ui, repo, all, contents)
     return result
 
+@eh.wrapcommand('debugstate',
+    opts=[('', 'large', None, _('display largefiles dirstate'))])
 def overridedebugstate(orig, ui, repo, *pats, **opts):
     large = opts.pop(r'large', False)
     if large:
@@ -799,6 +818,11 @@
 
 # after pulling changesets, we need to take some extra care to get
 # largefiles updated remotely
+@eh.wrapcommand('pull',
+    opts=[('', 'all-largefiles', None,
+                _('download all pulled versions of largefiles (DEPRECATED)')),
+          ('', 'lfrev', [],
+                _('download largefiles for these revisions'), _('REV'))])
 def overridepull(orig, ui, repo, source=None, **opts):
     revsprepull = len(repo)
     if not source:
@@ -822,6 +846,9 @@
         ui.status(_("%d largefiles cached\n") % numcached)
     return result
 
+@eh.wrapcommand('push',
+    opts=[('', 'lfrev', [],
+               _('upload largefiles for these revisions'), _('REV'))])
 def overridepush(orig, ui, repo, *args, **kwargs):
     """Override push command and store --lfrev parameters in opargs"""
     lfrevs = kwargs.pop(r'lfrev', None)
@@ -865,6 +892,9 @@
         raise error.Abort(_("pulled() only available in --lfrev"))
     return smartset.baseset([r for r in subset if r >= firstpulled])
 
+@eh.wrapcommand('clone',
+    opts=[('', 'all-largefiles', None,
+               _('download all versions of all largefiles'))])
 def overrideclone(orig, ui, source, dest=None, **opts):
     d = dest
     if d is None:
@@ -900,6 +930,7 @@
 
     return result
 
+@eh.wrapcommand('rebase', extension='rebase')
 def overriderebase(orig, ui, repo, **opts):
     if not util.safehasattr(repo, '_largefilesenabled'):
         return orig(ui, repo, **opts)
@@ -913,6 +944,7 @@
         repo._lfstatuswriters.pop()
         repo._lfcommithooks.pop()
 
+@eh.wrapcommand('archive')
 def overridearchivecmd(orig, ui, repo, dest, **opts):
     repo.unfiltered().lfstatus = True
 
@@ -1167,6 +1199,13 @@
                 showhashes(file)
             ui.status('\n')
 
+@eh.wrapcommand('outgoing',
+    opts=[('', 'large', None, _('display outgoing largefiles'))])
+def _outgoingcmd(orig, *args, **kwargs):
+    # Nothing to do here other than add the extra help option- the hook above
+    # processes it.
+    return orig(*args, **kwargs)
+
 def summaryremotehook(ui, repo, opts, changes):
     largeopt = opts.get('large', False)
     if changes is None:
@@ -1196,6 +1235,8 @@
             ui.status(_('largefiles: %d entities for %d files to upload\n')
                       % (len(lfhashes), len(toupload)))
 
+@eh.wrapcommand('summary',
+    opts=[('', 'large', None, _('display outgoing largefiles'))])
 def overridesummary(orig, ui, repo, *pats, **opts):
     try:
         repo.lfstatus = True
@@ -1242,6 +1283,7 @@
 
 # Calling purge with --all will cause the largefiles to be deleted.
 # Override repo.status to prevent this from happening.
+@eh.wrapcommand('purge', extension='purge')
 def overridepurge(orig, ui, repo, *dirs, **opts):
     # XXX Monkey patching a repoview will not work. The assigned attribute will
     # be set on the unfiltered repo, but we will only lookup attributes in the
@@ -1267,6 +1309,7 @@
     orig(ui, repo, *dirs, **opts)
     repo.status = oldstatus
 
+@eh.wrapcommand('rollback')
 def overriderollback(orig, ui, repo, **opts):
     with repo.wlock():
         before = repo.dirstate.parents()
@@ -1304,6 +1347,7 @@
         lfdirstate.write()
     return result
 
+@eh.wrapcommand('transplant', extension='transplant')
 def overridetransplant(orig, ui, repo, *revs, **opts):
     resuming = opts.get(r'continue')
     repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
@@ -1315,6 +1359,7 @@
         repo._lfcommithooks.pop()
     return result
 
+@eh.wrapcommand('cat')
 def overridecat(orig, ui, repo, file1, *pats, **opts):
     opts = pycompat.byteskwargs(opts)
     ctx = scmutil.revsingle(repo, opts.get('rev'))
--- a/hgext/largefiles/uisetup.py	Sun Dec 23 21:54:56 2018 -0500
+++ b/hgext/largefiles/uisetup.py	Sun Dec 23 17:26:25 2018 -0500
@@ -9,8 +9,6 @@
 '''setup for largefiles extension: uisetup'''
 from __future__ import absolute_import
 
-from mercurial.i18n import _
-
 from mercurial.hgweb import (
     webcommands,
 )
@@ -18,7 +16,6 @@
 from mercurial import (
     archival,
     cmdutil,
-    commands,
     copies,
     exchange,
     extensions,
@@ -43,15 +40,6 @@
     # Disable auto-status for some commands which assume that all
     # files in the result are under Mercurial's control
 
-    entry = extensions.wrapcommand(commands.table, 'add',
-                                   overrides.overrideadd)
-    addopt = [('', 'large', None, _('add as largefile')),
-              ('', 'normal', None, _('add as normal file')),
-              ('', 'lfsize', '', _('add all files above this size '
-                                   '(in megabytes) as largefiles '
-                                   '(default: 10)'))]
-    entry[1].extend(addopt)
-
     # The scmutil function is called both by the (trivial) addremove command,
     # and in the process of handling commit -A (issue3542)
     extensions.wrapfunction(scmutil, 'addremove', overrides.scmutiladdremove)
@@ -68,67 +56,17 @@
                             overrides.upgraderequirements)
 
     # Subrepos call status function
-    entry = extensions.wrapcommand(commands.table, 'status',
-                                   overrides.overridestatus)
     extensions.wrapfunction(subrepo.hgsubrepo, 'status',
                             overrides.overridestatusfn)
 
-    entry = extensions.wrapcommand(commands.table, 'log',
-                                   overrides.overridelog)
-    entry = extensions.wrapcommand(commands.table, 'rollback',
-                                   overrides.overriderollback)
-    entry = extensions.wrapcommand(commands.table, 'verify',
-                                   overrides.overrideverify)
-
-    verifyopt = [('', 'large', None,
-                  _('verify that all largefiles in current revision exists')),
-                 ('', 'lfa', None,
-                  _('verify largefiles in all revisions, not just current')),
-                 ('', 'lfc', None,
-                  _('verify local largefile contents, not just existence'))]
-    entry[1].extend(verifyopt)
-
-    entry = extensions.wrapcommand(commands.table, 'debugstate',
-                                   overrides.overridedebugstate)
-    debugstateopt = [('', 'large', None, _('display largefiles dirstate'))]
-    entry[1].extend(debugstateopt)
-
-    outgoing = lambda orgfunc, *arg, **kwargs: orgfunc(*arg, **kwargs)
-    entry = extensions.wrapcommand(commands.table, 'outgoing', outgoing)
-    outgoingopt = [('', 'large', None, _('display outgoing largefiles'))]
-    entry[1].extend(outgoingopt)
     cmdutil.outgoinghooks.add('largefiles', overrides.outgoinghook)
-    entry = extensions.wrapcommand(commands.table, 'summary',
-                                   overrides.overridesummary)
-    summaryopt = [('', 'large', None, _('display outgoing largefiles'))]
-    entry[1].extend(summaryopt)
     cmdutil.summaryremotehooks.add('largefiles', overrides.summaryremotehook)
 
-    entry = extensions.wrapcommand(commands.table, 'pull',
-                                   overrides.overridepull)
-    pullopt = [('', 'all-largefiles', None,
-                 _('download all pulled versions of largefiles (DEPRECATED)')),
-               ('', 'lfrev', [],
-                _('download largefiles for these revisions'), _('REV'))]
-    entry[1].extend(pullopt)
-
-    entry = extensions.wrapcommand(commands.table, 'push',
-                                   overrides.overridepush)
-    pushopt = [('', 'lfrev', [],
-                _('upload largefiles for these revisions'), _('REV'))]
-    entry[1].extend(pushopt)
     extensions.wrapfunction(exchange, 'pushoperation',
                             overrides.exchangepushoperation)
 
-    entry = extensions.wrapcommand(commands.table, 'clone',
-                                   overrides.overrideclone)
-    cloneopt = [('', 'all-largefiles', None,
-                 _('download all versions of all largefiles'))]
-    entry[1].extend(cloneopt)
     extensions.wrapfunction(hg, 'clone', overrides.hgclone)
 
-    entry = extensions.wrapcommand(commands.table, 'cat',
-                                   overrides.overridecat)
     extensions.wrapfunction(merge, '_checkunknownfile',
                             overrides.overridecheckunknownfile)
     extensions.wrapfunction(merge, 'calculateupdates',
@@ -145,8 +83,6 @@
 
     extensions.wrapfunction(cmdutil, 'revert', overrides.overriderevert)
 
-    extensions.wrapcommand(commands.table, 'archive',
-                           overrides.overridearchivecmd)
     extensions.wrapfunction(archival, 'archive', overrides.overridearchive)
     extensions.wrapfunction(subrepo.hgsubrepo, 'archive',
                             overrides.hgsubrepoarchive)
@@ -191,14 +127,6 @@
 
     # override some extensions' stuff as well
     for name, module in extensions.extensions():
-        if name == 'purge':
-            extensions.wrapcommand(getattr(module, 'cmdtable'), 'purge',
-                overrides.overridepurge)
         if name == 'rebase':
-            extensions.wrapcommand(getattr(module, 'cmdtable'), 'rebase',
-                overrides.overriderebase)
             extensions.wrapfunction(module, 'rebase',
                                     overrides.overriderebase)
-        if name == 'transplant':
-            extensions.wrapcommand(getattr(module, 'cmdtable'), 'transplant',
-                overrides.overridetransplant)