comparison mercurial/changegroup.py @ 51392:a0d88b021a98

unbundle: faster computation of changed heads To compute the set of changed heads it's sufficient to look at the recent commits, instead of looking at all heads currently in existence.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 21 Dec 2023 17:38:04 +0000
parents d718eddf01d9
children 493034cc3265
comparison
equal deleted inserted replaced
51391:3a7ef1398385 51392:a0d88b021a98
516 516
517 # write changelog data to temp files so concurrent readers 517 # write changelog data to temp files so concurrent readers
518 # will not see an inconsistent view 518 # will not see an inconsistent view
519 cl = repo.changelog 519 cl = repo.changelog
520 cl.delayupdate(tr) 520 cl.delayupdate(tr)
521 oldheads = set(cl.heads()) 521 oldrevcount = len(cl)
522 522
523 trp = weakref.proxy(tr) 523 trp = weakref.proxy(tr)
524 # pull off the changeset group 524 # pull off the changeset group
525 repo.ui.status(_(b"adding changesets\n")) 525 repo.ui.status(_(b"adding changesets\n"))
526 clstart = len(cl) 526 clstart = len(cl)
671 tr.changes[b'changegroup-count-changesets'] += changesets 671 tr.changes[b'changegroup-count-changesets'] += changesets
672 tr.changes[b'changegroup-count-revisions'] += newrevs 672 tr.changes[b'changegroup-count-revisions'] += newrevs
673 tr.changes[b'changegroup-count-files'] += newfiles 673 tr.changes[b'changegroup-count-files'] += newfiles
674 674
675 deltaheads = 0 675 deltaheads = 0
676 if oldheads: 676 newrevcount = len(cl)
677 heads = cl.heads() 677 heads_removed, heads_added = cl.diffheads(oldrevcount, newrevcount)
678 deltaheads += len(heads) - len(oldheads) 678 deltaheads += len(heads_added) - len(heads_removed)
679 for h in heads: 679 for h in heads_added:
680 if h not in oldheads and repo[h].closesbranch(): 680 if repo[h].closesbranch():
681 deltaheads -= 1 681 deltaheads -= 1
682 682
683 # see previous comment about checking ui.quiet 683 # see previous comment about checking ui.quiet
684 if not repo.ui.quiet: 684 if not repo.ui.quiet:
685 tr.changes[b'changegroup-count-heads'] += deltaheads 685 tr.changes[b'changegroup-count-heads'] += deltaheads
686 repo.invalidatevolatilesets() 686 repo.invalidatevolatilesets()
744 args = hookargs.copy() 744 args = hookargs.copy()
745 args[b'node'] = hex(cl.node(rev)) 745 args[b'node'] = hex(cl.node(rev))
746 del args[b'node_last'] 746 del args[b'node_last']
747 repo.hook(b"incoming", **pycompat.strkwargs(args)) 747 repo.hook(b"incoming", **pycompat.strkwargs(args))
748 748
749 newheads = [h for h in repo.heads() if h not in oldheads]
750 repo.ui.log( 749 repo.ui.log(
751 b"incoming", 750 b"incoming",
752 b"%d incoming changes - new heads: %s\n", 751 b"%d incoming changes - new heads: %s\n",
753 len(added), 752 len(added),
754 b', '.join([hex(c[:6]) for c in newheads]), 753 b', '.join([hex(c[:6]) for c in heads_added]),
755 ) 754 )
756 755
757 tr.addpostclose( 756 tr.addpostclose(
758 b'changegroup-runhooks-%020i' % clstart, 757 b'changegroup-runhooks-%020i' % clstart,
759 lambda tr: repo._afterlock(runhooks), 758 lambda tr: repo._afterlock(runhooks),
1733 # have sent. 1732 # have sent.
1734 if ( 1733 if (
1735 x in self._fullclnodes 1734 x in self._fullclnodes
1736 or cl.rev(x) in self._precomputedellipsis 1735 or cl.rev(x) in self._precomputedellipsis
1737 ): 1736 ):
1738
1739 manifestnode = c.manifest 1737 manifestnode = c.manifest
1740 # Record the first changeset introducing this manifest 1738 # Record the first changeset introducing this manifest
1741 # version. 1739 # version.
1742 manifests.setdefault(manifestnode, x) 1740 manifests.setdefault(manifestnode, x)
1743 # Set this narrow-specific dict so we have the lowest 1741 # Set this narrow-specific dict so we have the lowest
1992 ) 1990 )
1993 1991
1994 clrevtolocalrev.clear() 1992 clrevtolocalrev.clear()
1995 1993
1996 linkrevnodes = linknodes(filerevlog, fname) 1994 linkrevnodes = linknodes(filerevlog, fname)
1995
1997 # Lookup for filenodes, we collected the linkrev nodes above in the 1996 # Lookup for filenodes, we collected the linkrev nodes above in the
1998 # fastpath case and with lookupmf in the slowpath case. 1997 # fastpath case and with lookupmf in the slowpath case.
1999 def lookupfilelog(x): 1998 def lookupfilelog(x):
2000 return linkrevnodes[x] 1999 return linkrevnodes[x]
2001 2000