Patchwork [4,of,5,command,metadata,resend] cmdutil: add optionalrepo argument to command decorator

login
register
mail settings
Submitter Gregory Szorc
Date June 13, 2014, 6:24 p.m.
Message ID <0a7386f0bce039ecd20d.1402683860@gps-mbp.local>
Download mbox | patch
Permalink /patch/4998/
State Accepted
Headers show

Comments

Gregory Szorc - June 13, 2014, 6:24 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1399266754 25200
#      Sun May 04 22:12:34 2014 -0700
# Node ID 0a7386f0bce039ecd20d5417bbc67864fa8c6a33
# Parent  69ad9df9b270e2452aad8bab093e8a1c2684e65e
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
@@ -2492,10 +2492,13 @@  def command(table):
 
     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:
@@ -2505,8 +2508,12 @@  def command(table):
                 # 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