mercurial/revlog.py
changeset 12623 8f97b50a8d10
parent 12336 9d234f7d8a77
child 12624 557988c691d1
equal deleted inserted replaced
12622:01b6f058021b 12623:8f97b50a8d10
  1154                 dfh.close()
  1154                 dfh.close()
  1155             ifh.close()
  1155             ifh.close()
  1156 
  1156 
  1157     def _addrevision(self, node, text, transaction, link, p1, p2,
  1157     def _addrevision(self, node, text, transaction, link, p1, p2,
  1158                      cachedelta, ifh, dfh):
  1158                      cachedelta, ifh, dfh):
       
  1159 
       
  1160         def buildtext(cachedelta):
       
  1161             if text is not None:
       
  1162                 return text
       
  1163             # flush any pending writes here so we can read it in revision
       
  1164             if dfh:
       
  1165                 dfh.flush()
       
  1166             ifh.flush()
       
  1167             basetext = self.revision(self.node(cachedelta[0]))
       
  1168             patchedtext = mdiff.patch(basetext, cachedelta[1])
       
  1169             chk = hash(patchedtext, p1, p2)
       
  1170             if chk != node:
       
  1171                 raise RevlogError(_("consistency error in delta"))
       
  1172             return patchedtext
       
  1173 
  1159         curr = len(self)
  1174         curr = len(self)
  1160         prev = curr - 1
  1175         prev = curr - 1
  1161         base = curr
  1176         base = curr
  1162         offset = self.end(prev)
  1177         offset = self.end(prev)
  1163         flags = 0
  1178         flags = 0
  1173         if deltarev != nullrev:
  1188         if deltarev != nullrev:
  1174             # can we use the cached delta?
  1189             # can we use the cached delta?
  1175             if cachedelta:
  1190             if cachedelta:
  1176                 cacherev, d = cachedelta
  1191                 cacherev, d = cachedelta
  1177                 if cacherev != deltarev:
  1192                 if cacherev != deltarev:
       
  1193                     text = buildtext(cachedelta)
  1178                     d = None
  1194                     d = None
  1179             if d is None:
  1195             if d is None:
  1180                 ptext = self.revision(deltanode)
  1196                 ptext = self.revision(deltanode)
  1181                 d = mdiff.textdiff(ptext, text)
  1197                 d = mdiff.textdiff(ptext, text)
  1182             data = compress(d)
  1198             data = compress(d)
  1185             dist = l + offset - self.start(base)
  1201             dist = l + offset - self.start(base)
  1186 
  1202 
  1187         # full versions are inserted when the needed deltas
  1203         # full versions are inserted when the needed deltas
  1188         # become comparable to the uncompressed text
  1204         # become comparable to the uncompressed text
  1189         # or the base revision is punched
  1205         # or the base revision is punched
  1190         if (d is None or dist > len(text) * 2 or
  1206         if text is None:
       
  1207             textlen = mdiff.patchedsize(self.rawsize(cachedelta[0]),
       
  1208                                         cachedelta[1])
       
  1209         else:
       
  1210             textlen = len(text)
       
  1211         if (d is None or dist > textlen * 2 or
  1191             (self.flags(base) & REVIDX_PUNCHED_FLAG)):
  1212             (self.flags(base) & REVIDX_PUNCHED_FLAG)):
       
  1213             text = buildtext(cachedelta)
  1192             data = compress(text)
  1214             data = compress(text)
  1193             l = len(data[1]) + len(data[0])
  1215             l = len(data[1]) + len(data[0])
  1194             base = curr
  1216             base = curr
  1195 
  1217 
  1196         e = (offset_type(offset, flags), l, len(text),
  1218         e = (offset_type(offset, flags), l, textlen,
  1197              base, link, self.rev(p1), self.rev(p2), node)
  1219              base, link, self.rev(p1), self.rev(p2), node)
  1198         self.index.insert(-1, e)
  1220         self.index.insert(-1, e)
  1199         self.nodemap[node] = curr
  1221         self.nodemap[node] = curr
  1200 
  1222 
  1201         entry = self._io.packentry(e, self.node, self.version, curr)
  1223         entry = self._io.packentry(e, self.node, self.version, curr)