mirror of
https://github.com/facebook/sapling.git
synced 2025-01-04 03:06:30 +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):
|
def __exit__(self, exc_type, exc_value, traceback):
|
||||||
if exc_type is None:
|
if exc_type is None:
|
||||||
if not self._closed:
|
self.close()
|
||||||
self.close()
|
|
||||||
else:
|
else:
|
||||||
# Unclean exit
|
self.abort()
|
||||||
try:
|
|
||||||
self.opener.unlink(self.packpath)
|
def abort(self):
|
||||||
self.opener.unlink(self.idxpath)
|
# Unclean exit
|
||||||
except Exception:
|
try:
|
||||||
pass
|
self.opener.unlink(self.packpath)
|
||||||
|
self.opener.unlink(self.idxpath)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
def writeraw(self, data):
|
def writeraw(self, data):
|
||||||
self.packfp.write(data)
|
self.packfp.write(data)
|
||||||
self.sha.update(data)
|
self.sha.update(data)
|
||||||
|
|
||||||
def close(self, ledger=None):
|
def close(self, ledger=None):
|
||||||
|
if self._closed:
|
||||||
|
return
|
||||||
|
|
||||||
sha = self.sha.hexdigest()
|
sha = self.sha.hexdigest()
|
||||||
self.packfp.close()
|
self.packfp.close()
|
||||||
self.writeindex()
|
self.writeindex()
|
||||||
|
@ -354,6 +354,9 @@ class mutablehistorypack(basepack.mutablebasepack):
|
|||||||
self.entries[node] = node
|
self.entries[node] = node
|
||||||
|
|
||||||
def close(self, ledger=None):
|
def close(self, ledger=None):
|
||||||
|
if self._closed:
|
||||||
|
return
|
||||||
|
|
||||||
if self.currentfile:
|
if self.currentfile:
|
||||||
self._writependingsection()
|
self._writependingsection()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user