Patchwork [26,of,35] commands: define inferrepo in command decorator

mail settings
Submitter Gregory Szorc
Date May 5, 2014, 5:51 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/4617/
State Accepted
Commit f6a6d07b66b30d7a75aef0f5bfdc4d1179731c97
Headers show


Gregory Szorc - May 5, 2014, 5:51 a.m.
# HG changeset patch
# User Gregory Szorc <>
# Date 1399267379 25200
#      Sun May 04 22:22:59 2014 -0700
# Branch stable
# Node ID 0346a21b64c1354b4058ae1ee408a5cc513de670
# Parent  18c5c64d220340f5396490b6d8dcbe7a6b3ac598
commands: define inferrepo in command decorator


diff --git a/mercurial/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -28,18 +28,21 @@  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 = ''
 # 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")
+# Space delimited list of commands that will examine arguments looking for
+# a repository. This should be populated by passing inferrepo=True into the
+# @command decorator.
+inferrepo = ''
 # common command options
 globalopts = [
     ('R', 'repository', '',
      _('repository root directory or name of overlay bundle file'),
     ('', 'cwd', '',
      _('change working directory'), _('DIR')),
@@ -151,17 +154,18 @@  subrepoopts = [
     ('S', 'subrepos', None,
      _('recurse into subrepositories'))
 # Commands start here, listed alphabetically
     walkopts + subrepoopts + dryrunopts,
-    _('[OPTION]... [FILE]...'))
+    _('[OPTION]... [FILE]...'),
+    inferrepo=True)
 def add(ui, repo, *pats, **opts):
     """add the specified files on the next commit
     Schedule files to be version controlled and added to the
     The files will be added to the repository at the next commit. To
     undo an add before that, see :hg:`forget`.
@@ -187,17 +191,18 @@  def add(ui, repo, *pats, **opts):
     m = scmutil.match(repo[None], pats, opts)
     rejected = cmdutil.add(ui, repo, m, opts.get('dry_run'),
                            opts.get('subrepos'), prefix="", explicitonly=False)
     return rejected and 1 or 0
     similarityopts + walkopts + dryrunopts,
-    _('[OPTION]... [FILE]...'))
+    _('[OPTION]... [FILE]...'),
+    inferrepo=True)
 def addremove(ui, repo, *pats, **opts):
     """add all new files, delete all missing files
     Add all new files and remove all missing files from the
     New files are ignored if they match any of the patterns in
     ``.hgignore``. As with add, these changes take effect at the next
@@ -231,17 +236,18 @@  def addremove(ui, repo, *pats, **opts):
     ('a', 'text', None, _('treat all files as text')),
     ('u', 'user', None, _('list the author (long with -v)')),
     ('f', 'file', None, _('list the filename')),
     ('d', 'date', None, _('list the date (short with -q)')),
     ('n', 'number', None, _('list the revision number (default)')),
     ('c', 'changeset', None, _('list the changeset')),
     ('l', 'line-number', None, _('show line number at the first appearance'))
     ] + diffwsopts + walkopts,
-    _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'))
+    _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'),
+    inferrepo=True)
 def annotate(ui, repo, *pats, **opts):
     """show changeset information by line for each file
     List changes in files, showing the revision id responsible for
     each line
     This command is useful for discovering when a change was made and
     by whom.
@@ -1158,17 +1164,18 @@  def bundle(ui, repo, fname, dest=None, *
     changegroup.writebundle(cg, fname, bundletype)
     [('o', 'output', '',
      _('print output to file with formatted name'), _('FORMAT')),
     ('r', 'rev', '', _('print the given revision'), _('REV')),
     ('', 'decode', None, _('apply any matching decode filter')),
     ] + walkopts,
-    _('[OPTION]... FILE...'))
+    _('[OPTION]... FILE...'),
+    inferrepo=True)
 def cat(ui, repo, file1, *pats, **opts):
     """output the current or given revision of files
     Print the specified files as they were at the given revision. If
     no revision is given, the parent of the working directory is used.
     Output may be to a file, in which case the name of the file is
     given using a format string. The formatting rules as follows:
