mirror of
https://github.com/facebook/sapling.git
synced 2025-01-01 09:37:56 +03:00
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:
parent
a866710af5
commit
c9037da765
@ -231,21 +231,26 @@ class mutablebasepack(object):
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
if exc_type is None:
|
||||
if not self._closed:
|
||||
self.close()
|
||||
self.close()
|
||||
else:
|
||||
# Unclean exit
|
||||
try:
|
||||
self.opener.unlink(self.packpath)
|
||||
self.opener.unlink(self.idxpath)
|
||||
except Exception:
|
||||
pass
|
||||
self.abort()
|
||||
|
||||
def abort(self):
|
||||
# Unclean exit
|
||||
try:
|
||||
self.opener.unlink(self.packpath)
|
||||
self.opener.unlink(self.idxpath)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def writeraw(self, data):
|
||||
self.packfp.write(data)
|
||||
self.sha.update(data)
|
||||
|
||||
def close(self, ledger=None):
|
||||
if self._closed:
|
||||
return
|
||||
|
||||
sha = self.sha.hexdigest()
|
||||
self.packfp.close()
|
||||
self.writeindex()
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user