Patchwork [22,of,35] cmdutil: add optionalrepo argument to command decorator

login
register
mail settings
Submitter Gregory Szorc
Date May 5, 2014, 5:51 a.m.
Message ID <3adff8751da53b4975b5.1399269087@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4613/
State Superseded
Commit b280d0b60bc3e356e3370f12d325e47c48582e34
Headers show

Comments

Gregory Szorc - May 5, 2014, 5:51 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1399266754 25200
#      Sun May 04 22:12:34 2014 -0700
# Branch stable
# Node ID 3adff8751da53b4975b5229ba1a4de24fd843caa
# Parent  91d16a0390e01bbf1c5e46f7b909221502b8af91
cmdutil: add optionalrepo argument to command decorator

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2429,29 +2429,36 @@  def command(table):
     See ``mercurial.fancyopts.fancyopts()`` for the format of each tuple.
 
     The synopsis argument defines a short, one line summary of how to use the
     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.
     """
-    def cmd(name, options=(), synopsis=None, norepo=False):
+    def cmd(name, options=(), synopsis=None, norepo=False, optionalrepo=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))
+
             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()"