diff mercurial/obsutil.py @ 45075:04ef381000a8

hooklib: fix detection of successors for changeset_obsoleted Provide a hook for obsutil.getobsolete to be used with either a transaction or the changes item of the transaction, since hooks only have access to the latter. Use that to find the correct list of revisions with obsmarkers, even new ones, and then filter out revisions with known successors. Move the processing from pretxnclose to txnclose as the transaction access itself is no longer necessary. This is more in line with notify and ensures that sanity checks can abort the transaction first. Differential Revision: https://phab.mercurial-scm.org/D8575
author Joerg Sonnenberger <joerg@bec.de>
date Thu, 21 May 2020 18:18:50 +0200
parents 9d2b2df2c2ba
children 89a2afe31e82
line wrap: on
line diff
--- a/mercurial/obsutil.py	Thu Jul 09 20:46:52 2020 -0700
+++ b/mercurial/obsutil.py	Thu May 21 18:18:50 2020 +0200
@@ -13,6 +13,7 @@
 from . import (
     diffutil,
     encoding,
+    error,
     node as nodemod,
     phases,
     pycompat,
@@ -481,14 +482,23 @@
     return effects
 
 
-def getobsoleted(repo, tr):
-    """return the set of pre-existing revisions obsoleted by a transaction"""
+def getobsoleted(repo, tr=None, changes=None):
+    """return the set of pre-existing revisions obsoleted by a transaction
+
+    Either the transaction or changes item of the transaction (for hooks)
+    must be provided, but not both.
+    """
+    if (tr is None) == (changes is None):
+        e = b"exactly one of tr and changes must be provided"
+        raise error.ProgrammingError(e)
     torev = repo.unfiltered().changelog.index.get_rev
     phase = repo._phasecache.phase
     succsmarkers = repo.obsstore.successors.get
     public = phases.public
-    addedmarkers = tr.changes[b'obsmarkers']
-    origrepolen = tr.changes[b'origrepolen']
+    if changes is None:
+        changes = tr.changes
+    addedmarkers = changes[b'obsmarkers']
+    origrepolen = changes[b'origrepolen']
     seenrevs = set()
     obsoleted = set()
     for mark in addedmarkers: