Save hash object

This commit is contained in:
2024-02-12 19:35:14 +01:00
parent c647f99e5c
commit 71abdf3454
2 changed files with 19 additions and 0 deletions

View File

@@ -1,7 +1,17 @@
from pathlib import Path
import hashlib
GIT_DIR = ".ugit"
def init():
Path.mkdir(GIT_DIR)
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