-
-
Save jvns/ff884dceef7660402fe1eca697cfbf51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zlib | |
import sys | |
with open(sys.argv[1], "rb") as f: | |
content = f.read() | |
print(zlib.decompress(content).decode()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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