diff mercurial/phases.py @ 24444:27e3ba73fbb1

phase: default to C implementation for phase computation
author Laurent Charignon <lcharignon@fb.com>
date Fri, 20 Mar 2015 11:14:27 -0700
parents 37a92908a382
children de3acfabaddc
line wrap: on
line diff
--- a/mercurial/phases.py	Tue Mar 24 11:00:09 2015 -0700
+++ b/mercurial/phases.py	Fri Mar 20 11:14:27 2015 -0700
@@ -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):