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

login
register
mail settings
Submitter phabricator
Date Nov. 6, 2019, 5:04 p.m.
Message ID <differential-rev-PHID-DREV-rcfnraui63p6jrd4kvjj-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42807/
State New
Headers show

Comments

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

REPOSITORY
  rHG Mercurial

BRANCH
  default

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
phabricator - Nov. 12, 2019, 10:06 p.m.
marmoute added a comment.


  Can you elaborate on what this changeset is about ? the description is a bit… short;-)

REPOSITORY
  rHG Mercurial

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

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

To: martinvonz, #hg-reviewers
Cc: marmoute, mercurial-devel
phabricator - Nov. 12, 2019, 10:21 p.m.
martinvonz added a comment.


  In D7257#108377 <https://phab.mercurial-scm.org/D7257#108377>, @marmoute wrote:
  
  > Can you elaborate on what this changeset is about ? the description is a bit… short;-)
  
  Done.

REPOSITORY
  rHG Mercurial

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

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

To: martinvonz, #hg-reviewers
Cc: marmoute, mercurial-devel
phabricator - Nov. 13, 2019, 11:10 p.m.
durin42 added a comment.
durin42 accepted this revision as: durin42.


  I'm a big fan of this idea. I'd probably land it if there were some obvious usecases as child patches. :)

REPOSITORY
  rHG Mercurial

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

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

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

Patch

diff --git a/mercurial/repoview.py b/mercurial/repoview.py
--- a/mercurial/repoview.py
+++ b/mercurial/repoview.py
@@ -168,6 +168,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,
@@ -331,6 +332,24 @@ 
     return cl
 
 
+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
 
@@ -399,8 +418,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, r'_clcache', cl)
             object.__setattr__(self, r'_clcachekey', newkey)
         return cl
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -6793,7 +6793,7 @@ 
     if not revs and not change:
         # Avoid loading obsmarkers if we're accessing only the working copy
         # parent (which will never be hidden).
-        repo = repo.unfiltered()
+        repo = repo.filtered(b'notreally')
 
     if revs and change:
         msg = _(b'cannot specify --rev and --change at the same time')