[PATCH 3 of 7 V2] transaction: add onclose/onabort hook for pre-close logic
Durham Goode
durham at fb.com
Mon Mar 31 18:19:45 CDT 2014
# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1395701867 25200
# Mon Mar 24 15:57:47 2014 -0700
# Node ID f85f9ea96d16e180de3e38cfc468e53441f41743
# Parent a4fddbaf22f873d6d700be4b7d3842457d3680aa
transaction: add onclose/onabort hook for pre-close logic
Adds an optional onclose parameter to transactions that gets called just before
the transaction is committed. This allows things that build up data over the
course of the transaction (like the fncache) to commit their data.
Also adds onabort. It's not used, but will allow extensions to hook into onclose
and onabort to provide transaction support.
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -42,12 +42,15 @@
opener.unlink(journal)
class transaction(object):
- def __init__(self, report, opener, journal, after=None, createmode=None):
+ def __init__(self, report, opener, journal, after=None, createmode=None,
+ onclose=None, onabort=None):
self.count = 1
self.usages = 1
self.report = report
self.opener = opener
self.after = after
+ self.onclose = onclose
+ self.onabort = onabort
self.entries = []
self.map = {}
self.journal = journal
@@ -126,6 +129,9 @@
@active
def close(self):
'''commit the transaction'''
+ if self.count == 1 and self.onclose:
+ self.onclose()
+
self.count -= 1
if self.count != 0:
return
@@ -149,6 +155,9 @@
self.usages = 0
self.file.close()
+ if self.onabort:
+ self.onabort()
+
try:
if not self.entries:
if self.journal:
More information about the Mercurial-devel
mailing list