@@ -1314,17 +1321,18 @@  def clone(ui, source, dest=None, **opts)
      _('mark new/missing files as added/removed before committing')),
     ('', 'close-branch', None,
      _('mark a branch as closed, hiding it from the branch list')),
     ('', 'amend', None, _('amend the parent of the working dir')),
     ('s', 'secret', None, _('use the secret phase for committing')),
     ('e', 'edit', None,
      _('further edit commit message already specified')),
     ] + walkopts + commitopts + commitopts2 + subrepoopts,
-    _('[OPTION]... [FILE]...'))
+    _('[OPTION]... [FILE]...'),
+    inferrepo=True)
 def commit(ui, repo, *pats, **opts):
     """commit the specified files or all outstanding changes
     Commit changes to the given files into the repository. Unlike a
     centralized SCM, this operation is a local operation. See
     :hg:`push` for a way to actively distribute your changes.
     If a list of files is omitted, all changes reported by :hg:`status`
@@ -2782,17 +2790,17 @@  def debugsuccessorssets(ui, repo, *revs)
             if succsset:
                 ui.write('    ')
                 for node in succsset[1:]:
                     ui.write(' ')
-@command('debugwalk', walkopts, _('[OPTION]... [FILE]...'))
+@command('debugwalk', walkopts, _('[OPTION]... [FILE]...'), inferrepo=True)
 def debugwalk(ui, repo, *pats, **opts):
     """show how files match on given patterns"""
     m = scmutil.match(repo[None], pats, opts)
     items = list(repo.walk(m))
     if not items:
     f = lambda fn: fn
     if ui.configbool('ui', 'slash') and os.sep != '/':
@@ -2825,17 +2833,18 @@  def debugwireargs(ui, repopath, *vals, *
     ui.write("%s\n" % res1)
     if res1 != res2:
         ui.warn("%s\n" % res2)
     [('r', 'rev', [], _('revision'), _('REV')),
     ('c', 'change', '', _('change made by revision'), _('REV'))
     ] + diffopts + diffopts2 + walkopts + subrepoopts,
-    _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'))
+    _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...'),
+    inferrepo=True)
 def diff(ui, repo, *pats, **opts):
     """diff repository (or selected files)
     Show differences between revisions for the specified files.
     Differences between files are shown using the unified diff format.
     .. note::
@@ -2987,17 +2996,17 @@  def export(ui, repo, *changesets, **opts
     if len(revs) > 1:
         ui.note(_('exporting patches:\n'))
         ui.note(_('exporting patch:\n'))
     cmdutil.export(repo, revs, template=opts.get('output'),
                  opts=patch.diffopts(ui, opts))
-@command('^forget', walkopts, _('[OPTION]... FILE...'))
+@command('^forget', walkopts, _('[OPTION]... FILE...'), inferrepo=True)
 def forget(ui, repo, *pats, **opts):
     """forget the specified files on the next commit
     Mark the specified files so they will no longer be tracked
     after the next commit.
     This only removes files from the current branch, not from the
     entire project history, and it does not delete them from the
@@ -3253,17 +3262,18 @@  def graft(ui, repo, *revs, **opts):
     ('l', 'files-with-matches', None,
      _('print only filenames and revisions that match')),
     ('n', 'line-number', None, _('print matching line numbers')),
     ('r', 'rev', [],
      _('only search files changed within revision range'), _('REV')),
     ('u', 'user', None, _('list the author (long with -v)')),
     ('d', 'date', None, _('list the date (short with -q)')),
     ] + walkopts,
-    _('[OPTION]... PATTERN [FILE]...'))
+    _('[OPTION]... PATTERN [FILE]...'),
+    inferrepo=True)
 def grep(ui, repo, pattern, *pats, **opts):
     """search for a pattern in specified files and revisions
     Search revisions of files for a regular expression.
     This command behaves differently than Unix grep. It only accepts
     Python/Perl regexps. It searches repository history, not the
     working directory. It always prints the revision number in which a
@@ -4011,17 +4021,18 @@  def locate(ui, repo, *pats, **opts):
     ('', 'only-branch', [],
      _('show only changesets within the given named branch (DEPRECATED)'),
     ('b', 'branch', [],
      _('show changesets within the given named branch'), _('BRANCH')),
     ('P', 'prune', [],
      _('do not display revision or any of its ancestors'), _('REV')),
     ] + logopts + walkopts,
-    _('[OPTION]... [FILE]'))
+    _('[OPTION]... [FILE]'),
+    inferrepo=True)
 def log(ui, repo, *pats, **opts):
     """show revision history of entire repository or files
     Print the revision history of the specified files or the entire
     If no revision range is specified, the default is ``tip:0`` unless
     --follow is set, in which case the working directory parent is
@@ -4369,17 +4380,18 @@  def outgoing(ui, repo, dest=None, **opts
         return hg.outgoing(ui, repo, dest, opts)
         del repo._subtoppath
     [('r', 'rev', '', _('show parents of the specified revision'), _('REV')),
     ] + templateopts,
-    _('[-r REV] [FILE]'))
+    _('[-r REV] [FILE]'),
+    inferrepo=True)
 def parents(ui, repo, file_=None, **opts):
     """show the parents of the working directory or revision
     Print the working directory's parent revisions. If a revision is
     given via -r/--rev, the parent of that revision will be printed.
     If a file argument is given, the revision in which the file was
     last changed (before the working directory revision or the
     argument to --rev if given) is printed.
