[PATCH 5 of 6] largefiles: port commands to exthelper
Matt Harbison
mharbison72 at gmail.com
Wed Dec 26 16:33:37 EST 2018
# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1545603985 18000
# Sun Dec 23 17:26:25 2018 -0500
# Node ID 32aa43e038570b844946896376b358cada94f972
# Parent a341e513e16c560082afaf06ce6041091f8d40f1
largefiles: port commands to exthelper
One subtle change here is that the purge, rebase and transplant extensions are
wrapped in extsetup() instead of uisetup().
diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py
+++ b/hgext/largefiles/__init__.py
@@ -129,6 +129,8 @@ from . import (
testedwith = 'ships-with-hg-core'
eh = exthelper.exthelper()
+eh.merge(lfcommands.eh)
+eh.merge(overrides.eh)
eh.configitem('largefiles', 'minsize',
default=configitems.dynamicdefault,
@@ -140,17 +142,20 @@ eh.configitem('largefiles', 'usercache',
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):
+ at eh.uisetup
+def _uisetup(ui):
localrepo.featuresetupfuncs.add(featuresetup)
hg.wirepeersetupfuncs.append(proto.wirereposetup)
uisetupmod.uisetup(ui)
-cmdtable = lfcommands.cmdtable
revsetpredicate = overrides.revsetpredicate
diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -20,6 +20,7 @@ from mercurial import (
cmdutil,
context,
error,
+ exthelper,
hg,
lock,
match as matchmod,
@@ -44,10 +45,9 @@ release = lock.release
# -- Commands ----------------------------------------------------------
-cmdtable = {}
-command = registrar.command(cmdtable)
+eh = exthelper.exthelper()
- at command('lfconvert',
+ at eh.command('lfconvert',
[('s', 'size', '',
_('minimum size (MB) for files to be converted as largefiles'), 'SIZE'),
('', 'to-normal', False,
@@ -560,7 +560,7 @@ def updatelfiles(ui, repo, filelist=None
statuswriter(_('%d largefiles updated, %d removed\n') % (updated,
removed))
- at command('lfpull',
+ at eh.command('lfpull',
[('r', 'rev', [], _('pull largefiles for these revisions'))
] + cmdutil.remoteopts,
_('-r REV... [-e CMD] [--remotecmd CMD] [SOURCE]'))
@@ -599,7 +599,7 @@ def lfpull(ui, repo, source="default", *
numcached += len(cached)
ui.status(_("%d largefiles cached\n") % numcached)
- at command('debuglfput',
+ at eh.command('debuglfput',
[] + cmdutil.remoteopts,
_('FILE'))
def debuglfput(ui, repo, filepath, **kwargs):
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -18,6 +18,7 @@ from mercurial import (
archival,
cmdutil,
error,
+ exthelper,
hg,
logcmdutil,
match as matchmod,
@@ -35,6 +36,8 @@ from . import (
storefactory,
)
+eh = exthelper.exthelper()
+
# -- Utility functions: commonly/repeatedly needed functionality ---------------
def composelargefilematcher(match, manifest):
@@ -253,6 +256,11 @@ def decodepath(orig, path):
# -- Wrappers: modify existing commands --------------------------------
+ at 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 @@ def overridestatusfn(orig, repo, rev2, *
finally:
repo._repo.lfstatus = False
+ at eh.wrapcommand('status')
def overridestatus(orig, ui, repo, *pats, **opts):
try:
repo.lfstatus = True
@@ -300,6 +309,7 @@ def overridedirty(orig, repo, ignoreupda
finally:
repo._repo.lfstatus = False
+ at 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 @@ def overridelog(orig, ui, repo, *pats, *
restorematchandpatsfn()
setattr(logcmdutil, '_makenofollowfilematcher', oldmakefilematcher)
+ at 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 @@ def overrideverify(orig, ui, repo, *pats
result = result or lfcommands.verifylfiles(ui, repo, all, contents)
return result
+ at 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 @@ def overriderevert(orig, ui, repo, ctx,
# after pulling changesets, we need to take some extra care to get
# largefiles updated remotely
+ at 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 @@ def overridepull(orig, ui, repo, source=
ui.status(_("%d largefiles cached\n") % numcached)
return result
+ at 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 @@ def pulledrevsetsymbol(repo, subset, x):
raise error.Abort(_("pulled() only available in --lfrev"))
return smartset.baseset([r for r in subset if r >= firstpulled])
+ at 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 @@ def hgclone(orig, ui, opts, *args, **kwa
return result
+ at eh.wrapcommand('rebase', 'rebase')
def overriderebase(orig, ui, repo, **opts):
if not util.safehasattr(repo, '_largefilesenabled'):
return orig(ui, repo, **opts)
@@ -913,6 +944,7 @@ def overriderebase(orig, ui, repo, **opt
repo._lfstatuswriters.pop()
repo._lfcommithooks.pop()
+ at eh.wrapcommand('archive')
def overridearchivecmd(orig, ui, repo, dest, **opts):
repo.unfiltered().lfstatus = True
@@ -1167,6 +1199,13 @@ def outgoinghook(ui, repo, other, opts,
showhashes(file)
ui.status('\n')
+ at 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 @@ def summaryremotehook(ui, repo, opts, ch
ui.status(_('largefiles: %d entities for %d files to upload\n')
% (len(lfhashes), len(toupload)))
+ at eh.wrapcommand('summary',
+ opts=[('', 'large', None, _('display outgoing largefiles'))])
def overridesummary(orig, ui, repo, *pats, **opts):
try:
repo.lfstatus = True
@@ -1242,6 +1283,7 @@ def scmutiladdremove(orig, repo, matcher
# Calling purge with --all will cause the largefiles to be deleted.
# Override repo.status to prevent this from happening.
+ at eh.wrapcommand('purge', '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 @@ def overridepurge(orig, ui, repo, *dirs,
orig(ui, repo, *dirs, **opts)
repo.status = oldstatus
+ at eh.wrapcommand('rollback')
def overriderollback(orig, ui, repo, **opts):
with repo.wlock():
before = repo.dirstate.parents()
@@ -1304,6 +1347,7 @@ def overriderollback(orig, ui, repo, **o
lfdirstate.write()
return result
+ at eh.wrapcommand('transplant', 'transplant')
def overridetransplant(orig, ui, repo, *revs, **opts):
resuming = opts.get(r'continue')
repo._lfcommithooks.append(lfutil.automatedcommithook(resuming))
@@ -1315,6 +1359,7 @@ def overridetransplant(orig, ui, repo, *
repo._lfcommithooks.pop()
return result
+ at eh.wrapcommand('cat')
def overridecat(orig, ui, repo, file1, *pats, **opts):
opts = pycompat.byteskwargs(opts)
ctx = scmutil.revsingle(repo, opts.get('rev'))
diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -18,7 +18,6 @@ from mercurial.hgweb import (
from mercurial import (
archival,
cmdutil,
- commands,
copies,
exchange,
extensions,
@@ -43,15 +42,6 @@ def uisetup(ui):
# 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 +58,17 @@ def uisetup(ui):
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 +85,6 @@ def uisetup(ui):
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 +129,6 @@ def uisetup(ui):
# 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)
More information about the Mercurial-devel
mailing list