Skip to content

Instantly share code, notes, and snippets.

@jvns
Last active May 1, 2024 02:11
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jvns/ff884dceef7660402fe1eca697cfbf51 to your computer and use it in GitHub Desktop.
Save jvns/ff884dceef7660402fe1eca697cfbf51 to your computer and use it in GitHub Desktop.
import zlib
import sys
with open(sys.argv[1], "rb") as f:
content = f.read()
print(zlib.decompress(content).decode())
import zlib
import sys
for line in sys.stdin:
line = line.strip()
filename = f".git/objects/{line[0:2]}/{line[2:]}"
with open(filename, "rb") as f:
contents = zlib.decompress(f.read())
if contents.startswith(b"blob"):
print(line)
import hashlib
import sys
def object_path(content):
header = f"blob {len(content)}\0"
data = header.encode() + content
digest = hashlib.sha1(data).hexdigest()
return f".git/objects/{digest[:2]}/{digest[2:]}"
with open(sys.argv[1], "rb") as f:
print(object_path(f.read()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment