Patchwork [2,of,9] changegroup: add "vfs" argument to "writebundle()" for relative access via vfs

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 8, 2014, 4:07 p.m.
Message ID <84dd852c71cae8f87199.1394294827@juju>
Download mbox | patch
Permalink /patch/3893/
State Accepted
Commit c20f4898631e2f5f954d7e8afe5fc05b14b7e55f
Headers show

Comments

Katsunori FUJIWARA - March 8, 2014, 4:07 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1394294608 -32400
#      Sun Mar 09 01:03:28 2014 +0900
# Node ID 84dd852c71cae8f871996179ba6ee1e487ab9f6b
# Parent  d7aaef55c418c693aa67dc7f105b673535c370b3
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.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -57,7 +57,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.
@@ -70,7 +70,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")
@@ -110,7 +113,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':