def _decode_packobj(buf): assert (buf) c = byte_int(buf[0]) type = _typermap[(c & 0x70) >> 4] sz = c & 0x0f shift = 4 i = 0 while c & 0x80: i += 1 c = byte_int(buf[i]) sz |= (c & 0x7f) << shift shift += 7 if not (c & 0x80): break return (type, zlib.decompress(buf[i + 1:]))
def valid_save_name(name): # Enforce a superset of the restrictions in git-check-ref-format(1) if name == b'@' \ or name.startswith(b'/') or name.endswith(b'/') \ or name.endswith(b'.'): return False if _some_invalid_save_parts_rx.search(name): return False for c in name: if byte_int(c) < 0x20 or byte_int(c) == 0x7f: return False for part in name.split(b'/'): if part.startswith(b'.') or part.endswith(b'.lock'): return False return True
def splitbuf(buf): ofs = 0 for b in buf: b = byte_int(b) ofs += 1 if b >= basebits: return ofs, b return 0, 0
def read(self, sz): assert sz == 1 v = byte_int(self.file.read(1, szhint=self.szhint)[0]) self.szhint -= 1 ret = bytes_from_uint(v ^ self.vuint_cs[self.offs]) self.offs += 1 assert self.offs < len(self.vuint_cs) return ret
def _idx_from_hash(self, hash): global _total_searches, _total_steps _total_searches += 1 assert (len(hash) == 20) b1 = byte_int(hash[0]) start = self.fanout[b1 - 1] # range -1..254 end = self.fanout[b1] # range 0..255 want = hash _total_steps += 1 # lookup table is a step while start < end: _total_steps += 1 mid = start + (end - start) // 2 v = self._idx_to_hash(mid) if v < want: start = mid + 1 elif v > want: end = mid else: # got it! return mid return None
def add(self, sha, crc, offs): assert (sha) self.count += 1 self.idx[byte_int(sha[0])].append((sha, crc, offs))
def __init__(self, file, vuint_cs, szhint): self.file = file self.vuint_cs = [byte_int(x) for x in vuint_cs] self.offs = 0 self.szhint = szhint
def _update_idx(self, sha, crc, size): assert (sha) if self.idx: self.idx[byte_int(sha[0])].append( (sha, crc, self.file.tell() - size))