MCPcopy Index your code
hub / github.com/python/mypy / apply_diff

Function apply_diff

misc/apply-cache-diff.py:34–63  ·  view source on GitHub ↗
(
    cache_dir: str, diff_file: str, sqlite: bool = False, num_shards: int = SQLITE_NUM_SHARDS
)

Source from the content-addressed store, hash-verified

32
33
34def apply_diff(
35 cache_dir: str, diff_file: str, sqlite: bool = False, num_shards: int = SQLITE_NUM_SHARDS
36) -> None:
37 cache = make_cache(cache_dir, sqlite, num_shards=num_shards)
38 with open(diff_file, "rb") as f:
39 diff = json_loads(f.read())
40
41 old_deps = json_loads(cache.read("@deps.meta.json"))
42
43 for file, data in diff.items():
44 if data is None:
45 cache.remove(file)
46 else:
47 if file.endswith(".ff"):
48 data_bytes = base64.b64decode(data)
49 else:
50 data_bytes = data.encode() if isinstance(data, str) else data
51 cache.write(file, data_bytes)
52 if file.endswith(".meta.ff") and "@deps" not in file:
53 buf = ReadBuffer(data_bytes[2:])
54 meta = CacheMeta.read(buf, data_file="")
55 assert meta is not None
56 old_deps["snapshot"][meta.id] = meta.hash
57 elif file.endswith(".meta.json") and "@deps" not in file:
58 meta_dict = json_loads(data_bytes)
59 old_deps["snapshot"][meta_dict["id"]] = meta_dict["hash"]
60
61 cache.write("@deps.meta.json", json_dumps(old_deps))
62
63 cache.commit()
64
65
66def main() -> None:

Callers 1

mainFunction · 0.85

Calls 11

json_loadsFunction · 0.90
json_dumpsFunction · 0.90
isinstanceFunction · 0.85
encodeMethod · 0.80
make_cacheFunction · 0.70
readMethod · 0.45
itemsMethod · 0.45
removeMethod · 0.45
endswithMethod · 0.45
writeMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…