Patchwork D9826: callback: add a new_cl_rev_callback

login
register
mail settings
Submitter phabricator
Date Jan. 18, 2021, 6:11 p.m.
Message ID <differential-rev-PHID-DREV-oczdshg3xzu4fnjc3vvx-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48139/
State New
Headers show

Comments

phabricator - Jan. 18, 2021, 6:11 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This will be useful for consistency and cache warming.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9826

AFFECTED FILES
  mercurial/changelog.py
  mercurial/localrepo.py
  mercurial/transaction.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -134,6 +134,7 @@ 
         releasefn=None,
         checkambigfiles=None,
         name='<unnamed>',
+        new_cl_rev_callback=None,
     ):
         """Begin a new transaction
 
@@ -168,6 +169,11 @@ 
             releasefn = lambda tr, success: None
         self._releasefn = releasefn
 
+        # A callback to do thing for any new changelog revision
+        if new_cl_rev_callback is None:
+            new_cl_rev_callback = lambda rev: None
+        self.new_cl_rev_callback = new_cl_rev_callback
+
         self._checkambigfiles = set()
         if checkambigfiles:
             self._checkambigfiles.update(checkambigfiles)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2380,6 +2380,7 @@ 
             releasefn=releasefn,
             checkambigfiles=_cachedfiles,
             name=desc,
+            new_cl_rev_callback=self.new_cl_rev_callback,
         )
         tr.changes[b'origrepolen'] = len(self)
         tr.changes[b'obsmarkers'] = set()
@@ -2633,6 +2634,9 @@ 
 
         return updater
 
+    def new_cl_rev_callback(self, rev):
+        """called when new revision are added to the repository"""
+
     @unfilteredmethod
     def updatecaches(self, tr=None, full=False):
         """warm appropriate caches
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -610,3 +610,12 @@ 
         # We track them in a list to preserve their order from the source bundle
         duplicates = transaction.changes.setdefault(b'revduplicates', [])
         duplicates.append(self.rev(node))
+
+    def _addrevision(self, rawtext, transaction, *args, **kwargs):
+        next_tip = len(self)
+        node = super(changelog, self)._addrevision(
+            rawtext, transaction, *args, **kwargs
+        )
+        if next_tip < len(self):
+            transaction.new_cl_rev_callback(next_tip)
+        return node