comparison mercurial/revlogutils/debug.py @ 49776:511106bcb16c

debug-revlog: details about non-ancestors delta-bases Deltas against a base that is not an ancestor of the revision that owns this delta are notable. For example, they introduce complexity during the bundling process as the base might not exist on the unbundling side. We detect them in `hg debugrevlog` and print information about them.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 07 Nov 2022 14:38:52 -0500
parents bd3b6f363fb9
children 7aea9babac5d
comparison
equal deleted inserted replaced
49775:bd3b6f363fb9 49776:511106bcb16c
300 numfull = 0 300 numfull = 0
301 # intermediate snapshot against a prior snapshot 301 # intermediate snapshot against a prior snapshot
302 numsemi = 0 302 numsemi = 0
303 # snapshot count per depth 303 # snapshot count per depth
304 numsnapdepth = collections.defaultdict(lambda: 0) 304 numsnapdepth = collections.defaultdict(lambda: 0)
305 # number of snapshots with a non-ancestor delta
306 numsnapdepth_nad = collections.defaultdict(lambda: 0)
305 # delta against previous revision 307 # delta against previous revision
306 numprev = 0 308 numprev = 0
309 # delta against prev, where prev is a non-ancestor
310 numprev_nad = 0
307 # delta against first or second parent (not prev) 311 # delta against first or second parent (not prev)
308 nump1 = 0 312 nump1 = 0
309 nump2 = 0 313 nump2 = 0
310 # delta against neither prev nor parents 314 # delta against neither prev nor parents
311 numother = 0 315 numother = 0
316 # delta against other that is a non-ancestor
317 numother_nad = 0
312 # delta against prev that are also first or second parent 318 # delta against prev that are also first or second parent
313 # (details of `numprev`) 319 # (details of `numprev`)
314 nump1prev = 0 320 nump1prev = 0
315 nump2prev = 0 321 nump2prev = 0
316 322
356 numfull += 1 362 numfull += 1
357 numsnapdepth[0] += 1 363 numsnapdepth[0] += 1
358 addsize(size, fullsize) 364 addsize(size, fullsize)
359 addsize(size, snapsizedepth[0]) 365 addsize(size, snapsizedepth[0])
360 else: 366 else:
367 nad = (
368 delta != p1 and delta != p2 and not r.isancestorrev(delta, rev)
369 )
361 chainlengths.append(chainlengths[delta] + 1) 370 chainlengths.append(chainlengths[delta] + 1)
362 baseaddr = chainbases[delta] 371 baseaddr = chainbases[delta]
363 revaddr = r.start(rev) 372 revaddr = r.start(rev)
364 chainbases.append(baseaddr) 373 chainbases.append(baseaddr)
365 chainspans.append((revaddr - baseaddr) + size) 374 chainspans.append((revaddr - baseaddr) + size)
369 elif r.issnapshot(rev): 378 elif r.issnapshot(rev):
370 addsize(size, semisize) 379 addsize(size, semisize)
371 numsemi += 1 380 numsemi += 1
372 depth = r.snapshotdepth(rev) 381 depth = r.snapshotdepth(rev)
373 numsnapdepth[depth] += 1 382 numsnapdepth[depth] += 1
383 if nad:
384 numsnapdepth_nad[depth] += 1
374 addsize(size, snapsizedepth[depth]) 385 addsize(size, snapsizedepth[depth])
375 else: 386 else:
376 addsize(size, deltasize) 387 addsize(size, deltasize)
377 if delta == rev - 1: 388 if delta == rev - 1:
378 numprev += 1 389 numprev += 1
379 if delta == p1: 390 if delta == p1:
380 nump1prev += 1 391 nump1prev += 1
381 elif delta == p2: 392 elif delta == p2:
382 nump2prev += 1 393 nump2prev += 1
394 elif nad:
395 numprev_nad += 1
383 elif delta == p1: 396 elif delta == p1:
384 nump1 += 1 397 nump1 += 1
385 elif delta == p2: 398 elif delta == p2:
386 nump2 += 1 399 nump2 += 1
387 elif delta != nodemod.nullrev: 400 elif delta != nodemod.nullrev:
388 numother += 1 401 numother += 1
402 numother_nad += 1
389 403
390 # Obtain data on the raw chunks in the revlog. 404 # Obtain data on the raw chunks in the revlog.
391 if util.safehasattr(r, '_getsegmentforrevs'): 405 if util.safehasattr(r, '_getsegmentforrevs'):
392 segment = r._getsegmentforrevs(rev, rev)[1] 406 segment = r._getsegmentforrevs(rev, rev)[1]
393 else: 407 else:
408 for size in (datasize, fullsize, semisize, deltasize): 422 for size in (datasize, fullsize, semisize, deltasize):
409 if size[0] is None: 423 if size[0] is None:
410 size[0] = 0 424 size[0] = 0
411 425
412 numdeltas = numrevs - numfull - numempty - numsemi 426 numdeltas = numrevs - numfull - numempty - numsemi
413 numoprev = numprev - nump1prev - nump2prev 427 numoprev = numprev - nump1prev - nump2prev - numprev_nad
428 num_other_ancestors = numother - numother_nad
414 totalrawsize = datasize[2] 429 totalrawsize = datasize[2]
415 datasize[2] /= numrevs 430 datasize[2] /= numrevs
416 fulltotal = fullsize[2] 431 fulltotal = fullsize[2]
417 if numfull == 0: 432 if numfull == 0:
418 fullsize[2] = 0 433 fullsize[2] = 0
475 ) 490 )
476 ui.writenoi18n( 491 ui.writenoi18n(
477 b' snapshot : ' + fmt % pcfmt(numfull + numsemi, numrevs) 492 b' snapshot : ' + fmt % pcfmt(numfull + numsemi, numrevs)
478 ) 493 )
479 for depth in sorted(numsnapdepth): 494 for depth in sorted(numsnapdepth):
480 ui.write( 495 base = b' lvl-%-3d : ' % depth
481 (b' lvl-%-3d : ' % depth) 496 count = fmt % pcfmt(numsnapdepth[depth], numrevs)
482 + fmt % pcfmt(numsnapdepth[depth], numrevs) 497 pieces = [base, count]
483 ) 498 if numsnapdepth_nad[depth]:
499 pieces[-1] = count = count[:-1] # drop the final '\n'
500 more = b' non-ancestor-bases: '
501 anc_count = fmt
502 anc_count %= pcfmt(numsnapdepth_nad[depth], numsnapdepth[depth])
503 pieces.append(more)
504 pieces.append(anc_count)
505 ui.write(b''.join(pieces))
484 ui.writenoi18n(b' deltas : ' + fmt % pcfmt(numdeltas, numrevs)) 506 ui.writenoi18n(b' deltas : ' + fmt % pcfmt(numdeltas, numrevs))
485 ui.writenoi18n(b'revision size : ' + fmt2 % totalsize) 507 ui.writenoi18n(b'revision size : ' + fmt2 % totalsize)
486 ui.writenoi18n( 508 ui.writenoi18n(
487 b' snapshot : ' + fmt % pcfmt(fulltotal + semitotal, totalsize) 509 b' snapshot : ' + fmt % pcfmt(fulltotal + semitotal, totalsize)
488 ) 510 )
559 ) 581 )
560 ui.writenoi18n( 582 ui.writenoi18n(
561 b' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, numprev) 583 b' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, numprev)
562 ) 584 )
563 ui.writenoi18n( 585 ui.writenoi18n(
564 b' other : ' + fmt2 % pcfmt(numoprev, numprev) 586 b' other-ancestor : ' + fmt2 % pcfmt(numoprev, numprev)
587 )
588 ui.writenoi18n(
589 b' unrelated : ' + fmt2 % pcfmt(numoprev, numprev)
565 ) 590 )
566 if gdelta: 591 if gdelta:
567 ui.writenoi18n( 592 ui.writenoi18n(
568 b'deltas against p1 : ' + fmt % pcfmt(nump1, numdeltas) 593 b'deltas against p1 : ' + fmt % pcfmt(nump1, numdeltas)
569 ) 594 )
570 ui.writenoi18n( 595 ui.writenoi18n(
571 b'deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas) 596 b'deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas)
572 ) 597 )
573 ui.writenoi18n( 598 ui.writenoi18n(
574 b'deltas against other : ' + fmt % pcfmt(numother, numdeltas) 599 b'deltas against ancs : '
575 ) 600 + fmt % pcfmt(num_other_ancestors, numdeltas)
601 )
602 ui.writenoi18n(
603 b'deltas against other : '
604 + fmt % pcfmt(numother_nad, numdeltas)
605 )