Commits

Yuya Nishihara committed fe33487

hgext: textful: update to 4351921f0758

Comments (0)

Files changed (1)

dot.hgext/textful/__init__.py

         filters.append(somefilter)
 """
 import errno
-from mercurial import extensions, dispatch, error
+from mercurial import extensions, dispatch, error, util
 from mercurial.i18n import _
 
+# TODO: localrepo.(un)filteredpropertycache ?
+propertycache = util.propertycache
+
 _filters = []
 """List of fctx.data filters; extended by sub-extensions"""
 
             return wrapfilectx(e)
     return textfulworkingctx
 
+def _neverlock(wait):
+    if wait:
+        raise error.Abort(_('disallowed to modify textfulrepo'))
+    else:
+        raise error.LockUnavailable(errno.EACCES, 'Operation denied', '', '')
+
 @clswrapper
 def wraprepo(parcls):
     class textfulrepo(parcls):
+        @propertycache
+        def _textfulenabled(self):
+            return self.ui.configbool('textful', '_enabled')
+
         def __getitem__(self, changeid):
             e = super(textfulrepo, self).__getitem__(changeid)
+            if not self._textfulenabled:
+                return e
             if changeid is None:
                 return wrapworkingctx(e)
             return wrapchangectx(e)
 
         def filectx(self, path, changeid=None, fileid=None):
             x = super(textfulrepo, self).filectx(path, changeid, fileid)
+            if not self._textfulenabled:
+                return x
             return wrapfilectx(x)
 
+        # Since fctx.data() may return mangled data, we denies any destructive
+        # operation to repo if textful is enabled.
         def lock(self, wait=True):
-            # Since fctx.data() may return mangled data, we denies any
-            # destructive operation to repo.
-            if wait:
-                raise error.Abort(_('disallowed to modify textfulrepo'))
-            else:
-                raise error.LockUnavailable(errno.EACCES,
-                                            'Operation denied', '', '')
+            if self._textfulenabled:
+                _neverlock(wait)
+            return super(textfulrepo, self).lock(wait)
 
         def wlock(self, wait=True):
-            self.lock(wait)
+            if self._textfulenabled:
+                _neverlock(wait)
+            return super(textfulrepo, self).wlock(wait)
 
     return textfulrepo
 
+def reposetup(ui, repo):
+    if ui.plain():
+        return
+    wraprepo(repo)
+
 def uisetup(ui):
     if ui.plain():
         return
 
     def textfulcmd(orig, lui, repo, cmd, fullargs, ui, options, d, cmdpats,
                    cmdoptions):
-        if cmd in ui.configlist('textful', 'attend', attended):
-            wraprepo(repo)
+        # don't wraprepo(repo) here. repo may be proxycls of repoview.
+        # wrapping it will result in infinite recursion of __getattr__.
+        if repo:
+            enabled = cmd in ui.configlist('textful', 'attend', attended)
+            repo.ui.setconfig('textful', '_enabled', enabled)
         return orig(lui, repo, cmd, fullargs, ui, options, d, cmdpats,
                     cmdoptions)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.