Mercurial > hg
comparison mercurial/revlog.py @ 26115:748347e0e8d4
revlog: move delta check to it's own function
This moves the delta vs fulltext comparison to its own function. This will allow
us to reuse the function in future patches for more efficient delta choices. As
a side effect, this will also allow extensions to modify our delta criteria.
author | Durham Goode <durham@fb.com> |
---|---|
date | Sun, 30 Aug 2015 13:33:00 -0700 |
parents | 3df1574f3e75 |
children | 562cfc99e611 |
comparison
equal
deleted
inserted
replaced
26114:9d6d3fee0c3f | 26115:748347e0e8d4 |
---|---|
1231 if text[0] == '\0': | 1231 if text[0] == '\0': |
1232 return ("", text) | 1232 return ("", text) |
1233 return ('u', text) | 1233 return ('u', text) |
1234 return ("", bin) | 1234 return ("", bin) |
1235 | 1235 |
1236 def _isgooddelta(self, d, textlen): | |
1237 """Returns True if the given delta is good. Good means that it is within | |
1238 the disk span, disk size, and chain length bounds that we know to be | |
1239 performant.""" | |
1240 if d is None: | |
1241 return False | |
1242 | |
1243 # - 'dist' is the distance from the base revision -- bounding it limits | |
1244 # the amount of I/O we need to do. | |
1245 # - 'compresseddeltalen' is the sum of the total size of deltas we need | |
1246 # to apply -- bounding it limits the amount of CPU we consume. | |
1247 dist, l, data, base, chainbase, chainlen, compresseddeltalen = d | |
1248 if (dist > textlen * 4 or l > textlen or | |
1249 compresseddeltalen > textlen * 2 or | |
1250 (self._maxchainlen and chainlen > self._maxchainlen)): | |
1251 return False | |
1252 | |
1253 return True | |
1254 | |
1236 def _addrevision(self, node, text, transaction, link, p1, p2, flags, | 1255 def _addrevision(self, node, text, transaction, link, p1, p2, flags, |
1237 cachedelta, ifh, dfh): | 1256 cachedelta, ifh, dfh): |
1238 """internal function to add revisions to the log | 1257 """internal function to add revisions to the log |
1239 | 1258 |
1240 see addrevision for argument descriptions. | 1259 see addrevision for argument descriptions. |
1332 textlen = mdiff.patchedsize(self.rawsize(cachedelta[0]), | 1351 textlen = mdiff.patchedsize(self.rawsize(cachedelta[0]), |
1333 cachedelta[1]) | 1352 cachedelta[1]) |
1334 else: | 1353 else: |
1335 textlen = len(text) | 1354 textlen = len(text) |
1336 | 1355 |
1337 # - 'dist' is the distance from the base revision -- bounding it limits | 1356 if not self._isgooddelta(d, textlen): |
1338 # the amount of I/O we need to do. | |
1339 # - 'compresseddeltalen' is the sum of the total size of deltas we need | |
1340 # to apply -- bounding it limits the amount of CPU we consume. | |
1341 if (d is None or dist > textlen * 4 or l > textlen or | |
1342 compresseddeltalen > textlen * 2 or | |
1343 (self._maxchainlen and chainlen > self._maxchainlen)): | |
1344 text = buildtext() | 1357 text = buildtext() |
1345 data = self.compress(text) | 1358 data = self.compress(text) |
1346 l = len(data[1]) + len(data[0]) | 1359 l = len(data[1]) + len(data[0]) |
1347 base = chainbase = curr | 1360 base = chainbase = curr |
1348 | 1361 |