Skip to content

Commit 370572b

Browse files
refactor(tools): optimize git tag lookup and URL generation (#1370)
* refactor(versioning): optimize git tag lookup and URL generation * Update versioning.py * Update src/ethereum_test_tools/utility/versioning.py Co-authored-by: spencer <spencer.taylor-brown@ethereum.org> * fix lint * Update versioning.py * Update versioning.py --------- Co-authored-by: spencer <spencer.taylor-brown@ethereum.org>
1 parent f2c001c commit 370572b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/ethereum_test_tools/utility/versioning.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ def get_current_commit_hash_or_tag(repo_path=".", shorten_hash=False):
1616
"""
1717
try:
1818
repo = Repo(repo_path)
19-
# Try to get the current tag that points to the current commit
2019
current_commit = repo.head.commit
21-
current_tag = next((tag for tag in repo.tags if tag.commit == current_commit), None)
22-
if current_tag:
23-
return current_tag.name
24-
else:
25-
commit_hash = current_commit.hexsha
26-
return commit_hash[:8] if shorten_hash else commit_hash
20+
# Check if current commit has a tag using lookup
21+
for tag in repo.tags:
22+
if tag.commit == current_commit:
23+
return tag.name
24+
# No tag found, return commit hash
25+
return current_commit.hexsha[:8] if shorten_hash else current_commit.hexsha
2726
except InvalidGitRepositoryError:
2827
# Handle the case where the repository is not a valid Git repository
2928
return "Not a git repository; this should only be seen in framework tests."

0 commit comments

Comments
 (0)