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

login
register
mail settings
Submitter Laurent Charignon
Date March 20, 2015, 6:20 p.m.
Message ID <b9bccbb05b3ef1e1c375.1426875616@dev919.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8201/
State Superseded
Headers show

Comments

Laurent Charignon - March 20, 2015, 6:20 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1426875267 25200
#      Fri Mar 20 11:14:27 2015 -0700
# Node ID b9bccbb05b3ef1e1c375f053e3482bdb1fe0884e
# Parent  40030781f44b76e1096eca4044498b9ba7c5aeab
phase: default to C implementation for phase computation

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: