##// END OF EJS Templates
bundle: unify/refactor unbundle/readbundle
Matt Mackall -
r12042:210049a8 default
parent child Browse files
Show More
@@ -138,24 +138,24 b' def decompressor(fh, alg):'
138 raise util.Abort("unknown bundle compression '%s'" % alg)
138 raise util.Abort("unknown bundle compression '%s'" % alg)
139 return generator(fh)
139 return generator(fh)
140
140
141 def unbundle(header, fh):
142 if not header.startswith('HG'):
143 def fixup(f, h):
144 yield h
145 for x in f:
146 yield x
147 fh = fixup(f, h)
148 header = "HG10UN"
149
150 alg = header[4:6]
151 return util.chunkbuffer(decompressor(fh, alg))
152
153 def readbundle(fh, fname):
141 def readbundle(fh, fname):
154 header = fh.read(6)
142 header = fh.read(6)
155 if not header.startswith('HG'):
143
156 raise util.Abort(_('%s: not a Mercurial bundle file') % fname)
144 if not fname:
157 if not header.startswith('HG10'):
145 fname = "stream"
158 raise util.Abort(_('%s: unknown bundle version') % fname)
146 if not header.startswith('HG') and header.startswith('\0'):
159 elif header not in bundletypes:
147 # headerless bundle, clean things up
160 raise util.Abort(_('%s: unknown bundle compression type') % fname)
148 def fixup(f, h):
161 return unbundle(header, fh)
149 yield h
150 for x in f:
151 yield x
152 fh = fixup(fh, header)
153 header = "HG10UN"
154
155 magic, version, alg = header[0:2], header[2:4], header[4:6]
156
157 if magic != 'HG':
158 raise util.Abort(_('%s: not a Mercurial bundle') % fname)
159 if version != '10':
160 raise util.Abort(_('%s: unknown bundle version %s') % (fname, version))
161 return util.chunkbuffer(decompressor(fh, alg))
@@ -294,13 +294,7 b' def unbundle(repo, proto, heads):'
294
294
295 # push can proceed
295 # push can proceed
296 fp.seek(0)
296 fp.seek(0)
297 header = fp.read(6)
297 gen = changegroupmod.readbundle(fp, None)
298 if header.startswith('HG'):
299 if not header.startswith('HG10'):
300 raise ValueError('unknown bundle version')
301 elif header not in changegroupmod.bundletypes:
302 raise ValueError('unknown bundle compression type')
303 gen = changegroupmod.unbundle(header, fp)
304
298
305 try:
299 try:
306 r = repo.addchangegroup(gen, 'serve', proto._client(),
300 r = repo.addchangegroup(gen, 'serve', proto._client(),
General Comments 0
You need to be logged in to leave comments. Login now