Mercurial > public > mercurial-scm > hg-stable
diff mercurial/localrepo.py @ 24284:ff14b26fe5f4
hook: add a generic hook right before we commit a transaction
We are adding a 'txnclose' hook that will be run right before a transaction is
closed. Hooks running at that time will have access to the full transaction
content through both 'hookargs' content and on-disk reading. They will be able
to abort the transaction.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Mon, 09 Mar 2015 22:50:49 -0700 |
parents | db8679812f84 |
children | 6ddc86eedc3b |
line wrap: on
line diff
--- a/mercurial/localrepo.py Mon Mar 09 22:43:36 2015 -0700 +++ b/mercurial/localrepo.py Mon Mar 09 22:50:49 2015 -0700 @@ -915,17 +915,24 @@ renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] rp = report and report or self.ui.warn vfsmap = {'plain': self.vfs} # root of .hg/ - tr = transaction.transaction(rp, self.svfs, vfsmap, + # we must avoid cyclic reference between repo and transaction. + reporef = weakref.ref(self) + def validate(tr): + """will run pre-closing hooks""" + pending = lambda: tr.writepending() and self.root or "" + reporef().hook('pretxnclose', throw=True, pending=pending, + xnname=desc) + + tr = transaction.transaction(rp, self.sopener, vfsmap, "journal", "undo", aftertrans(renames), - self.store.createmode) + self.store.createmode, + validator=validate) # note: writing the fncache only during finalize mean that the file is # outdated when running hooks. As fncache is used for streaming clone, # this is not expected to break anything that happen during the hooks. tr.addfinalize('flush-fncache', self.store.write) - # we must avoid cyclic reference between repo and transaction. - reporef = weakref.ref(self) def txnclosehook(tr2): """To be run if transaction is successful, will schedule a hook run """