Mercurial > public > mercurial-scm > hg
comparison mercurial/changegroup.py @ 20976:c20f4898631e
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.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sun, 09 Mar 2014 01:03:28 +0900 |
parents | 63659b809021 |
children | 5b58714e97ed |
comparison
equal
deleted
inserted
replaced
20975:37cdf1fca1b2 | 20976:c20f4898631e |
---|---|
57 } | 57 } |
58 | 58 |
59 # hgweb uses this list to communicate its preferred type | 59 # hgweb uses this list to communicate its preferred type |
60 bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN'] | 60 bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN'] |
61 | 61 |
62 def writebundle(cg, filename, bundletype): | 62 def writebundle(cg, filename, bundletype, vfs=None): |
63 """Write a bundle file and return its filename. | 63 """Write a bundle file and return its filename. |
64 | 64 |
65 Existing files will not be overwritten. | 65 Existing files will not be overwritten. |
66 If no filename is specified, a temporary file is created. | 66 If no filename is specified, a temporary file is created. |
67 bz2 compression can be turned off. | 67 bz2 compression can be turned off. |
70 | 70 |
71 fh = None | 71 fh = None |
72 cleanup = None | 72 cleanup = None |
73 try: | 73 try: |
74 if filename: | 74 if filename: |
75 fh = open(filename, "wb") | 75 if vfs: |
76 fh = vfs.open(filename, "wb") | |
77 else: | |
78 fh = open(filename, "wb") | |
76 else: | 79 else: |
77 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg") | 80 fd, filename = tempfile.mkstemp(prefix="hg-bundle-", suffix=".hg") |
78 fh = os.fdopen(fd, "wb") | 81 fh = os.fdopen(fd, "wb") |
79 cleanup = filename | 82 cleanup = filename |
80 | 83 |
110 return filename | 113 return filename |
111 finally: | 114 finally: |
112 if fh is not None: | 115 if fh is not None: |
113 fh.close() | 116 fh.close() |
114 if cleanup is not None: | 117 if cleanup is not None: |
115 os.unlink(cleanup) | 118 if filename and vfs: |
119 vfs.unlink(cleanup) | |
120 else: | |
121 os.unlink(cleanup) | |
116 | 122 |
117 def decompressor(fh, alg): | 123 def decompressor(fh, alg): |
118 if alg == 'UN': | 124 if alg == 'UN': |
119 return fh | 125 return fh |
120 elif alg == 'GZ': | 126 elif alg == 'GZ': |