remotefilelog: refactor mutablepack close/abort

Summary:
This makes mutablepacks close and abort function accessible from outside the
__exit__ logic. This will be useful later when we tie the lifetime of a
mutablepack to a transaction.

Test Plan: Ran the tests

Reviewers: #mercurial, quark

Reviewed By: quark

Subscribers: mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4055730

Signature: t1:4055730:1477059602:ffdfd66e65279ddf3ff43d7c2ee65b00f1fd2600
This commit is contained in:
Durham Goode 2016-10-21 11:02:17 -07:00
parent a866710af5
commit c9037da765
2 changed files with 16 additions and 8 deletions

View File

@ -231,9 +231,11 @@ class mutablebasepack(object):
def __exit__(self, exc_type, exc_value, traceback):
if exc_type is None:
if not self._closed:
self.close()
else:
self.abort()
def abort(self):
# Unclean exit
try:
self.opener.unlink(self.packpath)
@ -246,6 +248,9 @@ class mutablebasepack(object):
self.sha.update(data)
def close(self, ledger=None):
if self._closed:
return
sha = self.sha.hexdigest()
self.packfp.close()
self.writeindex()

View File

@ -354,6 +354,9 @@ class mutablehistorypack(basepack.mutablebasepack):
self.entries[node] = node
def close(self, ledger=None):
if self._closed:
return
if self.currentfile:
self._writependingsection()