Print refs for k (visualization tool)
This commit is contained in:
13
ugit/data.py
13
ugit/data.py
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user