--- a/mercurial/context.py Thu Sep 22 17:16:53 2016 +0900
+++ b/mercurial/context.py Sun Oct 22 17:23:34 2017 +0900
@@ -946,6 +946,14 @@
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 @@
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
--- a/mercurial/dagop.py Thu Sep 22 17:16:53 2016 +0900
+++ b/mercurial/dagop.py Sun Oct 22 17:23:34 2017 +0900
@@ -268,9 +268,7 @@
`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))