Commit fc40eeac authored by Yuya Nishihara's avatar Yuya Nishihara
Browse files

commands: move templates of common command options to cmdutil (API)

The goal is to get rid of the debugcommands -> commands dependency.

Since globalopts is the property of the commands, it's kept in the commands
module.
parent 194b0f781132
......@@ -85,18 +85,20 @@ else:
# available, because commands.formatteropts has been available since
# 3.2 (or 7a7eed5176a4), even though formatting itself has been
# available since 2.2 (or ae5f92e154d3)
formatteropts = getattr(commands, "formatteropts", [])
formatteropts = getattr(cmdutil, "formatteropts",
getattr(commands, "formatteropts", []))
# for "historical portability":
# use locally defined option list, if debugrevlogopts isn't available,
# because commands.debugrevlogopts has been available since 3.7 (or
# 5606f7d0d063), even though cmdutil.openrevlog() has been available
# since 1.9 (or a79fea6b3e77).
revlogopts = getattr(commands, "debugrevlogopts", [
revlogopts = getattr(cmdutil, "debugrevlogopts",
getattr(commands, "debugrevlogopts", [
('c', 'changelog', False, ('open changelog')),
('m', 'manifest', False, ('open manifest')),
('', 'dir', False, ('open directory manifest')),
])
]))
cmdtable = {}
......
......@@ -19,11 +19,10 @@ from __future__ import absolute_import
from mercurial.i18n import _
from mercurial import (
cmdutil,
commands,
registrar,
)
templateopts = commands.templateopts
templateopts = cmdutil.templateopts
cmdtable = {}
command = registrar.command(cmdtable)
......
......@@ -17,7 +17,6 @@ import time
from mercurial.i18n import _
from mercurial import (
cmdutil,
commands,
encoding,
patch,
registrar,
......@@ -115,7 +114,7 @@ def countrate(ui, repo, amap, *pats, **opts):
('s', 'sort', False, _('sort by key (default: sort by count)')),
('', 'diffstat', False, _('display added/removed lines separately')),
('', 'aliases', '', _('file with email aliases'), _('FILE')),
] + commands.walkopts,
] + cmdutil.walkopts,
_("hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]"),
inferrepo=True)
def churn(ui, repo, *pats, **opts):
......
......@@ -74,7 +74,6 @@ from mercurial.node import (
from mercurial import (
archival,
cmdutil,
commands,
error,
filemerge,
pycompat,
......@@ -301,7 +300,7 @@ extdiffopts = [
('r', 'rev', [], _('revision'), _('REV')),
('c', 'change', '', _('change made by revision'), _('REV')),
('', 'patch', None, _('compare patches for two revisions'))
] + commands.walkopts + commands.subrepoopts
] + cmdutil.walkopts + cmdutil.subrepoopts
@command('extdiff',
[('p', 'program', '', _('comparison program to run'), _('CMD')),
......
......@@ -15,7 +15,6 @@ from mercurial.node import (
)
from mercurial import (
cmdutil,
commands,
error,
exchange,
hg,
......@@ -39,7 +38,7 @@ testedwith = 'ships-with-hg-core'
('e', 'edit', None, _('invoke editor on commit messages')),
('', 'force-editor', None, _('edit commit message (DEPRECATED)')),
('', 'switch-parent', None, _('switch parents when merging')),
] + commands.commitopts + commands.commitopts2 + commands.remoteopts,
] + cmdutil.commitopts + cmdutil.commitopts2 + cmdutil.remoteopts,
_('hg fetch [SOURCE]'))
def fetch(ui, repo, source='default', **opts):
'''pull changes from a remote repository, merge new changes if needed.
......
......@@ -14,7 +14,6 @@ import tempfile
from mercurial.i18n import _
from mercurial import (
cmdutil,
commands,
error,
match,
node as hgnode,
......@@ -222,7 +221,7 @@ def keystr(ui, key):
('m', 'message', '',
_('use text as commit message'), _('TEXT')),
('e', 'edit', False, _('invoke editor on commit messages')),
] + commands.commitopts2,
] + cmdutil.commitopts2,
_('hg sign [OPTION]... [REV]...'))
def sign(ui, repo, *revs, **opts):
"""add a signature for the current or given revision
......
......@@ -19,6 +19,7 @@ from __future__ import absolute_import
from mercurial.i18n import _
from mercurial import (
cmdutil,
commands,
registrar,
)
......@@ -51,7 +52,7 @@ testedwith = 'ships-with-hg-core'
_('show changesets within the given named branch'), _('BRANCH')),
('P', 'prune', [],
_('do not display revision or any of its ancestors'), _('REV')),
] + commands.logopts + commands.walkopts,
] + cmdutil.logopts + cmdutil.walkopts,
_('[OPTION]... [FILE]'),
inferrepo=True)
def glog(ui, repo, *pats, **opts):
......
......@@ -23,7 +23,6 @@ from mercurial.i18n import _
from mercurial import (
bookmarks,
cmdutil,
commands,
dispatch,
error,
extensions,
......@@ -421,7 +420,7 @@ _ignoreopts = ('no-merges', 'graph')
'journal', [
('', 'all', None, 'show history for all names'),
('c', 'commits', None, 'show commit metadata'),
] + [opt for opt in commands.logopts if opt[1] not in _ignoreopts],
] + [opt for opt in cmdutil.logopts if opt[1] not in _ignoreopts],
'[OPTION]... [BOOKMARKNAME]')
def journal(ui, repo, *args, **opts):
"""show the previous position of bookmarks and the working copy
......
......@@ -94,7 +94,6 @@ from mercurial.hgweb import webcommands
from mercurial import (
cmdutil,
commands,
context,
dispatch,
error,
......@@ -481,7 +480,7 @@ def demo(ui, repo, *args, **opts):
repo.wvfs.rmtree(repo.root)
@command('kwexpand',
commands.walkopts,
cmdutil.walkopts,
_('hg kwexpand [OPTION]... [FILE]...'),
inferrepo=True)
def expand(ui, repo, *pats, **opts):
......@@ -498,7 +497,7 @@ def expand(ui, repo, *pats, **opts):
[('A', 'all', None, _('show keyword status flags of all files')),
('i', 'ignore', None, _('show files excluded from expansion')),
('u', 'unknown', None, _('only show unknown (not tracked) files')),
] + commands.walkopts,
] + cmdutil.walkopts,
_('hg kwfiles [OPTION]... [FILE]...'),
inferrepo=True)
def files(ui, repo, *pats, **opts):
......@@ -557,7 +556,7 @@ def files(ui, repo, *pats, **opts):
fm.end()
@command('kwshrink',
commands.walkopts,
cmdutil.walkopts,
_('hg kwshrink [OPTION]... [FILE]...'),
inferrepo=True)
def shrink(ui, repo, *pats, **opts):
......
......@@ -18,7 +18,6 @@ from mercurial.i18n import _
from mercurial import (
cmdutil,
commands,
context,
error,
hg,
......@@ -542,7 +541,7 @@ def updatelfiles(ui, repo, filelist=None, printmessage=None,
@command('lfpull',
[('r', 'rev', [], _('pull largefiles for these revisions'))
] + commands.remoteopts,
] + cmdutil.remoteopts,
_('-r REV... [-e CMD] [--remotecmd CMD] [SOURCE]'))
def lfpull(ui, repo, source="default", **opts):
"""pull largefiles for the specified revisions from the specified source
......
......@@ -2407,7 +2407,7 @@ def init(ui, repo, **opts):
_('use uncompressed transfer (fast over LAN)')),
('p', 'patches', '',
_('location of source patch repository'), _('REPO')),
] + commands.remoteopts,
] + cmdutil.remoteopts,
_('hg qclone [OPTION]... SOURCE [DEST]'),
norepo=True)
def clone(ui, source, dest=None, **opts):
......@@ -2575,7 +2575,7 @@ def setupheaderopts(ui, opts):
('D', 'currentdate', None, _('add "Date: <current date>" to patch')),
('d', 'date', '',
_('add "Date: <DATE>" to patch'), _('DATE'))
] + commands.walkopts + commands.commitopts,
] + cmdutil.walkopts + cmdutil.commitopts,
_('hg qnew [-e] [-m TEXT] [-l FILE] PATCH [FILE]...'),
inferrepo=True)
def new(ui, repo, patch, *args, **opts):
......@@ -2624,7 +2624,7 @@ def new(ui, repo, patch, *args, **opts):
_('add/update date field in patch with current date')),
('d', 'date', '',
_('add/update date field in patch with given date'), _('DATE'))
] + commands.walkopts + commands.commitopts,
] + cmdutil.walkopts + cmdutil.commitopts,
_('hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] [FILE]...'),
inferrepo=True)
def refresh(ui, repo, *pats, **opts):
......@@ -2657,7 +2657,7 @@ def refresh(ui, repo, *pats, **opts):
return ret
@command("^qdiff",
commands.diffopts + commands.diffopts2 + commands.walkopts,
cmdutil.diffopts + cmdutil.diffopts2 + cmdutil.walkopts,
_('hg qdiff [OPTION]... [FILE]...'),
inferrepo=True)
def diff(ui, repo, *pats, **opts):
......@@ -2682,7 +2682,7 @@ def diff(ui, repo, *pats, **opts):
@command('qfold',
[('e', 'edit', None, _('invoke editor on commit messages')),
('k', 'keep', None, _('keep folded patch files')),
] + commands.commitopts,
] + cmdutil.commitopts,
_('hg qfold [-e] [-k] [-m TEXT] [-l FILE] PATCH...'))
def fold(ui, repo, *files, **opts):
"""fold the named patches into the current patch
......@@ -3044,7 +3044,7 @@ def restore(ui, repo, rev, **opts):
('n', 'name', '',
_('copy directory name'), _('NAME')),
('e', 'empty', None, _('clear queue status file')),
('f', 'force', None, _('force copy'))] + commands.commitopts,
('f', 'force', None, _('force copy'))] + cmdutil.commitopts,
_('hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'))
def save(ui, repo, **opts):
"""save current queue state (DEPRECATED)
......
......@@ -450,7 +450,7 @@ emailopts = [
('', 'base', [], _('a base changeset to specify instead of a destination '
'(with -b/--bundle)'), _('REV')),
('', 'intro', None, _('send an introduction email for a single patch')),
] + emailopts + commands.remoteopts,
] + emailopts + cmdutil.remoteopts,
_('hg email [OPTION]... [DEST]...'))
def email(ui, repo, *revs, **opts):
'''send changesets by email
......
......@@ -29,7 +29,7 @@ import os
from mercurial.i18n import _
from mercurial import (
commands,
cmdutil,
error,
registrar,
scmutil,
......@@ -52,7 +52,7 @@ testedwith = 'ships-with-hg-core'
('p', 'print', None, _('print filenames instead of deleting them')),
('0', 'print0', None, _('end filenames with NUL, for use with xargs'
' (implies -p/--print)')),
] + commands.walkopts,
] + cmdutil.walkopts,
_('hg purge [OPTION]... [DIR]...'))
def purge(ui, repo, *dirs, **opts):
'''removes files not tracked by Mercurial
......
......@@ -52,7 +52,7 @@ from mercurial import (
)
release = lock.release
templateopts = commands.templateopts
templateopts = cmdutil.templateopts
# The following constants are used throughout the rebase module. The ordering of
# their values must be maintained.
......
......@@ -33,7 +33,7 @@ testedwith = 'ships-with-hg-core'
@command("record",
# same options as commit + white space diff options
[c for c in commands.table['^commit|ci'][1][:]
if c[1] != "interactive"] + commands.diffwsopts,
if c[1] != "interactive"] + cmdutil.diffwsopts,
_('hg record [OPTION]... [FILE]...'))
def record(ui, repo, *pats, **opts):
'''interactively select changes to commit
......@@ -136,7 +136,7 @@ def uisetup(ui):
(qrecord,
# same options as qnew, but copy them so we don't get
# -i/--interactive for qrecord and add white space diff options
mq.cmdtable['^qnew'][1][:] + commands.diffwsopts,
mq.cmdtable['^qnew'][1][:] + cmdutil.diffwsopts,
_('hg qrecord [OPTION]... PATCH [FILE]...'))
_wrapcmd('qnew', mq.cmdtable, qnew, _("interactively record a new patch"))
......
......@@ -33,7 +33,6 @@ from mercurial import (
bundlerepo,
changegroup,
cmdutil,
commands,
error,
exchange,
hg,
......@@ -971,7 +970,7 @@ def _dounshelve(ui, repo, *shelved, **opts):
('i', 'interactive', None,
_('interactive mode, only works while creating a shelve')),
('', 'stat', None,
_('output diffstat-style summary of changes'))] + commands.walkopts,
_('output diffstat-style summary of changes'))] + cmdutil.walkopts,
_('hg shelve [OPTION]... [FILE]...'))
def shelvecmd(ui, repo, *pats, **opts):
'''save and set aside changes from the working directory
......
......@@ -58,7 +58,7 @@ class showcmdfunc(registrar._funcregistrarbase):
showview = showcmdfunc()
@command('show', [
# TODO: Switch this template flag to use commands.formatteropts if
# TODO: Switch this template flag to use cmdutil.formatteropts if
# 'hg show' becomes stable before --template/-T is stable. For now,
# we are putting it here without the '(EXPERIMENTAL)' flag because it
# is an important part of the 'hg show' user experience and the entire
......
......@@ -51,6 +51,113 @@ from . import (
)
stringio = util.stringio
# templates of common command options
dryrunopts = [
('n', 'dry-run', None,
_('do not perform actions, just print output')),
]
remoteopts = [
('e', 'ssh', '',
_('specify ssh command to use'), _('CMD')),
('', 'remotecmd', '',
_('specify hg command to run on the remote side'), _('CMD')),
('', 'insecure', None,
_('do not verify server certificate (ignoring web.cacerts config)')),
]
walkopts = [
('I', 'include', [],
_('include names matching the given patterns'), _('PATTERN')),
('X', 'exclude', [],
_('exclude names matching the given patterns'), _('PATTERN')),
]
commitopts = [
('m', 'message', '',
_('use text as commit message'), _('TEXT')),
('l', 'logfile', '',
_('read commit message from file'), _('FILE')),
]
commitopts2 = [
('d', 'date', '',
_('record the specified date as commit date'), _('DATE')),
('u', 'user', '',
_('record the specified user as committer'), _('USER')),
]
# hidden for now
formatteropts = [
('T', 'template', '',
_('display with template (EXPERIMENTAL)'), _('TEMPLATE')),
]
templateopts = [
('', 'style', '',
_('display using template map file (DEPRECATED)'), _('STYLE')),
('T', 'template', '',
_('display with template'), _('TEMPLATE')),
]
logopts = [
('p', 'patch', None, _('show patch')),
('g', 'git', None, _('use git extended diff format')),
('l', 'limit', '',
_('limit number of changes displayed'), _('NUM')),
('M', 'no-merges', None, _('do not show merges')),
('', 'stat', None, _('output diffstat-style summary of changes')),
('G', 'graph', None, _("show the revision DAG")),
] + templateopts
diffopts = [
('a', 'text', None, _('treat all files as text')),
('g', 'git', None, _('use git extended diff format')),
('', 'binary', None, _('generate binary diffs in git mode (default)')),
('', 'nodates', None, _('omit dates from diff headers'))
]
diffwsopts = [
('w', 'ignore-all-space', None,
_('ignore white space when comparing lines')),
('b', 'ignore-space-change', None,
_('ignore changes in the amount of white space')),
('B', 'ignore-blank-lines', None,
_('ignore changes whose lines are all blank')),
]
diffopts2 = [
('', 'noprefix', None, _('omit a/ and b/ prefixes from filenames')),
('p', 'show-function', None, _('show which function each change is in')),
('', 'reverse', None, _('produce a diff that undoes the changes')),
] + diffwsopts + [
('U', 'unified', '',
_('number of lines of context to show'), _('NUM')),
('', 'stat', None, _('output diffstat-style summary of changes')),
('', 'root', '', _('produce diffs relative to subdirectory'), _('DIR')),
]
mergetoolopts = [
('t', 'tool', '', _('specify merge tool')),
]
similarityopts = [
('s', 'similarity', '',
_('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY'))
]
subrepoopts = [
('S', 'subrepos', None,
_('recurse into subrepositories'))
]
debugrevlogopts = [
('c', 'changelog', False, _('open changelog')),
('m', 'manifest', False, _('open manifest')),
('', 'dir', '', _('open directory manifest')),
]
# special string such that everything below this line will be ingored in the
# editor text
_linebelow = "^HG: ------------------------ >8 ------------------------$"
......
......@@ -104,108 +104,21 @@ globalopts = [
_("when to paginate (boolean, always, auto, or never)"), _('TYPE')),
]
dryrunopts = [('n', 'dry-run', None,
_('do not perform actions, just print output'))]
remoteopts = [
('e', 'ssh', '',
_('specify ssh command to use'), _('CMD')),
('', 'remotecmd', '',
_('specify hg command to run on the remote side'), _('CMD')),
('', 'insecure', None,
_('do not verify server certificate (ignoring web.cacerts config)')),
]
walkopts = [
('I', 'include', [],
_('include names matching the given patterns'), _('PATTERN')),
('X', 'exclude', [],
_('exclude names matching the given patterns'), _('PATTERN')),
]
commitopts = [
('m', 'message', '',
_('use text as commit message'), _('TEXT')),
('l', 'logfile', '',
_('read commit message from file'), _('FILE')),
]
commitopts2 = [
('d', 'date', '',
_('record the specified date as commit date'), _('DATE')),
('u', 'user', '',
_('record the specified user as committer'), _('USER')),
]
# hidden for now
formatteropts = [
('T', 'template', '',
_('display with template (EXPERIMENTAL)'), _('TEMPLATE')),
]
templateopts = [
('', 'style', '',
_('display using template map file (DEPRECATED)'), _('STYLE')),
('T', 'template', '',
_('display with template'), _('TEMPLATE')),
]
logopts = [
('p', 'patch', None, _('show patch')),
('g', 'git', None, _('use git extended diff format')),
('l', 'limit', '',
_('limit number of changes displayed'), _('NUM')),
('M', 'no-merges', None, _('do not show merges')),
('', 'stat', None, _('output diffstat-style summary of changes')),
('G', 'graph', None, _("show the revision DAG")),
] + templateopts
diffopts = [
('a', 'text', None, _('treat all files as text')),
('g', 'git', None, _('use git extended diff format')),
('', 'binary', None, _('generate binary diffs in git mode (default)')),
('', 'nodates', None, _('omit dates from diff headers'))
]
diffwsopts = [
('w', 'ignore-all-space', None,
_('ignore white space when comparing lines')),
('b', 'ignore-space-change', None,
_('ignore changes in the amount of white space')),
('B', 'ignore-blank-lines', None,
_('ignore changes whose lines are all blank')),
]
diffopts2 = [
('', 'noprefix', None, _('omit a/ and b/ prefixes from filenames')),
('p', 'show-function', None, _('show which function each change is in')),
('', 'reverse', None, _('produce a diff that undoes the changes')),
] + diffwsopts + [
('U', 'unified', '',
_('number of lines of context to show'), _('NUM')),
('', 'stat', None, _('output diffstat-style summary of changes')),
('', 'root', '', _('produce diffs relative to subdirectory'), _('DIR')),
]
mergetoolopts = [
('t', 'tool', '', _('specify merge tool')),
]
similarityopts = [
('s', 'similarity', '',
_('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY'))
]
subrepoopts = [
('S', 'subrepos', None,
_('recurse into subrepositories'))
]
debugrevlogopts = [
('c', 'changelog', False, _('open changelog')),
('m', 'manifest', False, _('open manifest')),
('', 'dir', '', _('open directory manifest')),
]
dryrunopts = cmdutil.dryrunopts
remoteopts = cmdutil.remoteopts
walkopts = cmdutil.walkopts
commitopts = cmdutil.commitopts
commitopts2 = cmdutil.commitopts2
formatteropts = cmdutil.formatteropts
templateopts = cmdutil.templateopts
logopts = cmdutil.logopts
diffopts = cmdutil.diffopts
diffwsopts = cmdutil.diffwsopts
diffopts2 = cmdutil.diffopts2
mergetoolopts = cmdutil.mergetoolopts
similarityopts = cmdutil.similarityopts
subrepoopts = cmdutil.subrepoopts
debugrevlogopts = cmdutil.debugrevlogopts
# Commands start here, listed alphabetically
......
......@@ -501,7 +501,7 @@ def debugdag(ui, repo, file_=None, *revs, **opts):
ui.write(line)
ui.write("\n")
@command('debugdata', commands.debugrevlogopts, _('-c|-m|FILE REV'))
@command('debugdata', cmdutil.debugrevlogopts, _('-c|-m|FILE REV'))
def debugdata(ui, repo, file_, rev=None, **opts):
"""dump the contents of a data file revision"""
if opts.get('changelog') or opts.get('manifest') or opts.get('dir'):
......@@ -533,7 +533,7 @@ def debugdate(ui, date, range=None, **opts):
ui.write(("match: %s\n") % m(d[0]))
@command('debugdeltachain',
commands.debugrevlogopts + commands.formatteropts,
cmdutil.debugrevlogopts + cmdutil.formatteropts,
_('-c|-m|FILE'),
optionalrepo=True)
def debugdeltachain(ui, repo, file_=None, **opts):
......@@ -668,7 +668,7 @@ def debugstate(ui, repo, **opts):
[('', 'old', None, _('use old-style discovery')),
('', 'nonheads', None,
_('use old-style discovery with non-heads included')),
] + commands.remoteopts,
] + cmdutil.remoteopts,
_('[-l REV] [-r REV] [-b BRANCH]... [OTHER]'))
def debugdiscovery(ui, repo, remoteurl="default", **opts):
"""runs the changeset discovery protocol in isolation"""
......@@ -730,7 +730,7 @@ def debugdiscovery(ui, repo, remoteurl="default", **opts):
localrevs = opts.get('local_head')
doit(localrevs, remoterevs)
@command('debugextensions', commands.formatteropts, [], norepo=True)
@command('debugextensions', cmdutil.formatteropts, [], norepo=True)
def debugextensions(ui, **opts):
'''show information about active extensions'''
exts = extensions.extensions(ui)
......@@ -882,7 +882,7 @@ def debugignore(ui, repo, *files, **opts):
else:
ui.write(_("%s is not ignored\n") % f)
@command('debugindex', commands</