commands: add norepo argument to command decorator
Since decorators are evaluated at module load time and since the
@command decorator imports commands, the norepo variable (along with
its friends) may not be declared yet. These variables are now declared
before @command usage to ensure they are present.
--- a/mercurial/cmdutil.py Sun May 04 18:45:04 2014 -0700
+++ b/mercurial/cmdutil.py Sun May 04 20:58:25 2014 -0700
@@ -2489,14 +2489,23 @@
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.
"""
-
- def cmd(name, options=(), synopsis=None):
+ def cmd(name, options=(), synopsis=None, norepo=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))
+
return func
return decorator
--- a/mercurial/commands.py Sun May 04 18:45:04 2014 -0700
+++ b/mercurial/commands.py Sun May 04 20:58:25 2014 -0700
@@ -26,6 +26,13 @@
command = cmdutil.command(table)
+norepo = ("clone init version help debugcommands debugcomplete"
+ " debugdate debuginstall debugfsinfo debugpushkey debugwireargs"
+ " debugknown debuggetbundle debugbundle")
+optionalrepo = ("identify paths serve config showconfig debugancestor debugdag"
+ " debugdata debugindex debugindexdot debugrevlog")
+inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
+ " remove resolve status debugwalk")
# common command options
globalopts = [
@@ -5977,11 +5984,3 @@
"There is NO\nwarranty; "
"not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
))
-
-norepo = ("clone init version help debugcommands debugcomplete"
- " debugdate debuginstall debugfsinfo debugpushkey debugwireargs"
- " debugknown debuggetbundle debugbundle")
-optionalrepo = ("identify paths serve config showconfig debugancestor debugdag"
- " debugdata debugindex debugindexdot debugrevlog")
-inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
- " remove resolve status debugwalk")