diff mercurial/registrar.py @ 34781:fe987d0b9e1e

registrar: add support for storing the type of command in func object This patch adds support for storing the type of command which is going to run in the func object. For this it does the following: 1) Add three possible values as attributes to the registrar.command class 2) Add a new argument to registrar.command._doregister function 3) Add a new attribute cmdtype to the func object The type of command will be helpful in deciding what level of access on hidden commits it can has. Differential Revision: https://phab.mercurial-scm.org/D736
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 20 Sep 2017 04:47:43 +0530
parents c1fe66e89f57
children 7b857c5947ec
line wrap: on
line diff
--- a/mercurial/registrar.py	Mon Oct 16 22:19:02 2017 +0530
+++ b/mercurial/registrar.py	Wed Sep 20 04:47:43 2017 +0530
@@ -7,6 +7,7 @@
 
 from __future__ import absolute_import
 
+from .i18n import _
 from . import (
     configitems,
     error,
@@ -131,13 +132,35 @@
     command line arguments. If True, arguments will be examined for potential
     repository locations. See ``findrepo()``. If a repository is found, it
     will be used.
+
+    There are three constants in the class which tells what type of the command
+    that is. That information will be helpful at various places. It will be also
+    be used to decide what level of access the command has on hidden commits.
+    The constants are:
+
+    unrecoverablewrite is for those write commands which can't be recovered like
+    push.
+    recoverablewrite is for write commands which can be recovered like commit.
+    readonly is for commands which are read only.
     """
 
+    unrecoverablewrite = "unrecoverable"
+    recoverablewrite = "recoverable"
+    readonly = "readonly"
+
     def _doregister(self, func, name, options=(), synopsis=None,
-                    norepo=False, optionalrepo=False, inferrepo=False):
+                    norepo=False, optionalrepo=False, inferrepo=False,
+                    cmdtype=unrecoverablewrite):
+
+        possiblecmdtypes = set([self.unrecoverablewrite, self.recoverablewrite,
+                                self.readonly])
+        if cmdtype not in possiblecmdtypes:
+            raise error.ProgrammingError(_("unknown cmdtype value '%s' for "
+                                            "'%s' command") % (cmdtype, name))
         func.norepo = norepo
         func.optionalrepo = optionalrepo
         func.inferrepo = inferrepo
+        func.cmdtype = cmdtype
         if synopsis:
             self._table[name] = func, list(options), synopsis
         else: