Mercurial > hg
comparison mercurial/exchangev2.py @ 45788:a5206e71c536
revlog: extend addgroup() with callback for duplicates
The addgroup() interface currently doesn't allow the caller to keep
track of duplicated nodes except by looking at the returned node list.
Add an optional second callback for this purpose and change the return
type to a boolean. This allows follow-up changes to use more efficient
storage for the node list in places that are memory-sensitive.
Differential Revision: https://phab.mercurial-scm.org/D9231
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Sun, 18 Oct 2020 22:18:02 +0200 |
parents | b1e51ef4e536 |
children | 5d65e04b6a80 |
comparison
equal
deleted
inserted
replaced
45787:225e513c444e | 45788:a5206e71c536 |
---|---|
341 progress = repo.ui.makeprogress( | 341 progress = repo.ui.makeprogress( |
342 _(b'changesets'), unit=_(b'chunks'), total=meta.get(b'totalitems') | 342 _(b'changesets'), unit=_(b'chunks'), total=meta.get(b'totalitems') |
343 ) | 343 ) |
344 | 344 |
345 manifestnodes = {} | 345 manifestnodes = {} |
346 added = [] | |
346 | 347 |
347 def linkrev(node): | 348 def linkrev(node): |
348 repo.ui.debug(b'add changeset %s\n' % short(node)) | 349 repo.ui.debug(b'add changeset %s\n' % short(node)) |
349 # Linkrev for changelog is always self. | 350 # Linkrev for changelog is always self. |
350 return len(cl) | 351 return len(cl) |
351 | 352 |
353 def ondupchangeset(cl, node): | |
354 added.append(node) | |
355 | |
352 def onchangeset(cl, node): | 356 def onchangeset(cl, node): |
353 progress.increment() | 357 progress.increment() |
354 | 358 |
355 revision = cl.changelogrevision(node) | 359 revision = cl.changelogrevision(node) |
360 added.append(node) | |
356 | 361 |
357 # We need to preserve the mapping of changelog revision to node | 362 # We need to preserve the mapping of changelog revision to node |
358 # so we can set the linkrev accordingly when manifests are added. | 363 # so we can set the linkrev accordingly when manifests are added. |
359 manifestnodes[cl.rev(node)] = revision.manifest | 364 manifestnodes[cl.rev(node)] = revision.manifest |
360 | 365 |
401 mdiff.trivialdiffheader(len(data)) + data, | 406 mdiff.trivialdiffheader(len(data)) + data, |
402 # Flags not yet supported. | 407 # Flags not yet supported. |
403 0, | 408 0, |
404 ) | 409 ) |
405 | 410 |
406 added = cl.addgroup( | 411 cl.addgroup( |
407 iterrevisions(), linkrev, weakref.proxy(tr), addrevisioncb=onchangeset | 412 iterrevisions(), |
413 linkrev, | |
414 weakref.proxy(tr), | |
415 addrevisioncb=onchangeset, | |
416 duplicaterevisioncb=ondupchangeset, | |
408 ) | 417 ) |
409 | 418 |
410 progress.complete() | 419 progress.complete() |
411 | 420 |
412 return { | 421 return { |
514 ).result() | 523 ).result() |
515 | 524 |
516 # Chomp off header object. | 525 # Chomp off header object. |
517 next(objs) | 526 next(objs) |
518 | 527 |
519 added.extend( | 528 def onchangeset(cl, node): |
520 rootmanifest.addgroup( | 529 added.append(node) |
521 iterrevisions(objs, progress), | 530 |
522 linkrevs.__getitem__, | 531 rootmanifest.addgroup( |
523 weakref.proxy(tr), | 532 iterrevisions(objs, progress), |
524 ) | 533 linkrevs.__getitem__, |
534 weakref.proxy(tr), | |
535 addrevisioncb=onchangeset, | |
536 duplicaterevisioncb=onchangeset, | |
525 ) | 537 ) |
526 | 538 |
527 progress.complete() | 539 progress.complete() |
528 | 540 |
529 return { | 541 return { |