Print refs for k (visualization tool)

This commit is contained in:
2024-05-15 11:01:19 +02:00
parent c9d8b443ed
commit db7d608010
2 changed files with 21 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
from pathlib import Path
from pathlib import Path, PurePath
import hashlib
import os
GIT_DIR = ".ugit"
@@ -24,6 +25,16 @@ def get_ref(ref):
return f.read().strip()
def iter_refs():
refs = ["HEAD"]
for root, _, filenames in Path.walk(f"{GIT_DIR}/refs"):
root = PurePath.relative_to(root, GIT_DIR)
refs.extend(f"{root}/{name}" for name in filenames)
for refname in refs:
yield refname, get_ref(refname)
def hash_object(data, type_="blob"):
obj = type_.encode() + b"\x00" + data
oid = hashlib.sha1(obj).hexdigest()