Mercurial > hg
comparison mercurial/revlogutils/docket.py @ 47326:53ab13d6a5db
revlogv2: add a `get_data` helper to grab the next piece of docket
This make the processing more compact but abstracting repetitive processing
away.
Differential Revision: https://phab.mercurial-scm.org/D10774
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 20 May 2021 21:54:21 +0200 |
parents | f286d715f9ab |
children | 710435a5c469 |
comparison
equal
deleted
inserted
replaced
47325:f286d715f9ab | 47326:53ab13d6a5db |
---|---|
235 | 235 |
236 | 236 |
237 def parse_docket(revlog, data, use_pending=False): | 237 def parse_docket(revlog, data, use_pending=False): |
238 """given some docket data return a docket object for the given revlog""" | 238 """given some docket data return a docket object for the given revlog""" |
239 header = S_HEADER.unpack(data[: S_HEADER.size]) | 239 header = S_HEADER.unpack(data[: S_HEADER.size]) |
240 offset = S_HEADER.size | 240 |
241 # this is a mutable closure capture used in `get_data` | |
242 offset = [S_HEADER.size] | |
243 | |
244 def get_data(size): | |
245 """utility closure to access the `size` next bytes""" | |
246 if offset[0] + size > len(data): | |
247 # XXX better class | |
248 msg = b"docket is too short, expected %d got %d" | |
249 msg %= (offset[0] + size, len(data)) | |
250 raise error.Abort(msg) | |
251 raw = data[offset[0] : offset[0] + size] | |
252 offset[0] += size | |
253 return raw | |
241 | 254 |
242 iheader = iter(header) | 255 iheader = iter(header) |
243 | 256 |
244 version_header = next(iheader) | 257 version_header = next(iheader) |
245 | 258 |
246 index_uuid_size = next(iheader) | 259 index_uuid_size = next(iheader) |
247 index_uuid = data[offset : offset + index_uuid_size] | 260 index_uuid = get_data(index_uuid_size) |
248 offset += index_uuid_size | |
249 | 261 |
250 data_uuid_size = next(iheader) | 262 data_uuid_size = next(iheader) |
251 data_uuid = data[offset : offset + data_uuid_size] | 263 data_uuid = get_data(data_uuid_size) |
252 offset += data_uuid_size | |
253 | 264 |
254 index_size = next(iheader) | 265 index_size = next(iheader) |
255 | 266 |
256 pending_index_size = next(iheader) | 267 pending_index_size = next(iheader) |
257 | 268 |