mercurial/revlogutils/deltas.py
changeset 42465 6e9ba867a946
parent 42464 66c27df1be84
child 42466 465f2d0df9ae
equal deleted inserted replaced
42464:66c27df1be84 42465:6e9ba867a946
   930 
   930 
   931         return delta
   931         return delta
   932 
   932 
   933     def _builddeltainfo(self, revinfo, base, fh):
   933     def _builddeltainfo(self, revinfo, base, fh):
   934         # can we use the cached delta?
   934         # can we use the cached delta?
       
   935         revlog = self.revlog
       
   936         chainbase = revlog.chainbase(base)
       
   937         if revlog._generaldelta:
       
   938             deltabase = base
       
   939         else:
       
   940             deltabase = chainbase
       
   941         snapshotdepth = None
       
   942         if revlog._sparserevlog and deltabase == nullrev:
       
   943             snapshotdepth = 0
       
   944         elif revlog._sparserevlog and revlog.issnapshot(deltabase):
       
   945             # A delta chain should always be one full snapshot,
       
   946             # zero or more semi-snapshots, and zero or more deltas
       
   947             p1, p2 = revlog.rev(revinfo.p1), revlog.rev(revinfo.p2)
       
   948             if deltabase not in (p1, p2) and revlog.issnapshot(deltabase):
       
   949                 snapshotdepth = len(revlog._deltachain(deltabase)[0])
   935         delta = None
   950         delta = None
   936         if revinfo.cachedelta:
   951         if revinfo.cachedelta:
   937             cachebase, cachediff = revinfo.cachedelta
   952             cachebase, cachediff = revinfo.cachedelta
   938             #check if the diff still apply
   953             #check if the diff still apply
   939             currentbase = cachebase
   954             currentbase = cachebase
   943                 currentbase = self.revlog.deltaparent(currentbase)
   958                 currentbase = self.revlog.deltaparent(currentbase)
   944             if self.revlog._lazydelta and currentbase == base:
   959             if self.revlog._lazydelta and currentbase == base:
   945                 delta = revinfo.cachedelta[1]
   960                 delta = revinfo.cachedelta[1]
   946         if delta is None:
   961         if delta is None:
   947             delta = self._builddeltadiff(base, revinfo, fh)
   962             delta = self._builddeltadiff(base, revinfo, fh)
   948         revlog = self.revlog
       
   949         header, data = revlog.compress(delta)
   963         header, data = revlog.compress(delta)
   950         deltalen = len(header) + len(data)
   964         deltalen = len(header) + len(data)
   951         chainbase = revlog.chainbase(base)
       
   952         offset = revlog.end(len(revlog) - 1)
   965         offset = revlog.end(len(revlog) - 1)
   953         dist = deltalen + offset - revlog.start(chainbase)
   966         dist = deltalen + offset - revlog.start(chainbase)
   954         if revlog._generaldelta:
       
   955             deltabase = base
       
   956         else:
       
   957             deltabase = chainbase
       
   958         chainlen, compresseddeltalen = revlog._chaininfo(base)
   967         chainlen, compresseddeltalen = revlog._chaininfo(base)
   959         chainlen += 1
   968         chainlen += 1
   960         compresseddeltalen += deltalen
   969         compresseddeltalen += deltalen
   961 
       
   962         revlog = self.revlog
       
   963         snapshotdepth = None
       
   964         if deltabase == nullrev:
       
   965             snapshotdepth = 0
       
   966         elif revlog._sparserevlog and revlog.issnapshot(deltabase):
       
   967             # A delta chain should always be one full snapshot,
       
   968             # zero or more semi-snapshots, and zero or more deltas
       
   969             p1, p2 = revlog.rev(revinfo.p1), revlog.rev(revinfo.p2)
       
   970             if deltabase not in (p1, p2) and revlog.issnapshot(deltabase):
       
   971                 snapshotdepth = len(revlog._deltachain(deltabase)[0])
       
   972 
   970 
   973         return _deltainfo(dist, deltalen, (header, data), deltabase,
   971         return _deltainfo(dist, deltalen, (header, data), deltabase,
   974                           chainbase, chainlen, compresseddeltalen,
   972                           chainbase, chainlen, compresseddeltalen,
   975                           snapshotdepth)
   973                           snapshotdepth)
   976 
   974