Patchwork [2,of,3,V4] phase: default to C implementation for phase computation

login
register
mail settings
Submitter Laurent Charignon
Date March 24, 2015, 8:48 p.m.
Message ID <b425123efec6b39be5b4.1427230134@dev919.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8244/
State Accepted
Commit 27e3ba73fbb18096cf8d0463ae1dd2d23b77f506
Headers show

Comments

Laurent Charignon - March 24, 2015, 8:48 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1426875267 25200
#      Fri Mar 20 11:14:27 2015 -0700
# Node ID b425123efec6b39be5b426e67766b4bbd5361369
# Parent  0f69eec6e238d335be2dfadc00b0c3ebce2ae114
phase: default to C implementation for phase computation
Matt Mackall - March 25, 2015, 7:31 p.m.
On Tue, 2015-03-24 at 13:48 -0700, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1426875267 25200
> #      Fri Mar 20 11:14:27 2015 -0700
> # Node ID b425123efec6b39be5b426e67766b4bbd5361369
> # Parent  0f69eec6e238d335be2dfadc00b0c3ebce2ae114
> phase: default to C implementation for phase computation

These are queued for default, thanks.

Patch

diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -172,19 +172,29 @@ 
         for a in 'phaseroots dirty opener _phaserevs'.split():
             setattr(self, a, getattr(phcache, a))
 
+    def getphaserevsnative(self, repo):
+        repo = repo.unfiltered()
+        nativeroots = []
+        for phase in trackedphases:
+            nativeroots.append(map(repo.changelog.rev, self.phaseroots[phase]))
+        return repo.changelog.computephases(nativeroots)
+
     def getphaserevs(self, repo):
         if self._phaserevs is None:
-            repo = repo.unfiltered()
-            revs = [public] * len(repo.changelog)
-            self._phaserevs = revs
-            self._populatephaseroots(repo)
-            for phase in trackedphases:
-                roots = map(repo.changelog.rev, self.phaseroots[phase])
-                if roots:
-                    for rev in roots:
-                        revs[rev] = phase
-                    for rev in repo.changelog.descendants(roots):
-                        revs[rev] = phase
+            try:
+                self._phaserevs = self.getphaserevsnative(repo)
+            except AttributeError:
+                repo = repo.unfiltered()
+                revs = [public] * len(repo.changelog)
+                self._phaserevs = revs
+                self._populatephaseroots(repo)
+                for phase in trackedphases:
+                    roots = map(repo.changelog.rev, self.phaseroots[phase])
+                    if roots:
+                        for rev in roots:
+                            revs[rev] = phase
+                        for rev in repo.changelog.descendants(roots):
+                            revs[rev] = phase
         return self._phaserevs
 
     def invalidate(self):
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -724,6 +724,9 @@ 
         except AttributeError:
             return self._headrevs()
 
+    def computephases(self, roots):
+        return self.index.computephases(roots)
+
     def _headrevs(self):
         count = len(self)
         if not count: