mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
changegroup: add "vfs" argument to "writebundle()" for relative access via vfs
Before this patch, filename specified to "changegroup.writebundle()" should be absolute one. In some cases, they should be relative to repository root, store and so on (backup before strip, for example). This patch adds "vfs" argument to "writebundle()", and makes "writebundle()" open (and unlink) "filename" via vfs for relative access, if both filename and vfs are specified.
This commit is contained in:
parent
836e13a2f2
commit
01e064edbb
@ -59,7 +59,7 @@ bundletypes = {
|
||||
# hgweb uses this list to communicate its preferred type
|
||||
bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN']
|
||||
|
||||
def writebundle(cg, filename, bundletype):
|
||||
def writebundle(cg, filename, bundletype, vfs=None):
|
||||
"""Write a bundle file and return its filename.
|
||||
|
||||
Existing files will not be overwritten.
|
||||
@ -72,6 +72,9 @@ def writebundle(cg, filename, bundletype):
|
||||
cleanup = None
|
||||
try:
|
||||
if filename:
|
||||
if vfs:
|
||||
fh = vfs.open(filename, "wb")
|
||||
else:
|
||||
fh = open(filename, "wb")
|
||||
else:
|
||||
fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
|
||||
@ -112,6 +115,9 @@ def writebundle(cg, filename, bundletype):
|
||||
if fh is not None:
|
||||
fh.close()
|
||||
if cleanup is not None:
|
||||
if filename and vfs:
|
||||
vfs.unlink(cleanup)
|
||||
else:
|
||||
os.unlink(cleanup)
|
||||
|
||||
def decompressor(fh, alg):
|
||||
|
Loading…
Reference in New Issue
Block a user