313 if not isinstance(value, tuple) or len(value) != 2: |
313 if not isinstance(value, tuple) or len(value) != 2: |
314 raise TypeError( |
314 raise TypeError( |
315 b"Manifest values must be a tuple of (node, flags)." |
315 b"Manifest values must be a tuple of (node, flags)." |
316 ) |
316 ) |
317 hashval = value[0] |
317 hashval = value[0] |
318 # hashes are either 20 or 32 bytes (sha1 or its replacement), |
318 if not isinstance(hashval, bytes) or len(hashval) not in (20, 32): |
319 # and allow one extra byte taht won't be persisted to disk but |
|
320 # is sometimes used in memory. |
|
321 if not isinstance(hashval, bytes) or not ( |
|
322 20 <= len(hashval) <= 22 or 32 <= len(hashval) <= 34 |
|
323 ): |
|
324 raise TypeError(b"node must be a 20-byte or 32-byte byte string") |
319 raise TypeError(b"node must be a 20-byte or 32-byte byte string") |
325 flags = value[1] |
320 flags = value[1] |
326 if len(hashval) == 22: |
|
327 hashval = hashval[:-1] |
|
328 if not isinstance(flags, bytes) or len(flags) > 1: |
321 if not isinstance(flags, bytes) or len(flags) > 1: |
329 raise TypeError(b"flags must a 0 or 1 byte string, got %r", flags) |
322 raise TypeError(b"flags must a 0 or 1 byte string, got %r", flags) |
330 needle, found = self.bsearch2(key) |
323 needle, found = self.bsearch2(key) |
331 if found: |
324 if found: |
332 # put the item |
325 # put the item |