Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
24283:ef22cfff7052 | 24284:ff14b26fe5f4 |
---|---|
913 | 913 |
914 self._writejournal(desc) | 914 self._writejournal(desc) |
915 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | 915 renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
916 rp = report and report or self.ui.warn | 916 rp = report and report or self.ui.warn |
917 vfsmap = {'plain': self.vfs} # root of .hg/ | 917 vfsmap = {'plain': self.vfs} # root of .hg/ |
918 tr = transaction.transaction(rp, self.svfs, vfsmap, | 918 # we must avoid cyclic reference between repo and transaction. |
919 reporef = weakref.ref(self) | |
920 def validate(tr): | |
921 """will run pre-closing hooks""" | |
922 pending = lambda: tr.writepending() and self.root or "" | |
923 reporef().hook('pretxnclose', throw=True, pending=pending, | |
924 xnname=desc) | |
925 | |
926 tr = transaction.transaction(rp, self.sopener, vfsmap, | |
919 "journal", | 927 "journal", |
920 "undo", | 928 "undo", |
921 aftertrans(renames), | 929 aftertrans(renames), |
922 self.store.createmode) | 930 self.store.createmode, |
931 validator=validate) | |
923 # note: writing the fncache only during finalize mean that the file is | 932 # note: writing the fncache only during finalize mean that the file is |
924 # outdated when running hooks. As fncache is used for streaming clone, | 933 # outdated when running hooks. As fncache is used for streaming clone, |
925 # this is not expected to break anything that happen during the hooks. | 934 # this is not expected to break anything that happen during the hooks. |
926 tr.addfinalize('flush-fncache', self.store.write) | 935 tr.addfinalize('flush-fncache', self.store.write) |
927 # we must avoid cyclic reference between repo and transaction. | |
928 reporef = weakref.ref(self) | |
929 def txnclosehook(tr2): | 936 def txnclosehook(tr2): |
930 """To be run if transaction is successful, will schedule a hook run | 937 """To be run if transaction is successful, will schedule a hook run |
931 """ | 938 """ |
932 def hook(): | 939 def hook(): |
933 reporef().hook('txnclose', throw=False, txnname=desc, | 940 reporef().hook('txnclose', throw=False, txnname=desc, |