Patchwork D7257: [RFC] repoview: add a "filter" that just disallows walking to heads

login
register
mail settings
Submitter phabricator
Date Nov. 12, 2019, 9:34 p.m.
Message ID <05f054e42824212adcc9a19041bae2ab@localhost.localdomain>
Download mbox | patch
Permalink /patch/43151/
State Not Applicable
Headers show

Comments

phabricator - Nov. 12, 2019, 9:34 p.m.
martinvonz updated this revision to Diff 18048.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7257?vs=17625&id=18048

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

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

AFFECTED FILES
  mercurial/commands.py
  mercurial/repoview.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -169,6 +169,7 @@ 
 # Otherwise your filter will have to recompute all its branches cache
 # from scratch (very slow).
 filtertable = {
+    b'notreally': lambda repo, visibilityexceptions=None: frozenset(),
     b'visible': computehidden,
     b'visible-hidden': computehidden,
     b'served.hidden': computesecret,
@@ -336,6 +337,24 @@ 
         return super(filteredchangelogmixin, self).flags(rev)
 
 
+def poisonwalktoheads(unfichangelog):
+    cl = copy.copy(unfichangelog)
+
+    def poison(*args, **kwargs):
+        raise error.ProgrammingError('called method on changelog that requries '
+                                      'filtering, but filtering was not requested')
+
+    class filteredchangelog(cl.__class__):
+        tiprev = poison
+        headrevs = poison
+        __iter__ = poison
+        children = poison
+
+    cl.__class__ = filteredchangelog
+
+    return cl
+
+
 class repoview(object):
     """Provide a read/write view of a repo through a filtered changelog
 
@@ -404,8 +423,13 @@ 
             cl = None
         # could have been made None by the previous if
         if cl is None:
-            # Only filter if there's something to filter
-            cl = wrapchangelog(unfichangelog, revs) if revs else unfichangelog
+            if self.filtername == b'notreally':
+                cl = poisonwalktoheads(unfichangelog)
+            elif revs:
+                # Only filter if there's something to filter
+                cl = wrapchangelog(unfichangelog, revs)
+            else:
+                cl = unfichangelog
             object.__setattr__(self, '_clcache', cl)
             object.__setattr__(self, '_clcachekey', newkey)
         return cl
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -174,7 +174,7 @@ 
         if not kwargs.get(b'rev') and not kwargs.get(b'change'):
             use_unfiltered = True
 
-    return repo.unfiltered() if use_unfiltered else repo
+    return repo.filtered(b'notreally') if use_unfiltered else repo
 
 
 # Commands start here, listed alphabetically