# HG changeset patch # User Yuya Nishihara <y...@tcha.org> # Date 1508660614 -32400 # Sun Oct 22 17:23:34 2017 +0900 # Node ID 79e2137e034bcd8d9707c2e09780f7d1901e4bf0 # Parent fe473251da338771d6fa4d0cbbf1e3d3f5843d0e filectx: extract helper method to obtain filectx pointing to its introrev
diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -946,6 +946,14 @@ class basefilectx(object): return self.linkrev() return self._adjustlinkrev(self.rev(), inclusive=True) + def introfilectx(self): + """Return filectx having identical contents, but pointing to the + changeset revision where this filectx was introduced""" + introrev = self.introrev() + if self.rev() == introrev: + return self + return self.filectx(self.filenode(), changeid=introrev) + def _parentfilectx(self, path, fileid, filelog): """create parent filectx keeping ancestry info for _adjustlinkrev()""" fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) @@ -1036,19 +1044,16 @@ class basefilectx(object): return pl # use linkrev to find the first changeset where self appeared - base = self - introrev = self.introrev() - if self.rev() != introrev: - base = self.filectx(self.filenode(), changeid=introrev) + base = self.introfilectx() if getattr(base, '_ancestrycontext', None) is None: cl = self._repo.changelog - if introrev is None: + if base.rev() is None: # wctx is not inclusive, but works because _ancestrycontext # is used to test filelog revisions ac = cl.ancestors([p.rev() for p in base.parents()], inclusive=True) else: - ac = cl.ancestors([introrev], inclusive=True) + ac = cl.ancestors([base.rev()], inclusive=True) base._ancestrycontext = ac # This algorithm would prefer to be recursive, but Python is a diff --git a/mercurial/dagop.py b/mercurial/dagop.py --- a/mercurial/dagop.py +++ b/mercurial/dagop.py @@ -268,9 +268,7 @@ def blockancestors(fctx, fromline, tolin `fromline`-`toline` range. """ diffopts = patch.diffopts(fctx._repo.ui) - introrev = fctx.introrev() - if fctx.rev() != introrev: - fctx = fctx.filectx(fctx.filenode(), changeid=introrev) + fctx = fctx.introfilectx() visit = {(fctx.linkrev(), fctx.filenode()): (fctx, (fromline, toline))} while visit: c, linerange2 = visit.pop(max(visit)) _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel