Don't always derefence ref

This commit is contained in:
David Doblas Jiménez 2024-07-06 19:50:52 +02:00
parent fe5ed910a3
commit c484b41a89
3 changed files with 6 additions and 5 deletions

View File

@ -161,7 +161,7 @@ def get_oid(name):
f"refs/heads/{name}",
]
for ref in refs_to_try:
if data.get_ref(ref).value:
if data.get_ref(ref, deref=False).value:
return data.get_ref(ref).value
# Name is SHA1

View File

@ -121,10 +121,11 @@ def k(args):
dot = "digraph commits {\n"
oids = set()
for refname, ref in data.iter_refs():
for refname, ref in data.iter_refs(deref=False):
dot += f"'{refname}' [shape=note]\n"
dot += f"'{refname}' -> '{ref.value}'\n"
oids.add(ref.value)
if not ref.symbolic:
oids.add(ref.value)
for oid in base.iter_commits_and_parents(oids):
commit = base.get_commit(oid)

View File

@ -16,9 +16,9 @@ def init():
RefValue = namedtuple("RefValue", ["symbolic", "value"])
def update_ref(ref, value):
def update_ref(ref, value, deref=True):
assert not value.symbolic
ref = _get_ref_internal(ref)[0]
ref = _get_ref_internal(ref, deref)[0]
ref_path = f"{GIT_DIR}/{ref}"
Path.mkdir(ref_path, exist_ok=True)
with open(ref_path, "w") as f: