Mercurial > hg
changeset 1943:8198c60f7914
refactor the bundle writing code, since we will reuse it later
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Mon, 13 Mar 2006 03:54:23 +0100 |
parents | 9da45de3118d |
children | fdf40c9b3306 |
files | mercurial/commands.py |
diffstat | 1 files changed, 27 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/commands.py Mon Mar 13 03:54:23 2006 +0100 +++ b/mercurial/commands.py Mon Mar 13 03:54:23 2006 +0100 @@ -274,6 +274,32 @@ pathname), mode) +def write_bundle(cg, filename, compress=True, fh=None): + if fh is None: + fh = open(filename, "wb") + + class nocompress(object): + def compress(self, x): + return x + def flush(self): + return "" + try: + if compress: + fh.write("HG10") + z = bz2.BZ2Compressor(9) + else: + fh.write("HG11") + z = nocompress() + while 1: + chunk = cg.read(4096) + if not chunk: + break + fh.write(z.compress(chunk)) + fh.write(z.flush()) + except: + os.unlink(filename) + raise + def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always, changes=None, text=False, opts={}): if not node1: @@ -830,24 +856,11 @@ Unlike import/export, this exactly preserves all changeset contents including permissions, rename data, and revision history. """ - f = open(fname, "wb") dest = ui.expandpath(dest) other = hg.repository(ui, dest) o = repo.findoutgoing(other) cg = repo.changegroup(o, 'bundle') - - try: - f.write("HG10") - z = bz2.BZ2Compressor(9) - while 1: - chunk = cg.read(4096) - if not chunk: - break - f.write(z.compress(chunk)) - f.write(z.flush()) - except: - os.unlink(fname) - raise + write_bundle(cg, fname) def cat(ui, repo, file1, *pats, **opts): """output the latest or given revisions of files