diff mercurial/dispatch.py @ 28622:527cf881d000

dispatch: extract function that tests command attributes This function will host the compatibility layer for old third-party commands. See the next patch for details.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 14 Mar 2016 00:14:43 +0900
parents d856e85a8a7a
children 38dc3f28f478
line wrap: on
line diff
--- a/mercurial/dispatch.py	Mon Mar 14 00:06:52 2016 +0900
+++ b/mercurial/dispatch.py	Mon Mar 14 00:14:43 2016 +0900
@@ -746,6 +746,9 @@
         return lambda: runcommand(lui, None, cmd, args[:1], ui, options, d,
                                   [], {})
 
+def _cmdattr(ui, cmd, func, attr):
+    return getattr(func, attr)
+
 _loaded = set()
 
 # list of (objname, loadermod, loadername) tuple:
@@ -874,7 +877,7 @@
 
     repo = None
     cmdpats = args[:]
-    if not func.norepo:
+    if not _cmdattr(ui, cmd, func, 'norepo'):
         # use the repo from the request only if we don't have -R
         if not rpath and not cwd:
             repo = req.repo
@@ -895,8 +898,9 @@
             except error.RepoError:
                 if rpath and rpath[-1]: # invalid -R path
                     raise
-                if not func.optionalrepo:
-                    if func.inferrepo and args and not path:
+                if not _cmdattr(ui, cmd, func, 'optionalrepo'):
+                    if (_cmdattr(ui, cmd, func, 'inferrepo') and
+                        args and not path):
                         # try to infer -R from command args
                         repos = map(cmdutil.findrepo, args)
                         guess = repos[0]