Patchwork [4,of,6,RFC] localrepo: move repoview to immutable class

login
register
mail settings
Submitter Gregory Szorc
Date June 9, 2017, 6:36 a.m.
Message ID <0b779b2671892a99bce6.1496990168@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/21276/
State Deferred
Headers show

Comments

Gregory Szorc - June 9, 2017, 6:36 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1496980831 25200
#      Thu Jun 08 21:00:31 2017 -0700
# Node ID 0b779b2671892a99bce634078b84eae13aa6a189
# Parent  addfd306f838ccc177cc68983bb6d41a585edd3e
localrepo: move repoview to immutable class

unfiltered() is generic and can be moved outright.

filtered() uses a different repoview class on the immutable instance.
So the implementation is copied and modified as appropriate. The
docstring and comments go with it though.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -466,6 +466,21 @@  class immutablelocalrepository(object):
     def _writerequirements(self):
         scmutil.writerequires(self.vfs, self.requirements)
 
+    def unfiltered(self):
+        """Return unfiltered version of the repository
+
+        Intended to be overwritten by filtered repo."""
+        return self
+
+    def filtered(self, name):
+        """Return a filtered version of a repository"""
+        # build a new class with the mixin and the current class
+        # (possibly subclass of the repo)
+        base = self.unfiltered().__class__
+        class filteredrepo(repoview.immutablerepoview, base):
+            pass
+        return filteredrepo(self, name)
+
 class localrepository(immutablelocalrepository):
 
     def __init__(self, baseui, path, create=False):
@@ -508,16 +523,7 @@  class localrepository(immutablelocalrepo
     def peer(self):
         return localpeer(self) # not cached to avoid reference cycle
 
-    def unfiltered(self):
-        """Return unfiltered version of the repository
-
-        Intended to be overwritten by filtered repo."""
-        return self
-
     def filtered(self, name):
-        """Return a filtered version of a repository"""
-        # build a new class with the mixin and the current class
-        # (possibly subclass of the repo)
         class filteredrepo(repoview.repoview, self.unfiltered().__class__):
             pass
         return filteredrepo(self, name)