mercurial/transaction.py
changeset 24283 ef22cfff7052
parent 23904 d251da5e0e84
child 24721 774ee9800146
--- a/mercurial/transaction.py	Mon Mar 09 22:36:56 2015 -0700
+++ b/mercurial/transaction.py	Mon Mar 09 22:43:36 2015 -0700
@@ -83,7 +83,7 @@
 
 class transaction(object):
     def __init__(self, report, opener, vfsmap, journalname, undoname=None,
-                 after=None, createmode=None):
+                 after=None, createmode=None, validator=None):
         """Begin a new transaction
 
         Begins a new transaction that allows rolling back writes in the event of
@@ -107,6 +107,12 @@
         self.journal = journalname
         self.undoname = undoname
         self._queue = []
+        # A callback to validate transaction content before closing it.
+        # should raise exception is anything is wrong.
+        # target user is repository hooks.
+        if validator is None:
+            validator = lambda tr: None
+        self.validator = validator
         # a dict of arguments to be passed to hooks
         self.hookargs = {}
         self.file = opener.open(self.journal, "w")
@@ -378,6 +384,7 @@
     def close(self):
         '''commit the transaction'''
         if self.count == 1:
+            self.validator(self)  # will raise exception if needed
             self._generatefiles()
             categories = sorted(self._finalizecallback)
             for cat in categories: