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

Function source_fingerprint

tools/materialize-bench/run.py:51–77  ·  view source on GitHub ↗

Hash source bytes directly, never Git metadata or a writable Atomic open.

()

Source from the content-addressed store, hash-verified

49
50
51def source_fingerprint():
52 """Hash source bytes directly, never Git metadata or a writable Atomic open."""
53 names = ['Cargo.toml', 'Cargo.lock', 'rust-toolchain.toml', 'libatomic', 'tools']
54 names += sorted(p.name for p in ROOT.iterdir() if p.is_dir() and p.name.startswith('atomic-'))
55 files = []
56 for name in names:
57 path = ROOT / name
58 if path.is_file():
59 files.append(path)
60 elif path.is_dir():
61 for directory, dirs, entries in os.walk(path, followlinks=False):
62 dirs[:] = sorted(d for d in dirs if d not in ('target', '.git', '.atomic', '__pycache__'))
63 links = [d for d in dirs if (Path(directory) / d).is_symlink()]
64 files.extend(Path(directory) / d for d in links)
65 dirs[:] = [d for d in dirs if d not in links]
66 files.extend(Path(directory) / entry for entry in entries)
67 value = hashlib.sha256()
68 for path in sorted(set(files), key=lambda p: os.fsencode(str(p.relative_to(ROOT)))):
69 relative = os.fsencode(str(path.relative_to(ROOT)))
70 value.update(len(relative).to_bytes(8, 'big'))
71 value.update(relative)
72 value.update(b'L' if path.is_symlink() else b'F')
73 value.update(bytes([bool(path.lstat().st_mode & 0o111)]))
74 content = os.fsencode(os.readlink(path)) if path.is_symlink() else path.read_bytes()
75 value.update(len(content).to_bytes(8, 'big'))
76 value.update(content)
77 return value.hexdigest()
78
79
80def distribution(values):

Callers 2

mainFunction · 0.90
mainFunction · 0.85

Calls 8

setFunction · 0.85
is_dirMethod · 0.80
extendMethod · 0.80
is_fileMethod · 0.45
appendMethod · 0.45
walkMethod · 0.45
updateMethod · 0.45
to_bytesMethod · 0.45

Tested by

no test coverage detected