##// END OF EJS Templates
create a readbundle function
Matt Mackall -
r3660:8500a13e default
parent child Browse files
Show More
@@ -93,3 +93,23 b' def writebundle(cg, filename, compress):'
93 fh.close()
93 fh.close()
94 if cleanup is not None:
94 if cleanup is not None:
95 os.unlink(cleanup)
95 os.unlink(cleanup)
96
97 def readbundle(fh):
98 header = fh.read(6)
99 if not header.startswith("HG"):
100 raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
101 elif not header.startswith("HG10"):
102 raise util.Abort(_("%s: unknown bundle version") % fname)
103
104 if header == "HG10BZ":
105 def generator(f):
106 zd = bz2.BZ2Decompressor()
107 zd.decompress("BZ")
108 for chunk in util.filechunkiter(f, 4096):
109 yield zd.decompress(chunk)
110 return util.chunkbuffer(generator(fh))
111 elif header == "HG10UN":
112 return fh
113
114 raise util.Abort(_("%s: unknown bundle compression type")
115 % fname)
@@ -11,7 +11,7 b' from i18n import gettext as _'
11 demandload(globals(), "os re sys signal imp urllib pdb shlex")
11 demandload(globals(), "os re sys signal imp urllib pdb shlex")
12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
12 demandload(globals(), "fancyopts ui hg util lock revlog bundlerepo")
13 demandload(globals(), "difflib patch time")
13 demandload(globals(), "difflib patch time")
14 demandload(globals(), "traceback errno version atexit bz2")
14 demandload(globals(), "traceback errno version atexit")
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
15 demandload(globals(), "archival changegroup cmdutil hgweb.server sshserver")
16
16
17 class UnknownCommand(Exception):
17 class UnknownCommand(Exception):
@@ -2195,29 +2195,8 b' def unbundle(ui, repo, fname, **opts):'
2195 Apply a compressed changegroup file generated by the bundle
2195 Apply a compressed changegroup file generated by the bundle
2196 command.
2196 command.
2197 """
2197 """
2198 f = urllib.urlopen(fname)
2198 gen = changegroup.readbundle(urllib.urlopen(fname))
2199
2199 modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
2200 header = f.read(6)
2201 if not header.startswith("HG"):
2202 raise util.Abort(_("%s: not a Mercurial bundle file") % fname)
2203 elif not header.startswith("HG10"):
2204 raise util.Abort(_("%s: unknown bundle version") % fname)
2205 elif header == "HG10BZ":
2206 def generator(f):
2207 zd = bz2.BZ2Decompressor()
2208 zd.decompress("BZ")
2209 for chunk in f:
2210 yield zd.decompress(chunk)
2211 elif header == "HG10UN":
2212 def generator(f):
2213 for chunk in f:
2214 yield chunk
2215 else:
2216 raise util.Abort(_("%s: unknown bundle compression type")
2217 % fname)
2218 gen = generator(util.filechunkiter(f, 4096))
2219 modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle',
2220 'bundle:' + fname)
2221 return postincoming(ui, repo, modheads, opts['update'])
2200 return postincoming(ui, repo, modheads, opts['update'])
2222
2201
2223 def update(ui, repo, node=None, merge=False, clean=False, force=None,
2202 def update(ui, repo, node=None, merge=False, clean=False, force=None,
General Comments 0
You need to be logged in to leave comments. Login now