mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-18 08:34:41 +04:00
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:
parent
8416413a0e
commit
66d1c0707e
2 changed files with 17 additions and 1 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue