Patchwork [23,of,35] commands: define optionalrepo in command decorator

login
register
mail settings
Submitter Gregory Szorc
Date May 5, 2014, 5:51 a.m.
Message ID <1ae447c6135b80ab4663.1399269088@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4614/
State Accepted
Commit 5403245edb3a19f148900417643e495393e21833
Headers show

Comments

Gregory Szorc - May 5, 2014, 5:51 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1399266965 25200
#      Sun May 04 22:16:05 2014 -0700
# Branch stable
# Node ID 1ae447c6135b80ab466304fdf4e59006e2145bb9
# Parent  3adff8751da53b4975b5229ba1a4de24fd843caa
commands: define optionalrepo in command decorator

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -24,18 +24,20 @@  import phases, obsolete, exchange
 
 table = {}
 
 command = cmdutil.command(table)
 
 # Space delimited list of commands that don't require local repositories.
 # This should be populated by passing norepo=True into the @command decorator.
 norepo = ''
-optionalrepo = ("identify paths serve config showconfig debugancestor debugdag"
-                " debugdata debugindex debugindexdot debugrevlog")
+# Space delimited list of commands that optionally require local repositories.
+# This should be populated by passing optionalrepo=True into the @command
+# decorator.
+optionalrepo = ''
 inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
              " remove resolve status debugwalk")
 # common command options
 
 globalopts = [
     ('R', 'repository', '',
      _('repository root directory or name of overlay bundle file'),
      _('REPO')),
@@ -1450,17 +1452,18 @@  def commit(ui, repo, *pats, **opts):
 
     cmdutil.commitstatus(repo, node, branch, bheads, opts)
 
 @command('config|showconfig|debugconfig',
     [('u', 'untrusted', None, _('show untrusted configuration options')),
      ('e', 'edit', None, _('edit user config')),
      ('l', 'local', None, _('edit repository config')),
      ('g', 'global', None, _('edit global config'))],
-      _('[-u] [NAME]...'))
+    _('[-u] [NAME]...'),
+    optionalrepo=True)
 def config(ui, repo, *values, **opts):
     """show combined config settings from all hgrc files
 
     With no arguments, print names and values of all config items.
 
     With one argument of the form section.name, print just the value
     of that config item.
 
@@ -1569,17 +1572,17 @@  def copy(ui, repo, *pats, **opts):
     Returns 0 on success, 1 if errors are encountered.
     """
     wlock = repo.wlock(False)
     try:
         return cmdutil.copy(ui, repo, pats, opts)
     finally:
         wlock.release()
 
-@command('debugancestor', [], _('[INDEX] REV1 REV2'))
+@command('debugancestor', [], _('[INDEX] REV1 REV2'), optionalrepo=True)
 def debugancestor(ui, repo, *args):
     """find the ancestor revision of two revisions in a given index"""
     if len(args) == 3:
         index, rev1, rev2 = args
         r = revlog.revlog(scmutil.opener(os.getcwd(), audit=False), index)
         lookup = r.lookup
     elif len(args) == 2:
         if not repo:
@@ -1861,17 +1864,18 @@  def debugcomplete(ui, cmd='', **opts):
         cmdlist = [' '.join(c[0]) for c in cmdlist.values()]
     ui.write("%s\n" % "\n".join(sorted(cmdlist)))
 
 @command('debugdag',
     [('t', 'tags', None, _('use tags as labels')),
     ('b', 'branches', None, _('annotate with branch names')),
     ('', 'dots', None, _('use dots for runs')),
     ('s', 'spaces', None, _('separate elements by spaces'))],
-    _('[OPTION]... [FILE [REV]...]'))
+    _('[OPTION]... [FILE [REV]...]'),
+    optionalrepo=True)
 def debugdag(ui, repo, file_=None, *revs, **opts):
     """format the changelog or an index DAG as a concise textual description
 
     If you pass a revlog index, the revlog's DAG is emitted. If you list
     revision numbers, they get labeled in the output as rN.
 
     Otherwise, the changelog DAG of the current repo is emitted.
     """
@@ -1936,17 +1940,17 @@  def debugdata(ui, repo, file_, rev=None,
     try:
         ui.write(r.revision(r.lookup(rev)))
     except KeyError:
         raise util.Abort(_('invalid revision identifier %s') % rev)
 
 @command('debugdate',
     [('e', 'extended', None, _('try extended date formats'))],
     _('[-e] DATE [RANGE]'),
-    norepo=True)
+    norepo=True, optionalrepo=True)
 def debugdate(ui, date, range=None, **opts):
     """parse and display a date"""
     if opts["extended"]:
         d = util.parsedate(date, util.extendeddateformats)
     else:
         d = util.parsedate(date)
     ui.write(("internal: %s %s\n") % d)
     ui.write(("standard: %s\n") % util.datestr(d))
@@ -2088,17 +2092,18 @@  def debugignore(ui, repo, *values, **opt
         ui.write("%s\n" % includepat)
     else:
         raise util.Abort(_("no ignore patterns found"))
 
 @command('debugindex',
     [('c', 'changelog', False, _('open changelog')),
      ('m', 'manifest', False, _('open manifest')),
      ('f', 'format', 0, _('revlog format'), _('FORMAT'))],
-    _('[-f FORMAT] -c|-m|FILE'))
+    _('[-f FORMAT] -c|-m|FILE'),
+    optionalrepo=True)
 def debugindex(ui, repo, file_=None, **opts):
     """dump the contents of an index file"""
     r = cmdutil.openrevlog(repo, 'debugindex', file_, opts)
     format = opts.get('format', 0)
     if format not in (0, 1):
         raise util.Abort(_("unknown format %d") % format)
 
     generaldelta = r.version & revlog.REVLOGGENERALDELTA
@@ -2130,17 +2135,17 @@  def debugindex(ui, repo, file_=None, **o
                     i, r.start(i), r.length(i), base, r.linkrev(i),
                     short(node), short(pp[0]), short(pp[1])))
         elif format == 1:
             pr = r.parentrevs(i)
             ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % (
                     i, r.flags(i), r.start(i), r.length(i), r.rawsize(i),
                     base, r.linkrev(i), pr[0], pr[1], short(node)))
 
-@command('debugindexdot', [], _('FILE'))
+@command('debugindexdot', [], _('FILE'), optionalrepo=True)
 def debugindexdot(ui, repo, file_):
     """dump an index DAG as a graphviz dot file"""
     r = None
     if repo:
         filelog = repo.file(file_)
         if len(filelog):
             r = filelog
     if not r:
@@ -2469,17 +2474,18 @@  def debugrename(ui, repo, file1, *pats, 
             ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
         else:
             ui.write(_("%s not renamed\n") % rel)
 
 @command('debugrevlog',
     [('c', 'changelog', False, _('open changelog')),
      ('m', 'manifest', False, _('open manifest')),
      ('d', 'dump', False, _('dump index data'))],
-     _('-c|-m|FILE'))
+    _('-c|-m|FILE'),
+    optionalrepo=True)
 def debugrevlog(ui, repo, file_=None, **opts):
     """show data and statistics about a revlog"""
     r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts)
 
     if opts.get("dump"):
         numrevs = len(r)
         ui.write("# rev p1rev p2rev start   end deltastart base   p1   p2"
                  " rawsize totalsize compression heads\n")
@@ -3562,17 +3568,18 @@  def help_(ui, name=None, **opts):
     [('r', 'rev', '',
      _('identify the specified revision'), _('REV')),
     ('n', 'num', None, _('show local revision number')),
     ('i', 'id', None, _('show global revision id')),
     ('b', 'branch', None, _('show branch')),
     ('t', 'tags', None, _('show tags')),
     ('B', 'bookmarks', None, _('show bookmarks')),
     ] + remoteopts,
-    _('[-nibtB] [-r REV] [SOURCE]'))
+    _('[-nibtB] [-r REV] [SOURCE]'),
+    optionalrepo=True)
 def identify(ui, repo, source=None, rev=None,
              num=None, id=None, branch=None, tags=None, bookmarks=None, **opts):
     """identify the working copy or specified revision
 
     Print a summary identifying the repository state at REV using one or
     two parent hash identifiers, followed by a "+" if the working
     directory has uncommitted changes, the branch name (if not default),
     a list of tags, and a list of bookmarks.
@@ -4405,17 +4412,17 @@  def parents(ui, repo, file_=None, **opts
         p = [cp.node() for cp in ctx.parents()]
 
     displayer = cmdutil.show_changeset(ui, repo, opts)
     for n in p:
         if n != nullid:
             displayer.show(repo[n])
     displayer.close()
 
-@command('paths', [], _('[NAME]'))
+@command('paths', [], _('[NAME]'), optionalrepo=True)
 def paths(ui, repo, search=None):
     """show aliases for remote repositories
 
     Show definition of symbolic path name NAME. If no name is given,
     show definition of all available names.
 
     Option -q/--quiet suppresses all output when searching for NAME
     and shows only the path names when listing all definitions.
@@ -5132,17 +5139,18 @@  def root(ui, repo):
      _('FILE')),
     ('', 'pid-file', '', _('name of file to write process ID to'), _('FILE')),
     ('', 'stdio', None, _('for remote clients')),
     ('', 'cmdserver', '', _('for remote clients'), _('MODE')),
     ('t', 'templates', '', _('web templates to use'), _('TEMPLATE')),
     ('', 'style', '', _('template style to use'), _('STYLE')),
     ('6', 'ipv6', None, _('use IPv6 in addition to IPv4')),
     ('', 'certificate', '', _('SSL certificate file'), _('FILE'))],
-    _('[OPTION]...'))
+    _('[OPTION]...'),
+    optionalrepo=True)
 def serve(ui, repo, **opts):
     """start stand-alone webserver
 
     Start a local HTTP repository browser and pull server. You can use
     this for ad-hoc sharing and browsing of repositories. It is
     recommended to use a real web server to serve a repository for
     longer periods of time.