From patchwork Sat Apr 18 11:28:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 4, STABLE] filectx: extract function to create parent fctx keeping ancestry info From: Yuya Nishihara X-Patchwork-Id: 8736 Message-Id: <54242b301d723b516a27.1429356492@mimosa> To: mercurial-devel@selenic.com Date: Sat, 18 Apr 2015 20:28:12 +0900 # HG changeset patch # User Yuya Nishihara # Date 1429333421 -32400 # Sat Apr 18 14:03:41 2015 +0900 # Branch stable # Node ID 54242b301d723b516a27932e13d83fd213a0e3bb # Parent 0ff963ddcf2be79598659cc75f5992dc3cd0950f filectx: extract function to create parent fctx keeping ancestry info committablefilectx.parents() should use this to take advantage of the linkrev adjustment. diff --git a/mercurial/context.py b/mercurial/context.py --- 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]