Update object_find to accept more object spec types
This commit is contained in:
parent
cd2aca3ca5
commit
9365c473fd
29
libwyag.py
29
libwyag.py
@ -284,7 +284,34 @@ def cat_file(repo, obj, fmt=None):
|
|||||||
sys.stdout.buffer.write(obj.serialize())
|
sys.stdout.buffer.write(obj.serialize())
|
||||||
|
|
||||||
def object_find(repo, name, fmt=None, follow=True):
|
def object_find(repo, name, fmt=None, follow=True):
|
||||||
return name
|
sha = object_resolve(repo, name)
|
||||||
|
|
||||||
|
if not sha:
|
||||||
|
raise Exception(f"No such reference {name}")
|
||||||
|
|
||||||
|
if len(sha) > 1:
|
||||||
|
raise Exception(f"Ambiguous reference {0}: Candidates are:\n - {1}.".format(name, "\n - ".join(sha)))
|
||||||
|
|
||||||
|
sha = sha[0]
|
||||||
|
|
||||||
|
if not fmt:
|
||||||
|
return sha
|
||||||
|
|
||||||
|
while True:
|
||||||
|
obj = object_read(repo, sha)
|
||||||
|
|
||||||
|
if obj.fmt == fmt:
|
||||||
|
return sha
|
||||||
|
|
||||||
|
if not follow:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if obj.fmt == b'tag':
|
||||||
|
sha = obj.kvlm[b'object'].decode("ascii")
|
||||||
|
elif obj.fmt == b'commit' and fmt == b'tree':
|
||||||
|
sha = obj.kvlm[b'tree'].decode("ascii")
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
argsp = argsubparsers.add_parser(
|
argsp = argsubparsers.add_parser(
|
||||||
"hash-object",
|
"hash-object",
|
||||||
|
Loading…
Reference in New Issue
Block a user