##// END OF EJS Templates
Delete bundle file of hg incoming in case of errors, preserve existing files....
Thomas Arendsen Hein -
r1974:0d54675c default
parent child Browse files
Show More
@@ -274,20 +274,32 b' def make_file(repo, r, pat, node=None,'
274 274 pathname),
275 275 mode)
276 276
277 def write_bundle(cg, filename, compress=True, fh=None):
278 """Write a bundle file, optionally without bz2 compression.
279
280 A file handle (fh) may be passed and is guaranteed to be closed.
277 def write_bundle(cg, filename=None, compress=True):
278 """Write a bundle file and return its filename.
279
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 285 class nocompress(object):
286 286 def compress(self, x):
287 287 return x
288 288 def flush(self):
289 289 return ""
290
291 fh = None
292 cleanup = None
290 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 303 if compress:
292 304 fh.write("HG10")
293 305 z = bz2.BZ2Compressor(9)
@@ -300,11 +312,13 b' def write_bundle(cg, filename, compress='
300 312 break
301 313 fh.write(z.compress(chunk))
302 314 fh.write(z.flush())
303 except:
315 cleanup = None
316 return filename
317 finally:
318 if fh is not None:
304 319 fh.close()
305 os.unlink(filename)
306 raise
307 fh.close()
320 if cleanup is not None:
321 os.unlink(cleanup)
308 322
309 323 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
310 324 changes=None, text=False, opts={}):
@@ -1782,20 +1796,15 b' def incoming(ui, repo, source="default",'
1782 1796 return
1783 1797
1784 1798 cleanup = None
1799 try:
1785 1800 fname = opts["bundle"]
1786 if fname:
1801 if fname or not other.local():
1787 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 1803 cg = other.changegroup(incoming, "incoming")
1797 write_bundle(cg, fname, compress=other.local(), fh=f)
1798 # write_bundle closed f for us.
1804 fname = cleanup = write_bundle(cg, fname, compress=other.local())
1805 # keep written bundle?
1806 if opts["bundle"]:
1807 cleanup = None
1799 1808 if not other.local():
1800 1809 # use the created uncompressed bundlerepo
1801 1810 other = bundlerepo.bundlerepository(ui, repo.root, fname)
@@ -1813,9 +1822,10 b' def incoming(ui, repo, source="default",'
1813 1822 prev = (parents and parents[0]) or nullid
1814 1823 dodiff(ui, ui, other, prev, n)
1815 1824 ui.write("\n")
1816
1825 finally:
1826 if hasattr(other, 'close'):
1827 other.close()
1817 1828 if cleanup:
1818 other.close() # explicit close for unlink
1819 1829 os.unlink(cleanup)
1820 1830
1821 1831 def init(ui, dest="."):
General Comments 0
You need to be logged in to leave comments. Login now