[PATCH 6 of 6 ctx-minor-fixes] context: define contract for parents

Yuya Nishihara yuya at tcha.org
Wed Sep 19 09:27:02 EDT 2018


On Tue, 18 Sep 2018 22:35:48 -0700, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean at farley.io>
> # Date 1528497109 25200
> #      Fri Jun 08 15:31:49 2018 -0700
> # Branch ctx-minor-fixes
> # Node ID 58496e395dd324297748551297d1d572ab762496
> # Parent  56222df6e5c8738b9b04881477c166540c50b17a
> context: define contract for parents

>      def parents(self):
>          """return contexts for each parent changeset"""
> -        return self._parents
> +        pl = self._parents
> +
> +        # maybe should assert that we expect _parents to always be both parents
> +        # (even when p2 is null) and to always be revs (e.g. ints)
> +        if pl[1] == nullrev:
> +            return [changectx(self._repo, pl[0])]
> +        return [changectx(self._repo, pl[0]), changectx(self._repo, pl[1])]
>  
>      def p1(self):
>          return self.parents()[0]
>  
>      def p2(self):
> @@ -479,15 +485,11 @@ class changectx(basectx):
>      def _manifestdelta(self):
>          return self._manifestctx.readdelta()
>  
>      @propertycache
>      def _parents(self):
> -        repo = self._repo
> -        p1, p2 = repo.changelog.parentrevs(self._rev)
> -        if p2 == nullrev:
> -            return [changectx(repo, p1)]
> -        return [changectx(repo, p1), changectx(repo, p2)]
> +        return self._repo.changelog.parentrevs(self._rev)

So, this removes the cache of p1/p2 ctxs. IIUC, that's the reason we have
self._parents as an interface for sub classes.


More information about the Mercurial-devel mailing list