Compare commits
2 Commits
9c53919802
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| c484b41a89 | |||
| fe5ed910a3 |
15
how_to/Change_34.md
Normal file
15
how_to/Change_34.md
Normal file
@@ -0,0 +1,15 @@
|
||||
- data: Don't always dereference refs (for `ugit k`)
|
||||
|
||||
Actually, it's not always desirable to dereference a ref all the way. Sometimes
|
||||
we would like to know at which ref a symbolic ref points, rather than the final
|
||||
OID. Or we would like to update a ref directly, rather then updating the last
|
||||
ref in the chain.
|
||||
|
||||
One such usecase is `ugit k`. When visualizing refs it would be nice to see
|
||||
which ref points to which ref. We will see another usecase soon.
|
||||
|
||||
To accomodate this, we will add a `deref` option to `get_ref`, `iter_refs` and
|
||||
`update_ref`. If they will be called with `deref=False`, they will work on the
|
||||
raw value of a ref and not dereference any symbolic refs.
|
||||
|
||||
Then we will update `k` to use `deref=False`.
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user