Create RefValue container
This commit is contained in:
12
ugit/data.py
12
ugit/data.py
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user