changeset 46371:0903d6b9b1df

repository: introduce register_changeset callback The new callback is called whenever a changeset is added to the repository (commit, unbundle or exchange). Since the bulk operations already parse the changeset (readfiles or full changesetrevision), always use the latter to avoid redundant lookups. The first consumer of the new interface needs to look at extra. Differential Revision: https://phab.mercurial-scm.org/D9780
author Joerg Sonnenberger <joerg@bec.de>
date Tue, 19 Jan 2021 00:20:53 +0100
parents cad17d50736c
children 3e91d9978bec
files mercurial/changegroup.py mercurial/commit.py mercurial/exchangev2.py mercurial/interfaces/repository.py mercurial/localrepo.py
diffstat 5 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/changegroup.py	Fri Jan 15 01:30:08 2021 +0100
+++ b/mercurial/changegroup.py	Tue Jan 19 00:20:53 2021 +0100
@@ -323,7 +323,10 @@
                     cgnodes.append(node)
 
             def onchangelog(cl, node):
-                efilesset.update(cl.readfiles(node))
+                rev = cl.rev(node)
+                ctx = cl.changelogrevision(rev)
+                efilesset.update(ctx.files)
+                repo.register_changeset(rev, ctx)
 
             self.changelogheader()
             deltas = self.deltaiter()
--- a/mercurial/commit.py	Fri Jan 15 01:30:08 2021 +0100
+++ b/mercurial/commit.py	Tue Jan 19 00:20:53 2021 +0100
@@ -97,6 +97,9 @@
             extra,
         )
         rev = repo[n].rev()
+        if oldtip != repo.changelog.tiprev():
+            repo.register_changeset(rev, repo.changelog.changelogrevision(rev))
+
         xp1, xp2 = p1.hex(), p2 and p2.hex() or b''
         repo.hook(
             b'pretxncommit',
--- a/mercurial/exchangev2.py	Fri Jan 15 01:30:08 2021 +0100
+++ b/mercurial/exchangev2.py	Tue Jan 19 00:20:53 2021 +0100
@@ -372,6 +372,8 @@
         # so we can set the linkrev accordingly when manifests are added.
         manifestnodes[rev] = revision.manifest
 
+        repo.register_changeset(rev, revision)
+
     nodesbyphase = {phase: set() for phase in phases.phasenames.values()}
     remotebookmarks = {}
 
--- a/mercurial/interfaces/repository.py	Fri Jan 15 01:30:08 2021 +0100
+++ b/mercurial/interfaces/repository.py	Tue Jan 19 00:20:53 2021 +0100
@@ -1641,6 +1641,14 @@
     def revbranchcache():
         pass
 
+    def register_changeset(rev, changelogrevision):
+        """Extension point for caches for new nodes.
+
+        Multiple consumers are expected to need parts of the changelogrevision,
+        so it is provided as optimization to avoid duplicate lookups. A simple
+        cache would be fragile when other revisions are accessed, too."""
+        pass
+
     def branchtip(branchtip, ignoremissing=False):
         """Return the tip node for a given branch."""
 
--- a/mercurial/localrepo.py	Fri Jan 15 01:30:08 2021 +0100
+++ b/mercurial/localrepo.py	Tue Jan 19 00:20:53 2021 +0100
@@ -2062,6 +2062,9 @@
             self._revbranchcache = branchmap.revbranchcache(self.unfiltered())
         return self._revbranchcache
 
+    def register_changeset(self, rev, changelogrevision):
+        pass
+
     def branchtip(self, branch, ignoremissing=False):
         """return the tip node for a given branch