Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 35280:d90c534099b1
filectx: extract helper method to obtain filectx pointing to its introrev
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 22 Oct 2017 17:23:34 +0900 |
parents | b22a0d9e0a83 |
children | 010179e21e91 |
comparison
equal
deleted
inserted
replaced
35279:0d27685b4a2f | 35280:d90c534099b1 |
---|---|
944 noctx = not ('_changeid' in attrs or '_changectx' in attrs) | 944 noctx = not ('_changeid' in attrs or '_changectx' in attrs) |
945 if noctx or self.rev() == lkr: | 945 if noctx or self.rev() == lkr: |
946 return self.linkrev() | 946 return self.linkrev() |
947 return self._adjustlinkrev(self.rev(), inclusive=True) | 947 return self._adjustlinkrev(self.rev(), inclusive=True) |
948 | 948 |
949 def introfilectx(self): | |
950 """Return filectx having identical contents, but pointing to the | |
951 changeset revision where this filectx was introduced""" | |
952 introrev = self.introrev() | |
953 if self.rev() == introrev: | |
954 return self | |
955 return self.filectx(self.filenode(), changeid=introrev) | |
956 | |
949 def _parentfilectx(self, path, fileid, filelog): | 957 def _parentfilectx(self, path, fileid, filelog): |
950 """create parent filectx keeping ancestry info for _adjustlinkrev()""" | 958 """create parent filectx keeping ancestry info for _adjustlinkrev()""" |
951 fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) | 959 fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog) |
952 if '_changeid' in vars(self) or '_changectx' in vars(self): | 960 if '_changeid' in vars(self) or '_changectx' in vars(self): |
953 # If self is associated with a changeset (probably explicitly | 961 # If self is associated with a changeset (probably explicitly |
1034 p._filelog = getlog(p.path()) | 1042 p._filelog = getlog(p.path()) |
1035 | 1043 |
1036 return pl | 1044 return pl |
1037 | 1045 |
1038 # use linkrev to find the first changeset where self appeared | 1046 # use linkrev to find the first changeset where self appeared |
1039 base = self | 1047 base = self.introfilectx() |
1040 introrev = self.introrev() | |
1041 if self.rev() != introrev: | |
1042 base = self.filectx(self.filenode(), changeid=introrev) | |
1043 if getattr(base, '_ancestrycontext', None) is None: | 1048 if getattr(base, '_ancestrycontext', None) is None: |
1044 cl = self._repo.changelog | 1049 cl = self._repo.changelog |
1045 if introrev is None: | 1050 if base.rev() is None: |
1046 # wctx is not inclusive, but works because _ancestrycontext | 1051 # wctx is not inclusive, but works because _ancestrycontext |
1047 # is used to test filelog revisions | 1052 # is used to test filelog revisions |
1048 ac = cl.ancestors([p.rev() for p in base.parents()], | 1053 ac = cl.ancestors([p.rev() for p in base.parents()], |
1049 inclusive=True) | 1054 inclusive=True) |
1050 else: | 1055 else: |
1051 ac = cl.ancestors([introrev], inclusive=True) | 1056 ac = cl.ancestors([base.rev()], inclusive=True) |
1052 base._ancestrycontext = ac | 1057 base._ancestrycontext = ac |
1053 | 1058 |
1054 # This algorithm would prefer to be recursive, but Python is a | 1059 # This algorithm would prefer to be recursive, but Python is a |
1055 # bit recursion-hostile. Instead we do an iterative | 1060 # bit recursion-hostile. Instead we do an iterative |
1056 # depth-first search. | 1061 # depth-first search. |