perf: use git cat-file -e instead of git rev-list in _rev_exists

Replace git rev-list --quiet with git cat-file -e for checking if a
revision exists. This changes the operation from O(commits) to O(1).

Benchmarks from a large monorepo:
- git rev-list --quiet <sha>: 5150ms
- git cat-file -e <sha>: 4ms

Both commands have the same semantics: return success if the revision
exists in the local repo, failure otherwise.
This commit is contained in:
Claude 2025-12-24 21:02:22 +00:00
parent 8416413a0e
commit 66d1c0707e
No known key found for this signature in database
2 changed files with 17 additions and 1 deletions

View file

@ -111,7 +111,7 @@ def _ns(
def _rev_exists(rev: str) -> bool:
return not subprocess.call(('git', 'rev-list', '--quiet', rev))
return subprocess.call(('git', 'cat-file', '-e', rev)) == 0
def _pre_push_ns(