mercurial/commands.py
changeset 1943 8198c60f7914
parent 1940 7ae177a70f54
child 1944 fdf40c9b3306
equal deleted inserted replaced
1942:9da45de3118d 1943:8198c60f7914
   272         return pat
   272         return pat
   273     return open(make_filename(repo, r, pat, node, total, seqno, revwidth,
   273     return open(make_filename(repo, r, pat, node, total, seqno, revwidth,
   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:
   280         node1 = repo.dirstate.parents()[0]
   306         node1 = repo.dirstate.parents()[0]
   281     # reading the data for node1 early allows it to play nicely
   307     # reading the data for node1 early allows it to play nicely
   828     extension is ".hg".
   854     extension is ".hg".
   829 
   855 
   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
   854 
   867 
   855     Print the specified files as they were at the given revision.
   868     Print the specified files as they were at the given revision.