Show More
@@ -274,20 +274,32 b' def make_file(repo, r, pat, node=None,' | |||||
274 | pathname), |
|
274 | pathname), | |
275 | mode) |
|
275 | mode) | |
276 |
|
276 | |||
277 |
def write_bundle(cg, filename, compress=True |
|
277 | def write_bundle(cg, filename=None, compress=True): | |
278 | """Write a bundle file, optionally without bz2 compression. |
|
278 | """Write a bundle file and return its filename. | |
279 |
|
279 | |||
280 | A file handle (fh) may be passed and is guaranteed to be closed. |
|
280 | Existing files will not be overwritten. | |
|
281 | If no filename is specified, a temporary file is created. | |||
|
282 | bz2 compression can be turned off. | |||
|
283 | The bundle file will be deleted in case of errors. | |||
281 | """ |
|
284 | """ | |
282 | if fh is None: |
|
|||
283 | fh = open(filename, "wb") |
|
|||
284 |
|
||||
285 | class nocompress(object): |
|
285 | class nocompress(object): | |
286 | def compress(self, x): |
|
286 | def compress(self, x): | |
287 | return x |
|
287 | return x | |
288 | def flush(self): |
|
288 | def flush(self): | |
289 | return "" |
|
289 | return "" | |
|
290 | ||||
|
291 | fh = None | |||
|
292 | cleanup = None | |||
290 | try: |
|
293 | try: | |
|
294 | if filename: | |||
|
295 | if os.path.exists(filename): | |||
|
296 | raise util.Abort(_("file '%s' already exists"), filename) | |||
|
297 | fh = open(filename, "wb") | |||
|
298 | else: | |||
|
299 | fd, filename = tempfile.mkstemp(suffix=".hg", prefix="hg-bundle-") | |||
|
300 | fh = os.fdopen(fd, "wb") | |||
|
301 | cleanup = filename | |||
|
302 | ||||
291 | if compress: |
|
303 | if compress: | |
292 | fh.write("HG10") |
|
304 | fh.write("HG10") | |
293 | z = bz2.BZ2Compressor(9) |
|
305 | z = bz2.BZ2Compressor(9) | |
@@ -300,11 +312,13 b' def write_bundle(cg, filename, compress=' | |||||
300 | break |
|
312 | break | |
301 | fh.write(z.compress(chunk)) |
|
313 | fh.write(z.compress(chunk)) | |
302 | fh.write(z.flush()) |
|
314 | fh.write(z.flush()) | |
303 | except: |
|
315 | cleanup = None | |
|
316 | return filename | |||
|
317 | finally: | |||
|
318 | if fh is not None: | |||
304 | fh.close() |
|
319 | fh.close() | |
305 | os.unlink(filename) |
|
320 | if cleanup is not None: | |
306 | raise |
|
321 | os.unlink(cleanup) | |
307 | fh.close() |
|
|||
308 |
|
322 | |||
309 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, |
|
323 | def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, | |
310 | changes=None, text=False, opts={}): |
|
324 | changes=None, text=False, opts={}): | |
@@ -1782,20 +1796,15 b' def incoming(ui, repo, source="default",' | |||||
1782 | return |
|
1796 | return | |
1783 |
|
1797 | |||
1784 | cleanup = None |
|
1798 | cleanup = None | |
|
1799 | try: | |||
1785 | fname = opts["bundle"] |
|
1800 | fname = opts["bundle"] | |
1786 | if fname: |
|
1801 | if fname or not other.local(): | |
1787 | # create a bundle (uncompressed if other repo is not local) |
|
1802 | # create a bundle (uncompressed if other repo is not local) | |
1788 | f = open(fname, "wb") |
|
|||
1789 | elif not other.local(): |
|
|||
1790 | # create an uncompressed temporary bundle |
|
|||
1791 | fd, fname = tempfile.mkstemp(suffix=".hg", prefix="hg-incoming-") |
|
|||
1792 | f = os.fdopen(fd, "wb") |
|
|||
1793 | cleanup = fname |
|
|||
1794 |
|
||||
1795 | if fname: |
|
|||
1796 | cg = other.changegroup(incoming, "incoming") |
|
1803 | cg = other.changegroup(incoming, "incoming") | |
1797 |
write_bundle(cg, fname, compress=other.local() |
|
1804 | fname = cleanup = write_bundle(cg, fname, compress=other.local()) | |
1798 | # write_bundle closed f for us. |
|
1805 | # keep written bundle? | |
|
1806 | if opts["bundle"]: | |||
|
1807 | cleanup = None | |||
1799 | if not other.local(): |
|
1808 | if not other.local(): | |
1800 | # use the created uncompressed bundlerepo |
|
1809 | # use the created uncompressed bundlerepo | |
1801 | other = bundlerepo.bundlerepository(ui, repo.root, fname) |
|
1810 | other = bundlerepo.bundlerepository(ui, repo.root, fname) | |
@@ -1813,9 +1822,10 b' def incoming(ui, repo, source="default",' | |||||
1813 | prev = (parents and parents[0]) or nullid |
|
1822 | prev = (parents and parents[0]) or nullid | |
1814 | dodiff(ui, ui, other, prev, n) |
|
1823 | dodiff(ui, ui, other, prev, n) | |
1815 | ui.write("\n") |
|
1824 | ui.write("\n") | |
1816 |
|
1825 | finally: | ||
|
1826 | if hasattr(other, 'close'): | |||
|
1827 | other.close() | |||
1817 | if cleanup: |
|
1828 | if cleanup: | |
1818 | other.close() # explicit close for unlink |
|
|||
1819 | os.unlink(cleanup) |
|
1829 | os.unlink(cleanup) | |
1820 |
|
1830 | |||
1821 | def init(ui, dest="."): |
|
1831 | def init(ui, dest="."): |
General Comments 0
You need to be logged in to leave comments.
Login now