Patchwork [25,of,35] cmdutil: support inferrepo in command decorator

login
register
mail settings
Submitter Gregory Szorc
Date May 5, 2014, 5:51 a.m.
Message ID <18c5c64d220340f53964.1399269090@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4616/
State Accepted
Commit 17d1ac452127c66674a208f3a653c792e7084d3e
Headers show

Comments

Gregory Szorc - May 5, 2014, 5:51 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1399267200 25200
#      Sun May 04 22:20:00 2014 -0700
# Branch stable
# Node ID 18c5c64d220340f5396490b6d8dcbe7a6b3ac598
# Parent  78059bc9fedddd37c619dbd07ba1aff50909af0e
cmdutil: support inferrepo in command decorator

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2432,33 +2432,43 @@  def command(table):
     command. This shows up in the help output.
 
     The norepo argument defines whether the command does not require a
     local repository. Most commands operate against a repository, thus the
     default is False.
 
     The optionalrepo argument defines whether the command optionally requires
     a local repository.
+
+    The inferrepo argument defines whether to try to find a repository from the
+    command line arguments. If True, arguments will be examined for potential
+    repository locations. See ``findrepo()``. If a repository is found, it
+    will be used.
     """
-    def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False):
+    def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=False,
+            inferrepo=False):
         def decorator(func):
             if synopsis:
                 table[name] = func, list(options), synopsis
             else:
                 table[name] = func, list(options)
 
             if norepo:
                 # Avoid import cycle.
                 import commands
                 commands.norepo += ' %s' % ' '.join(parsealiases(name))
 
             if optionalrepo:
                 import commands
                 commands.optionalrepo += ' %s' % ' '.join(parsealiases(name))
 
+            if inferrepo:
+                import commands
+                commands.inferrepo += ' %s' % ' '.join(parsealiases(name))
+
             return func
         return decorator
 
     return cmd
 
 # a list of (ui, repo, otherpeer, opts, missing) functions called by
 # commands.outgoing.  "missing" is "missing" of the result of
 # "findcommonoutgoing()"