mercurial/context.py
changeset 30275 e81d72b4b0ae
parent 30270 e25ce44f8447
child 30340 608ba935e041
equal deleted inserted replaced
30274:c1345969f6c5 30275:e81d72b4b0ae
   678         elif '_changectx' in self.__dict__:
   678         elif '_changectx' in self.__dict__:
   679             return self._changectx.rev()
   679             return self._changectx.rev()
   680         elif '_descendantrev' in self.__dict__:
   680         elif '_descendantrev' in self.__dict__:
   681             # this file context was created from a revision with a known
   681             # this file context was created from a revision with a known
   682             # descendant, we can (lazily) correct for linkrev aliases
   682             # descendant, we can (lazily) correct for linkrev aliases
   683             return self._adjustlinkrev(self._path, self._filelog,
   683             return self._adjustlinkrev(self._descendantrev)
   684                                        self._filenode, self._descendantrev)
       
   685         else:
   684         else:
   686             return self._filelog.linkrev(self._filerev)
   685             return self._filelog.linkrev(self._filerev)
   687 
   686 
   688     @propertycache
   687     @propertycache
   689     def _filenode(self):
   688     def _filenode(self):
   809             or self.size() == fctx.size()):
   808             or self.size() == fctx.size()):
   810             return self._filelog.cmp(self._filenode, fctx.data())
   809             return self._filelog.cmp(self._filenode, fctx.data())
   811 
   810 
   812         return True
   811         return True
   813 
   812 
   814     def _adjustlinkrev(self, path, filelog, fnode, srcrev, inclusive=False):
   813     def _adjustlinkrev(self, srcrev, inclusive=False):
   815         """return the first ancestor of <srcrev> introducing <fnode>
   814         """return the first ancestor of <srcrev> introducing <fnode>
   816 
   815 
   817         If the linkrev of the file revision does not point to an ancestor of
   816         If the linkrev of the file revision does not point to an ancestor of
   818         srcrev, we'll walk down the ancestors until we find one introducing
   817         srcrev, we'll walk down the ancestors until we find one introducing
   819         this file revision.
   818         this file revision.
   820 
   819 
   821         :repo: a localrepository object (used to access changelog and manifest)
       
   822         :path: the file path
       
   823         :fnode: the nodeid of the file revision
       
   824         :filelog: the filelog of this path
       
   825         :srcrev: the changeset revision we search ancestors from
   820         :srcrev: the changeset revision we search ancestors from
   826         :inclusive: if true, the src revision will also be checked
   821         :inclusive: if true, the src revision will also be checked
   827         """
   822         """
   828         repo = self._repo
   823         repo = self._repo
   829         cl = repo.unfiltered().changelog
   824         cl = repo.unfiltered().changelog
   830         mfl = repo.manifestlog
   825         mfl = repo.manifestlog
   831         # fetch the linkrev
   826         # fetch the linkrev
   832         fr = filelog.rev(fnode)
   827         lkr = self.linkrev()
   833         lkr = filelog.linkrev(fr)
       
   834         # hack to reuse ancestor computation when searching for renames
   828         # hack to reuse ancestor computation when searching for renames
   835         memberanc = getattr(self, '_ancestrycontext', None)
   829         memberanc = getattr(self, '_ancestrycontext', None)
   836         iteranc = None
   830         iteranc = None
   837         if srcrev is None:
   831         if srcrev is None:
   838             # wctx case, used by workingfilectx during mergecopy
   832             # wctx case, used by workingfilectx during mergecopy
   845                                                inclusive=inclusive)
   839                                                inclusive=inclusive)
   846         # check if this linkrev is an ancestor of srcrev
   840         # check if this linkrev is an ancestor of srcrev
   847         if lkr not in memberanc:
   841         if lkr not in memberanc:
   848             if iteranc is None:
   842             if iteranc is None:
   849                 iteranc = cl.ancestors(revs, lkr, inclusive=inclusive)
   843                 iteranc = cl.ancestors(revs, lkr, inclusive=inclusive)
       
   844             fnode = self._filenode
       
   845             path = self._path
   850             for a in iteranc:
   846             for a in iteranc:
   851                 ac = cl.read(a) # get changeset data (we avoid object creation)
   847                 ac = cl.read(a) # get changeset data (we avoid object creation)
   852                 if path in ac[3]: # checking the 'files' field.
   848                 if path in ac[3]: # checking the 'files' field.
   853                     # The file has been touched, check if the content is
   849                     # The file has been touched, check if the content is
   854                     # similar to the one we search for.
   850                     # similar to the one we search for.
   872         lkr = self.linkrev()
   868         lkr = self.linkrev()
   873         attrs = vars(self)
   869         attrs = vars(self)
   874         noctx = not ('_changeid' in attrs or '_changectx' in attrs)
   870         noctx = not ('_changeid' in attrs or '_changectx' in attrs)
   875         if noctx or self.rev() == lkr:
   871         if noctx or self.rev() == lkr:
   876             return self.linkrev()
   872             return self.linkrev()
   877         return self._adjustlinkrev(self._path, self._filelog, self._filenode,
   873         return self._adjustlinkrev(self.rev(), inclusive=True)
   878                                    self.rev(), inclusive=True)
       
   879 
   874 
   880     def _parentfilectx(self, path, fileid, filelog):
   875     def _parentfilectx(self, path, fileid, filelog):
   881         """create parent filectx keeping ancestry info for _adjustlinkrev()"""
   876         """create parent filectx keeping ancestry info for _adjustlinkrev()"""
   882         fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog)
   877         fctx = filectx(self._repo, path, fileid=fileid, filelog=filelog)
   883         if '_changeid' in vars(self) or '_changectx' in vars(self):
   878         if '_changeid' in vars(self) or '_changectx' in vars(self):