@@ -4766,17 +4778,18 @@  def recover(ui, repo):
         return hg.verify(repo)
     return 1
     [('A', 'after', None, _('record delete for missing files')),
     ('f', 'force', None,
      _('remove (and delete) file even if added or modified')),
     ] + walkopts,
-    _('[OPTION]... FILE...'))
+    _('[OPTION]... FILE...'),
+    inferrepo=True)
 def remove(ui, repo, *pats, **opts):
     """remove the specified files on the next commit
     Schedule the indicated files for removal from the current branch.
     This command schedules the files to be removed at the next commit.
     To undo a remove before that, see :hg:`revert`. To undo added
     files, see :hg:`forget`.
@@ -4895,17 +4908,18 @@  def rename(ui, repo, *pats, **opts):
     [('a', 'all', None, _('select all unresolved files')),
     ('l', 'list', None, _('list state of files needing merge')),
     ('m', 'mark', None, _('mark files as resolved')),
     ('u', 'unmark', None, _('mark files as unresolved')),
     ('n', 'no-status', None, _('hide status prefix'))]
     + mergetoolopts + walkopts,
-    _('[OPTION]... [FILE]...'))
+    _('[OPTION]... [FILE]...'),
+    inferrepo=True)
 def resolve(ui, repo, *pats, **opts):
     """redo merges or set/view the merge status of files
     Merges with unresolved conflicts are often the result of
     non-interactive merging using the ``internal:merge`` configuration
     setting, or a command-line merge tool like ``diff3``. The resolve
     command is used to manage the files involved in a merge, after
     :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the
@@ -5266,17 +5280,18 @@  class httpservice(object):
     ('u', 'unknown', None, _('show only unknown (not tracked) files')),
     ('i', 'ignored', None, _('show only ignored files')),
     ('n', 'no-status', None, _('hide status prefix')),
     ('C', 'copies', None, _('show source of copied files')),
     ('0', 'print0', None, _('end filenames with NUL, for use with xargs')),
     ('', 'rev', [], _('show difference from revision'), _('REV')),
     ('', 'change', '', _('list the changed files of a revision'), _('REV')),
     ] + walkopts + subrepoopts,
-    _('[OPTION]... [FILE]...'))
+    _('[OPTION]... [FILE]...'),
+    inferrepo=True)
 def status(ui, repo, *pats, **opts):
     """show changed files in the working directory
     Show status of files in the repository. If names are given, only
     files that match are shown. Files that are clean or ignored or
     the source of a copy/move operation, are not listed unless
     -c/--clean, -i/--ignored, -C/--copies or -A/--all are given.
     Unless options described with "show only ..." are given, the