python / cherry-picker

🐍🍒⛏ Utility script for backporting/cherry-picking CPython changes from master into one of the maintenance branches.
Apache License 2.0
49 stars 39 forks source link

Optimize `validate_sha()` with `--max-count=1` #111

Closed aloisklink closed 8 months ago

aloisklink commented 8 months ago

Optimize the validate_sha() function with --max-count=1 to prevent printing the git log of every single commit. See the "Commit Limiting" section of git-log's man page

This makes the function near instant.

Currently, running time git log main > /dev/null takes about ~1s second for me on the CPython repo, while time git log --max-count=1 main > /dev/null (with or without the -r flag) only takes about 0.003s.

Additionally, if you've cloned the CPython repo using a blobless clone (e.g. with git clone --filter=blob:none https://github.com/python/cpython.git), doing a git log -r takes a very long time (almost an hour for me on a slow internet connection!), since the -r flag seems to force downloading a blob for every single commit, which makes a blobless clone kind of useless.