MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / prepare

Function prepare

tools/materialize-bench/imported_guest.py:103–189  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

101
102
103def prepare(args):
104 root = args.root.resolve()
105 root.mkdir(parents=True, exist_ok=False)
106 (root / 'owner.json').write_text(json.dumps({'marker': MARKER, 'root': str(root)}))
107 manifest = json.loads(args.manifest.read_text())
108 validate_manifest(manifest)
109 (root / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
110 env = isolated_env(root)
111 golden = root / 'golden'
112 golden.mkdir()
113 fixtures = {}
114 binary_sha = digest(args.cli)
115 for backend in BACKENDS:
116 repo = root / backend
117 command(['git', '-c', 'core.hooksPath=/dev/null', 'clone', '--no-checkout', args.bundle, repo], env)
118 command(['git', '-c', 'core.hooksPath=/dev/null', 'checkout', '-b', 'atomic-bench', manifest['git_tip']], env, repo)
119 tip = command(['git', 'rev-parse', 'HEAD'], env, repo).decode().strip()
120 count = int(command(['git', 'rev-list', '--first-parent', '--count', 'HEAD'], env, repo))
121 if tip != manifest['git_tip'] or count != manifest['first_parent_commits']:
122 raise ValueError('wrong Git fixture identity')
123 entries = command(['git', 'ls-tree', '-r', '-z', tip], env, repo)
124 actual = set()
125 for row in filter(None, entries.split(b'\0')):
126 meta, path = row.split(b'\t', 1)
127 mode, kind, oid = meta.decode().split()
128 if kind != 'blob':
129 raise ValueError('unsupported non-blob Git entry')
130 actual.add((path.decode('utf-8'), mode, oid))
131 expected = {(file['path'], file['mode'], file['git_blob']) for file in manifest['files']}
132 if actual != expected:
133 raise ValueError('manifest does not cover the exact pinned Git tree')
134 verify_checkout(repo, manifest)
135 index_sha = digest(repo / '.git/index')
136 for index, file in enumerate(manifest['files']):
137 blob = command(['git', 'cat-file', 'blob', file['git_blob']], env, repo)
138 if hashlib.sha256(blob).hexdigest() != file['sha256']:
139 raise ValueError('Git manifest mismatch')
140 target = golden / str(index)
141 if target.exists() and target.read_bytes() != blob:
142 raise ValueError('graph/span Git baseline differs')
143 target.write_bytes(blob)
144 args_import = [args.cli, 'git', 'import', '--no-vault']
145 if backend == 'span':
146 args_import.append('--span')
147 started = time.monotonic()
148 command(args_import, env, repo, root / (backend + '-import'))
149 import_seconds = time.monotonic() - started
150 verify_checkout(repo, manifest)
151 if digest(repo / '.git/index') != index_sha:
152 raise ValueError('import changed Git index')
153 repair = dict(requested=args.repair_derived_indexes, performed=False)
154 try:
155 command([args.cli, 'doctor', 'check'], env, repo, root / (backend + '-doctor'))
156 except subprocess.CalledProcessError as error:
157 repair['initial_doctor_exit'] = error.returncode
158 if not args.repair_derived_indexes:
159 raise
160 shutil.copyfile(repo / '.atomic/atomic.redb', root / (backend + '-pre-repair.redb'))

Callers 1

mainFunction · 0.70

Calls 14

isolated_envFunction · 0.85
setFunction · 0.85
verify_checkoutFunction · 0.85
immutable_changes_digestFunction · 0.85
validate_manifestFunction · 0.70
digestFunction · 0.70
commandFunction · 0.70
filterFunction · 0.50
resolveMethod · 0.45
decodeMethod · 0.45
addMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected