Patchwork [4,of,7] revlog: accept a revs argument in `headrevs`

login
register
mail settings
Submitter Boris Feld
Date Jan. 15, 2019, 7:33 p.m.
Message ID <c9906eb8d45f2e80157c.1547580803@localhost.localdomain>
Download mbox | patch
Permalink /patch/37757/
State Accepted
Headers show

Comments

Boris Feld - Jan. 15, 2019, 7:33 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1547481960 -3600
#      Mon Jan 14 17:06:00 2019 +0100
# Node ID c9906eb8d45f2e80157ca441c1ad01987d8e198a
# Parent  da8305b14fd8d61f7943c0f53480cfbb2358880d
# EXP-Topic revset.predicates
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r c9906eb8d45f
revlog: accept a revs argument in `headrevs`

Computing the heads of an arbitrary set of revision is useful, we make it
possible to do so through the `headrevs` method of the revlog.

Right now, this is just calling dagop's implementation. However, we expect to
plug a native implementation soon.

Patch

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -347,8 +347,8 @@  class changelog(revlog.revlog):
     def reachableroots(self, minroot, heads, roots, includepath=False):
         return self.index.reachableroots2(minroot, heads, roots, includepath)
 
-    def headrevs(self):
-        if self.filteredrevs:
+    def headrevs(self, revs=None):
+        if revs is None and self.filteredrevs:
             try:
                 return self.index.headrevsfiltered(self.filteredrevs)
             # AttributeError covers non-c-extension environments and
@@ -356,7 +356,7 @@  class changelog(revlog.revlog):
             except AttributeError:
                 return self._headrevs()
 
-        return super(changelog, self).headrevs()
+        return super(changelog, self).headrevs(revs)
 
     def strip(self, *args, **kwargs):
         # XXX make something better than assert
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1100,11 +1100,13 @@  class revlog(object):
         assert heads
         return (orderedout, roots, heads)
 
-    def headrevs(self):
-        try:
-            return self.index.headrevs()
-        except AttributeError:
-            return self._headrevs()
+    def headrevs(self, revs=None):
+        if revs is None:
+            try:
+                return self.index.headrevs()
+            except AttributeError:
+                return self._headrevs()
+        return dagop.headrevs(revs, self.parentrevs)
 
     def computephases(self, roots):
         return self.index.computephasesmapsets(roots)