From d32c454372adf2700333c49aa507328dc9fb024d Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 18 Apr 2015 14:03:41 +0900 Subject: [PATCH] filectx: extract function to create parent fctx keeping ancestry info committablefilectx.parents() should use this to take advantage of the linkrev adjustment. --- mercurial/context.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/mercurial/context.py b/mercurial/context.py index 109e4bb777..da1293be41 100644 --- a/mercurial/context.py +++ b/mercurial/context.py @@ -806,6 +806,22 @@ class basefilectx(object): return self._adjustlinkrev(self._path, self._filelog, self._filenode, self.rev(), inclusive=True) + def _parentfilectx(self, path, fileid, filelog): + """create parent filectx keeping ancestry info for _adjustlinkrev()""" + fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) + if '_changeid' in vars(self) or '_changectx' in vars(self): + # If self is associated with a changeset (probably explicitly + # fed), ensure the created filectx is associated with a + # changeset that is an ancestor of self.changectx. + # This lets us later use _adjustlinkrev to get a correct link. + fctx._descendantrev = self.rev() + fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) + elif '_descendantrev' in vars(self): + # Otherwise propagate _descendantrev if we have one associated. + fctx._descendantrev = self._descendantrev + fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) + return fctx + def parents(self): _path = self._path fl = self._filelog @@ -824,22 +840,7 @@ class basefilectx(object): # first nullid parent with rename information. pl.insert(0, (r[0], r[1], self._repo.file(r[0]))) - ret = [] - for path, fnode, l in pl: - fctx = filectx(self._repo, path, fileid=fnode, filelog=l) - if '_changeid' in vars(self) or '_changectx' in vars(self): - # If self is associated with a changeset (probably explicitly - # fed), ensure the created filectx is associated with a - # changeset that is an ancestor of self.changectx. - # This lets us later use _adjustlinkrev to get a correct link. - fctx._descendantrev = self.rev() - fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) - elif '_descendantrev' in vars(self): - # Otherwise propagate _descendantrev if we have one associated. - fctx._descendantrev = self._descendantrev - fctx._ancestrycontext = getattr(self, '_ancestrycontext', None) - ret.append(fctx) - return ret + return [self._parentfilectx(path, fnode, l) for path, fnode, l in pl] def p1(self): return self.parents()[0]