comparison mercurial/revlogutils/deltas.py @ 50654:e77ca247b85b stable

delta-find: fix pulled-delta-reuse-policy=forced behavior The code that select delta still has too many oportunity to discard the delta is has been forcibly asked to reuse. However is is fairly easy to use a dedicated fastpath for this case. So we do so. Cleaning other code that tries to enforce that policy will be done on default.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 05 Jun 2023 03:11:26 +0200
parents 485c9410b75a
children a41eeb877d07
comparison
equal deleted inserted replaced
50653:f2d78fb29f61 50654:e77ca247b85b
1260 target_rev = len(self.revlog) 1260 target_rev = len(self.revlog)
1261 1261
1262 gather_debug = self._gather_debug 1262 gather_debug = self._gather_debug
1263 cachedelta = revinfo.cachedelta 1263 cachedelta = revinfo.cachedelta
1264 revlog = self.revlog 1264 revlog = self.revlog
1265
1266 p1r = p2r = None 1265 p1r = p2r = None
1266
1267 if excluded_bases is None:
1268 excluded_bases = set()
1267 1269
1268 if gather_debug: 1270 if gather_debug:
1269 start = util.timer() 1271 start = util.timer()
1270 dbg = self._one_dbg_data() 1272 dbg = self._one_dbg_data()
1271 dbg['revision'] = target_rev 1273 dbg['revision'] = target_rev
1308 dbg['duration'] = end - start 1310 dbg['duration'] = end - start
1309 dbg[ 1311 dbg[
1310 'delta-base' 1312 'delta-base'
1311 ] = deltainfo.base # pytype: disable=attribute-error 1313 ] = deltainfo.base # pytype: disable=attribute-error
1312 dbg['search_round_count'] = 0 1314 dbg['search_round_count'] = 0
1313 dbg['using-cached-base'] = True 1315 dbg['using-cached-base'] = False
1314 dbg['delta_try_count'] = 0 1316 dbg['delta_try_count'] = 0
1315 dbg['type'] = b"full" 1317 dbg['type'] = b"full"
1316 dbg['snapshot-depth'] = 0 1318 dbg['snapshot-depth'] = 0
1317 self._dbg_process_data(dbg) 1319 self._dbg_process_data(dbg)
1318 return deltainfo 1320 return deltainfo
1319 1321
1320 if excluded_bases is None: 1322 deltainfo = None
1321 excluded_bases = set() 1323
1324 # If this source delta are to be forcibly reuse, let us comply early.
1325 if (
1326 revlog._generaldelta
1327 and revinfo.cachedelta is not None
1328 and revinfo.cachedelta[2] == DELTA_BASE_REUSE_FORCE
1329 ):
1330 base = revinfo.cachedelta[0]
1331 if base == nullrev:
1332 dbg_type = b"full"
1333 deltainfo = self._fullsnapshotinfo(fh, revinfo, target_rev)
1334 if gather_debug:
1335 snapshotdepth = 0
1336 elif base not in excluded_bases:
1337 delta = revinfo.cachedelta[1]
1338 header, data = revlog.compress(delta)
1339 deltalen = len(header) + len(data)
1340 if gather_debug:
1341 offset = revlog.end(len(revlog) - 1)
1342 chainbase = revlog.chainbase(base)
1343 distance = deltalen + offset - revlog.start(chainbase)
1344 chainlen, compresseddeltalen = revlog._chaininfo(base)
1345 chainlen += 1
1346 compresseddeltalen += deltalen
1347 if base == p1r or base == p2r:
1348 dbg_type = b"delta"
1349 snapshotdepth = None
1350 elif not revlog.issnapshot(base):
1351 snapshotdepth = None
1352 else:
1353 dbg_type = b"snapshot"
1354 snapshotdepth = revlog.snapshotdepth(base) + 1
1355 else:
1356 distance = None
1357 chainbase = None
1358 chainlen = None
1359 compresseddeltalen = None
1360 snapshotdepth = None
1361 deltainfo = _deltainfo(
1362 distance=distance,
1363 deltalen=deltalen,
1364 data=(header, data),
1365 base=base,
1366 chainbase=chainbase,
1367 chainlen=chainlen,
1368 compresseddeltalen=compresseddeltalen,
1369 snapshotdepth=snapshotdepth,
1370 )
1371
1372 if deltainfo is not None:
1373 if gather_debug:
1374 end = util.timer()
1375 dbg['duration'] = end - start
1376 dbg[
1377 'delta-base'
1378 ] = deltainfo.base # pytype: disable=attribute-error
1379 dbg['search_round_count'] = 0
1380 dbg['using-cached-base'] = True
1381 dbg['delta_try_count'] = 0
1382 dbg['type'] = b"full"
1383 if snapshotdepth is None:
1384 dbg['snapshot-depth'] = 0
1385 else:
1386 dbg['snapshot-depth'] = snapshotdepth
1387 self._dbg_process_data(dbg)
1388 return deltainfo
1322 1389
1323 # count the number of different delta we tried (for debug purpose) 1390 # count the number of different delta we tried (for debug purpose)
1324 dbg_try_count = 0 1391 dbg_try_count = 0
1325 # count the number of "search round" we did. (for debug purpose) 1392 # count the number of "search round" we did. (for debug purpose)
1326 dbg_try_rounds = 0 1393 dbg_try_rounds = 0
1327 dbg_type = b'unknown' 1394 dbg_type = b'unknown'
1328 1395
1329 deltainfo = None
1330 if p1r is None: 1396 if p1r is None:
1331 p1r = revlog.rev(revinfo.p1) 1397 p1r = revlog.rev(revinfo.p1)
1332 p2r = revlog.rev(revinfo.p2) 1398 p2r = revlog.rev(revinfo.p2)
1333 1399
1334 if self._debug_search: 1400 if self._debug_search: