Patchwork D736: registrar: add support for storing the type of command in func object

login
register
mail settings
Submitter phabricator
Date Oct. 11, 2017, 7:10 p.m.
Message ID <5cb00555cc93ac3268f020be5b4dbb23@localhost.localdomain>
Download mbox | patch
Permalink /patch/24753/
State Not Applicable
Headers show

Comments

phabricator - Oct. 11, 2017, 7:10 p.m.
pulkit updated this revision to Diff 2595.
pulkit edited the summary of this revision.
pulkit retitled this revision from "directaccess: add support for storing the type of command in func object" to "registrar: add support for storing the type of command in func object".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D736?vs=1904&id=2595

REVISION DETAIL
  https://phab.mercurial-scm.org/D736

AFFECTED FILES
  mercurial/dispatch.py
  mercurial/registrar.py

CHANGE DETAILS




To: pulkit, #hg-reviewers, durham
Cc: durham, mercurial-devel

Patch

diff --git a/mercurial/registrar.py b/mercurial/registrar.py
--- a/mercurial/registrar.py
+++ b/mercurial/registrar.py
@@ -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:
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -35,11 +35,14 @@ 
     hook,
     profiling,
     pycompat,
+    registrar,
     scmutil,
     ui as uimod,
     util,
 )
 
+unrecoverablewrite = registrar.command.unrecoverablewrite
+
 class request(object):
     def __init__(self, args, ui=None, repo=None, fin=None, fout=None,
                  ferr=None, prereposetups=None):
@@ -495,7 +498,7 @@ 
         return aliasargs(self.fn, args)
 
     def __getattr__(self, name):
-        adefaults = {r'norepo': True,
+        adefaults = {r'norepo': True, r'cmdtype': unrecoverablewrite,
                      r'optionalrepo': False, r'inferrepo': False}
         if name not in adefaults:
             raise AttributeError(name)