INNER CODE UNIT · Python
snapshot
spantaleev/matrix-docker-ansible-deploy · bin/molecule-select-roles.py:54
def snapshot(self, ref):
entries = {}
for entry in self.run("ls-tree", "-rz", ref, "--", "roles/custom", "molecule-shared").split(b"\0"):
if not entry:
continue
metadata, path = entry.decode().split("\t", 1)
mode, kind, oid = metadata.split()
if path.startswith("molecule-shared/") or "/molecule/" in path:
if kind != "blob":
raise Uncertain(f"Unsupported Git entry: {path}")
entries[path] = (mode, oid)
# Read the blobs in one process; a subprocess per scenario file is slow.
oids = list(dict.fromkeys(oid for mode, oid in entries.values()))
data = self.run("cat-file", "--batch", input="".join(f"{oid}\n" for oid in oids).encode())
blobs = {}
offset = 0
for oid in oids: