Print refs for k (visualization tool)
This commit is contained in:
parent
c9d8b443ed
commit
db7d608010
@ -56,6 +56,9 @@ def parse_args():
|
||||
tag_parser.add_argument("name")
|
||||
tag_parser.add_argument("oid", default="@", type=oid, nargs="?")
|
||||
|
||||
k_parser = commands.add_parser("k")
|
||||
k_parser.set_defaults(func=k)
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@ -104,3 +107,9 @@ def checkout(args):
|
||||
|
||||
def tag(args):
|
||||
base.create_tag(args.name, args.oid)
|
||||
|
||||
|
||||
def k(args):
|
||||
for refname, ref in data.iter_refs():
|
||||
print(refname, ref)
|
||||
# TODO visualize refs
|
||||
|
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()
|
||||
|
Loading…
Reference in New Issue
Block a user