Mercurial > hg-stable
changeset 6742:2d54e7c1e69d
context: clean up parents()
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 26 Jun 2008 13:46:33 -0500 |
parents | 5918e2b79859 |
children | 86e8187b721a |
files | mercurial/context.py mercurial/localrepo.py |
diffstat | 2 files changed, 15 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/context.py Thu Jun 26 13:46:31 2008 -0500 +++ b/mercurial/context.py Thu Jun 26 13:46:33 2008 -0500 @@ -55,6 +55,12 @@ md = self._repo.manifest.readdelta(self._changeset[0]) self._manifestdelta = md return self._manifestdelta + elif name == '_parents': + p = self._repo.changelog.parents(self._node) + if p[1] == nullid: + p = p[:-1] + self._parents = [changectx(self._repo, x) for x in p] + return self._parents else: raise AttributeError, name @@ -85,8 +91,7 @@ def parents(self): """return contexts for each parent changeset""" - p = self._repo.changelog.parents(self._node) - return [changectx(self._repo, x) for x in p] + return self._parents def children(self): """return contexts for each child changeset""" @@ -484,15 +489,18 @@ return True def __getattr__(self, name): - if name == '_parents': - self._parents = self._repo.parents() - return self._parents if name == '_status': self._status = self._repo.status() return self._status if name == '_manifest': self._buildmanifest() return self._manifest + elif name == '_parents': + p = self._repo.dirstate.parents() + if p[1] == nullid: + p = p[:-1] + self._parents = [changectx(self._repo, x) for x in p] + return self._parents else: raise AttributeError, name @@ -544,10 +552,6 @@ [t.extend(p.tags()) for p in self.parents()] return t - def parents(self): - """return contexts for each parent changeset""" - return self._parents - def children(self): return []
--- a/mercurial/localrepo.py Thu Jun 26 13:46:31 2008 -0500 +++ b/mercurial/localrepo.py Thu Jun 26 13:46:33 2008 -0500 @@ -489,17 +489,8 @@ return context.changectx(self, changeid) def parents(self, changeid=None): - ''' - get list of changectxs for parents of changeid or working directory - ''' - if changeid is None: - pl = self.dirstate.parents() - else: - n = self.changelog.lookup(changeid) - pl = self.changelog.parents(n) - if pl[1] == nullid: - return [self.changectx(pl[0])] - return [self.changectx(pl[0]), self.changectx(pl[1])] + '''get list of changectxs for parents of changeid''' + return self.changectx(changeid).parents() def filectx(self, path, changeid=None, fileid=None): """changeid can be a changeset revision, node, or tag.