Patchwork [2,of,3] localrepo: use type() to create filtered repo type

login
register
mail settings
Submitter Gregory Szorc
Date May 27, 2017, 12:42 a.m.
Message ID <9a7f60cb77b6969608d2.1495845755@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/20955/
State Accepted
Headers show

Comments

Gregory Szorc - May 27, 2017, 12:42 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1495831746 25200
#      Fri May 26 13:49:06 2017 -0700
# Node ID 9a7f60cb77b6969608d2a9b72a2ccb31a53db82b
# Parent  922d86488388b186fa407eae78fbb811c57a3293
localrepo: use type() to create filtered repo type

This allows us to name the type after the filter. This makes
debugging a bit easier.

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -495,9 +495,9 @@  class localrepository(object):
         """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)
+        bases = (repoview.repoview, self.unfiltered().__class__)
+        cls = type('%sfilteredrepo' % name, bases, {})
+        return cls(self, name)
 
     @repofilecache('bookmarks', 'bookmarks.current')
     def _bookmarks(self):