--- a/mercurial/localrepo.py Tue Feb 28 11:49:35 2006 -0600
+++ b/mercurial/localrepo.py Tue Feb 28 12:24:54 2006 -0600
@@ -13,6 +13,8 @@
demandload(globals(), "re lock transaction tempfile stat mdiff errno")
class localrepository(object):
+ def __del__(self):
+ self.transhandle = None
def __init__(self, ui, path=None, create=0):
if not path:
p = os.getcwd()
@@ -37,6 +39,7 @@
self.nodetagscache = None
self.encodepats = None
self.decodepats = None
+ self.transhandle = None
if create:
os.mkdir(self.path)
@@ -215,6 +218,10 @@
return self.wopener(filename, 'w').write(data)
def transaction(self):
+ tr = self.transhandle
+ if tr != None and tr.running():
+ return tr.nest()
+
# save dirstate for undo
try:
ds = self.opener("dirstate").read()
@@ -222,13 +229,11 @@
ds = ""
self.opener("journal.dirstate", "w").write(ds)
- def after():
- util.rename(self.join("journal"), self.join("undo"))
- util.rename(self.join("journal.dirstate"),
- self.join("undo.dirstate"))
-
- return transaction.transaction(self.ui.warn, self.opener,
- self.join("journal"), after)
+ tr = transaction.transaction(self.ui.warn, self.opener,
+ self.join("journal"),
+ aftertrans(self.path))
+ self.transhandle = tr
+ return tr
def recover(self):
l = self.lock()
@@ -1879,3 +1884,13 @@
if errors[0]:
self.ui.warn(_("%d integrity errors encountered!\n") % errors[0])
return 1
+
+# used to avoid circular references so destructors work
+def aftertrans(base):
+ p = base
+ def a():
+ util.rename(os.path.join(p, "journal"), os.path.join(p, "undo"))
+ util.rename(os.path.join(p, "journal.dirstate"),
+ os.path.join(p, "undo.dirstate"))
+ return a
+