~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-04 18:20:42 UTC
  • mto: (0.17.34 trunk)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090304182042-yo1m7n2i2bpdldfl
We at least have the rudimentary ability to encode and decode values.

Show diffs side-by-side

added added

removed removed

Lines of Context:
176
176
        if bytes[:6] != cls.GCB_HEADER:
177
177
            raise gc_errors.InvalidGroupCompressBlock(
178
178
                'bytes did not start with %r' % (cls.GCB_HEADER,))
 
179
        pos = bytes.index('\n', 6)
 
180
        total_header_length = int(bytes[6:pos])
 
181
        if total_header_length == 0:
 
182
            return out
 
183
        pos += 1
 
184
        header_bytes = bytes[pos:total_header_length+pos]
 
185
        lines = header_bytes.split('\n')
 
186
        info_dict = {}
 
187
        for line in lines:
 
188
            if not line: #End of record
 
189
                if not info_dict:
 
190
                    break
 
191
                out.add_entry(**info_dict)
 
192
                info_dict = {}
 
193
                continue
 
194
            key, value = line.split(':', 1)
 
195
            if key == 'key':
 
196
                value = tuple(map(intern, value.split('\x00')))
 
197
            elif key in ('start', 'length'):
 
198
                value = int(value)
 
199
            info_dict[key] = value
179
200
        return out
180
201
 
181
202
    def extract(self, key, sha1=None):
207
228
        for key in sorted(self._entries):
208
229
            entry = self._entries[key]
209
230
            chunk = ('key:%s\n'
 
231
                     'sha1:%s\n'
210
232
                     'type:%s\n'
211
 
                     'sha1:%s\n'
212
233
                     'start:%s\n'
213
234
                     'length:%s\n'
214
235
                     '\n'
215
236
                     ) % ('\x00'.join(entry.key),
 
237
                          entry.sha1,
216
238
                          entry.type,
217
 
                          entry.sha1,
218
239
                          entry.start,
219
240
                          entry.length,
220
241
                          )