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, node, rawtext, transaction, *args, **kwargs): + next_tip = len(self) + node = super(changelog, self)._addrevision( + node, rawtext, transaction, *args, **kwargs + ) + if next_tip < len(self): + transaction.new_cl_rev_callback(next_tip) + return node 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/transaction.py b/mercurial/transaction.py --- a/mercurial/transaction.py +++ b/mercurial/transaction.py @@ -134,6 +134,7 @@ releasefn=None, checkambigfiles=None, name='', + 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)