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
|
2024-02-14 20:24:33 +01:00
|
|
|
|
|
|
|
|
|
|
|
def get_object(oid):
|
|
|
|
with open(f"{GIT_DIR}/objects/{oid}", "rb") as f:
|
|
|
|
return f.read()
|