##// END OF EJS Templates
refactor the bundle writing code, since we will reuse it later
Benoit Boissinot -
r1943:8198c60f default
parent child Browse files
Show More
@@ -274,6 +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, fh=None):
278 if fh is None:
279 fh = open(filename, "wb")
280
281 class nocompress(object):
282 def compress(self, x):
283 return x
284 def flush(self):
285 return ""
286 try:
287 if compress:
288 fh.write("HG10")
289 z = bz2.BZ2Compressor(9)
290 else:
291 fh.write("HG11")
292 z = nocompress()
293 while 1:
294 chunk = cg.read(4096)
295 if not chunk:
296 break
297 fh.write(z.compress(chunk))
298 fh.write(z.flush())
299 except:
300 os.unlink(filename)
301 raise
302
277 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
303 def dodiff(fp, ui, repo, node1, node2, files=None, match=util.always,
278 changes=None, text=False, opts={}):
304 changes=None, text=False, opts={}):
279 if not node1:
305 if not node1:
@@ -830,24 +856,11 b' def bundle(ui, repo, fname, dest="defaul'
830 Unlike import/export, this exactly preserves all changeset
856 Unlike import/export, this exactly preserves all changeset
831 contents including permissions, rename data, and revision history.
857 contents including permissions, rename data, and revision history.
832 """
858 """
833 f = open(fname, "wb")
834 dest = ui.expandpath(dest)
859 dest = ui.expandpath(dest)
835 other = hg.repository(ui, dest)
860 other = hg.repository(ui, dest)
836 o = repo.findoutgoing(other)
861 o = repo.findoutgoing(other)
837 cg = repo.changegroup(o, 'bundle')
862 cg = repo.changegroup(o, 'bundle')
838
863 write_bundle(cg, fname)
839 try:
840 f.write("HG10")
841 z = bz2.BZ2Compressor(9)
842 while 1:
843 chunk = cg.read(4096)
844 if not chunk:
845 break
846 f.write(z.compress(chunk))
847 f.write(z.flush())
848 except:
849 os.unlink(fname)
850 raise
851
864
852 def cat(ui, repo, file1, *pats, **opts):
865 def cat(ui, repo, file1, *pats, **opts):
853 """output the latest or given revisions of files
866 """output the latest or given revisions of files
General Comments 0
You need to be logged in to leave comments. Login now