mercurial/revlog.py
changeset 4984 b4066fcbd6ba
parent 4983 4dbcfc6e359e
child 4985 e6525e459157
equal deleted inserted replaced
4983:4dbcfc6e359e 4984:b4066fcbd6ba
   407         and can be used to implement COW semantics or the like.
   407         and can be used to implement COW semantics or the like.
   408         """
   408         """
   409         self.indexfile = indexfile
   409         self.indexfile = indexfile
   410         self.datafile = indexfile[:-2] + ".d"
   410         self.datafile = indexfile[:-2] + ".d"
   411         self.opener = opener
   411         self.opener = opener
   412 
       
   413         self.indexstat = None
   412         self.indexstat = None
   414         self.cache = None
   413         self._cache = None
   415         self._chunkcache = None
   414         self._chunkcache = None
   416         self.defversion = REVLOG_DEFAULT_VERSION
   415         self.defversion = REVLOG_DEFAULT_VERSION
   417         if hasattr(opener, "defversion"):
   416         if hasattr(opener, "defversion"):
   418             self.defversion = opener.defversion
   417             self.defversion = opener.defversion
   419             if self.defversion & REVLOGNG:
   418             if self.defversion & REVLOGNG:
   889 
   888 
   890     def revision(self, node):
   889     def revision(self, node):
   891         """return an uncompressed revision of a given"""
   890         """return an uncompressed revision of a given"""
   892         if node == nullid:
   891         if node == nullid:
   893             return ""
   892             return ""
   894         if self.cache and self.cache[0] == node:
   893         if self._cache and self._cache[0] == node:
   895             return self.cache[2]
   894             return self._cache[2]
   896 
   895 
   897         # look up what we need to read
   896         # look up what we need to read
   898         text = None
   897         text = None
   899         rev = self.rev(node)
   898         rev = self.rev(node)
   900         base = self.base(rev)
   899         base = self.base(rev)
   904             df = None
   903             df = None
   905         else:
   904         else:
   906             df = self.opener(self.datafile)
   905             df = self.opener(self.datafile)
   907 
   906 
   908         # do we have useful data cached?
   907         # do we have useful data cached?
   909         if self.cache and self.cache[1] >= base and self.cache[1] < rev:
   908         if self._cache and self._cache[1] >= base and self._cache[1] < rev:
   910             base = self.cache[1]
   909             base = self._cache[1]
   911             text = self.cache[2]
   910             text = self._cache[2]
   912             self._loadindex(base, rev + 1)
   911             self._loadindex(base, rev + 1)
   913         else:
   912         else:
   914             self._loadindex(base, rev + 1)
   913             self._loadindex(base, rev + 1)
   915             text = self.chunk(base, df=df)
   914             text = self.chunk(base, df=df)
   916 
   915 
   923         p1, p2 = self.parents(node)
   922         p1, p2 = self.parents(node)
   924         if node != hash(text, p1, p2):
   923         if node != hash(text, p1, p2):
   925             raise RevlogError(_("integrity check failed on %s:%d")
   924             raise RevlogError(_("integrity check failed on %s:%d")
   926                               % (self.datafile, rev))
   925                               % (self.datafile, rev))
   927 
   926 
   928         self.cache = (node, rev, text)
   927         self._cache = (node, rev, text)
   929         return text
   928         return text
   930 
   929 
   931     def checkinlinesize(self, tr, fp=None):
   930     def checkinlinesize(self, tr, fp=None):
   932         if not self._inline:
   931         if not self._inline:
   933             return
   932             return
  1045             ifh.write(entry)
  1044             ifh.write(entry)
  1046             ifh.write(data[0])
  1045             ifh.write(data[0])
  1047             ifh.write(data[1])
  1046             ifh.write(data[1])
  1048             self.checkinlinesize(transaction, ifh)
  1047             self.checkinlinesize(transaction, ifh)
  1049 
  1048 
  1050         self.cache = (node, curr, text)
  1049         self._cache = (node, curr, text)
  1051         return node
  1050         return node
  1052 
  1051 
  1053     def ancestor(self, a, b):
  1052     def ancestor(self, a, b):
  1054         """calculate the least common ancestor of nodes a and b"""
  1053         """calculate the least common ancestor of nodes a and b"""
  1055 
  1054 
  1231 
  1230 
  1232         indexf = self.opener(self.indexfile, "a")
  1231         indexf = self.opener(self.indexfile, "a")
  1233         indexf.truncate(end)
  1232         indexf.truncate(end)
  1234 
  1233 
  1235         # then reset internal state in memory to forget those revisions
  1234         # then reset internal state in memory to forget those revisions
  1236         self.cache = None
  1235         self._cache = None
  1237         self._chunkcache = None
  1236         self._chunkcache = None
  1238         for x in xrange(rev, self.count()):
  1237         for x in xrange(rev, self.count()):
  1239             del self.nodemap[self.node(x)]
  1238             del self.nodemap[self.node(x)]
  1240 
  1239 
  1241         del self.index[rev:-1]
  1240         del self.index[rev:-1]