[PATCH 2 of 5] revlog: support closing files via a caller-specified mechanism
Gregory Szorc
gregory.szorc at gmail.com
Wed Sep 30 00:36:28 CDT 2015
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1443487562 25200
# Mon Sep 28 17:46:02 2015 -0700
# Node ID 6433c97a719dec3532379deec5cc178270b0cdc6
# Parent f578fedbeb3ce63fff0e3fdbe7b2424e9cdd399a
revlog: support closing files via a caller-specified mechanism
This patch allows addgroup() to receive a function that will be called
in lieu of closing the handles within addgroup(). We will soon hook this
up to the file closer utility that was just introduced.
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1441,9 +1441,10 @@ class revlog(object):
ifh.write(data[0])
ifh.write(data[1])
self.checkinlinesize(transaction, ifh)
- def addgroup(self, bundle, linkmapper, transaction, addrevisioncb=None):
+ def addgroup(self, bundle, linkmapper, transaction, addrevisioncb=None,
+ closecb=None):
"""
add a delta group
given a set of deltas, add them to the revision log. the
@@ -1451,8 +1452,12 @@ class revlog(object):
log, the rest are against the previous delta.
If ``addrevisioncb`` is defined, it will be called with arguments of
this revlog and the node that was added.
+
+ If ``closecb`` is defined, it will be called with open file handles
+ that will no longer be used and the file handles will not be closed
+ by this function.
"""
# track the base of the current delta log
content = []
@@ -1540,11 +1545,16 @@ class revlog(object):
ifh.close()
dfh = self.opener(self.datafile, "a+")
ifh = self.opener(self.indexfile, "a+")
finally:
- if dfh:
- dfh.close()
- ifh.close()
+ if closecb:
+ if dfh:
+ closecb(dfh)
+ closecb(ifh)
+ else:
+ if dfh:
+ dfh.close()
+ ifh.close()
return content
def iscensored(self, rev):
More information about the Mercurial-devel
mailing list