DIY_GIT_in_Python/ugit/data.py

18 lines
296 B
Python
Raw Normal View History

2024-02-10 19:09:11 +01:00
from pathlib import Path
2024-02-12 19:35:14 +01:00
import hashlib
2024-02-10 19:09:11 +01:00
GIT_DIR = ".ugit"
def init():
Path.mkdir(GIT_DIR)
2024-02-12 19:35:14 +01:00
Path.mkdir(f"{GIT_DIR}/objects")
def hash_object(data):
oid = hashlib.sha1(data).hexdigest()
with open(f"{GIT_DIR}/objects/{oid}", "wb") as out:
out.write(data)
return oid