Patchwork D7248: repoview: avoid wrapping changelog if there's nothing to filter

login
register
mail settings
Submitter phabricator
Date Nov. 6, 2019, 12:59 a.m.
Message ID <differential-rev-PHID-DREV-xzbb3jfqswujz74tryyr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42773/
State Superseded
Headers show

Comments

phabricator - Nov. 6, 2019, 12:59 a.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This simplifies the code a bit by moving the optimizaton for no
  filtered revisions to one place. I assume it also makes working with
  repos without obsmarkers a little faster, but it doesn't seem
  significant.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/repoview.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 6, 2019, 3:35 a.m.
This revision is now accepted and ready to land.
indygreg added a comment.
indygreg accepted this revision.


  Nice series.
  
  The only thing that I would consider changing is moving the class definition out of a function so it can more easily be monkeypatched. We can always construct a new type using the generic class as a base to facilitate wrapping the changelog. The code in `localrepo.py` for deriving a custom repo type could be used as inspiration.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7248/new/

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

To: martinvonz, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -26,7 +26,6 @@ 
     obsolete,
     phases,
     pycompat,
-    revlog,
     tags as tagsmod,
     util,
 )
@@ -241,9 +240,6 @@ 
 
         def __iter__(self):
             """filtered version of revlog.__iter__"""
-            if len(self.filteredrevs) == 0:
-                return revlog.revlog.__iter__(self)
-
             def filterediter():
                 for i in pycompat.xrange(len(self)):
                     if i not in self.filteredrevs:
@@ -279,7 +275,7 @@ 
             return revs
 
         def headrevs(self, revs=None):
-            if revs is None and self.filteredrevs:
+            if revs is None:
                 try:
                     return self.index.headrevsfiltered(self.filteredrevs)
                 # AttributeError covers non-c-extension environments and
@@ -287,8 +283,7 @@ 
                 except AttributeError:
                     return self._headrevs()
 
-            if self.filteredrevs:
-                revs = self._checknofilteredinrevs(revs)
+            revs = self._checknofilteredinrevs(revs)
             return super(filteredchangelog, self).headrevs(revs)
 
         def strip(self, *args, **kwargs):
@@ -402,7 +397,8 @@ 
             cl = None
         # could have been made None by the previous if
         if cl is None:
-            cl = wrapchangelog(unfichangelog, revs)
+            # Only filter if there's something to filter
+            cl = wrapchangelog(unfichangelog, revs) if revs else unfichangelog
             object.__setattr__(self, r'_clcache', cl)
             object.__setattr__(self, r'_clcachekey', newkey)
         return cl