changegroup: add "vfs" argument to "writebundle()" for relative access via vfs
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sun, 09 Mar 2014 01:03:28 +0900
changeset 20976 c20f4898631e
parent 20975 37cdf1fca1b2
child 20977 a57dcd11be34
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.
mercurial/changegroup.py
--- a/mercurial/changegroup.py	Sun Mar 09 01:03:28 2014 +0900
+++ b/mercurial/changegroup.py	Sun Mar 09 01:03:28 2014 +0900
@@ -59,7 +59,7 @@
 # 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,7 +72,10 @@
     cleanup = None
     try:
         if filename:
-            fh = open(filename, "wb")
+            if vfs:
+                fh = vfs.open(filename, "wb")
+            else:
+                fh = open(filename, "wb")
         else:
             fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg")
             fh = os.fdopen(fd, "wb")
@@ -112,7 +115,10 @@
         if fh is not None:
             fh.close()
         if cleanup is not None:
-            os.unlink(cleanup)
+            if filename and vfs:
+                vfs.unlink(cleanup)
+            else:
+                os.unlink(cleanup)
 
 def decompressor(fh, alg):
     if alg == 'UN':