Create RefValue container

This commit is contained in:
2024-06-14 16:29:58 +02:00
parent 556c16c081
commit 6841a97d18
3 changed files with 18 additions and 12 deletions

View File

@@ -3,6 +3,8 @@ from pathlib import Path, PurePath
import hashlib
import os
from collections import namedtuple
GIT_DIR = ".ugit"
@@ -11,11 +13,15 @@ def init():
Path.mkdir(f"{GIT_DIR}/objects")
def update_ref(ref, oid):
RefValue = namedtuple("RefValue", ["symbolic", "value"])
def update_ref(ref, value):
assert not value.symbolic
ref_path = f"{GIT_DIR}/{ref}"
Path.mkdir(ref_path, exist_ok=True)
with open(ref_path, "w") as f:
f.write(oid)
f.write(value.value)
def get_ref(ref):
@@ -28,7 +34,7 @@ def get_ref(ref):
if value and value.startswith("ref:"):
return get_ref(value.split(":", 1)[1].strip())
return value
return RefValue(symbolic=False, value=value)
def iter_refs():