[PATCH 04 of 18] phases: add to cache allowing to know in which state a changeset is

Matt Mackall mpm at selenic.com
Mon Oct 10 14:28:37 CDT 2011


On Mon, 2011-10-10 at 14:28 +0200, pierre-yves.david at logilab.fr wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at logilab.fr>
> # Date 1318239224 -7200
> # Node ID b26e7c7e3ebbcab5f6a7f4bf376b66056b0bb506
> # Parent  c48674734436d256c467145bc5acaa6fa675b887
> phases: add to cache allowing to know in which state a changeset is

Way too much code. There's no need for an on-disk cache either: it will
take longer to read or write the cache than to calculate it from the
heads.

> +    def nodephase(self, node):
> +        """return the node associated to a phase"""
> +        return self._phasesrev.get(self.changelog.rev(node), phases.allphases[-1])

No thanks. We use contexts now.

> +def _computecache(repo):
> +      """compute a {rev => phase} mapping"""
> +      cache = {}
> +      for rev in repo.changelog:
> +          cache[rev] = allphases[-1]

If you're going to look up with a rev, use a list:

cache = [0] * len(repo)

> +      for phase in reversed(trackedphases):
> +          heads = map(repo.changelog.rev, repo._phasesheads[phase])
> +          for rev in heads:
> +              cache[rev] = phase
> +          for rev in repo.changelog.ancestors(*heads):
> +              cache[rev] = phase
> +      return cache

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list