Mercurial > hg
comparison mercurial/changegroup.py @ 12042:210049a8d16e
bundle: unify/refactor unbundle/readbundle
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 25 Aug 2010 15:33:06 -0500 |
parents | 270fb4d39153 |
children | bef5effb3db0 |
comparison
equal
deleted
inserted
replaced
12041:270fb4d39153 | 12042:210049a8d16e |
---|---|
136 yield zd.decompress(chunk) | 136 yield zd.decompress(chunk) |
137 else: | 137 else: |
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)) |