summaryrefslogtreecommitdiffstats
path: root/object-name.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-06-12 10:03:36 +0200
committerJunio C Hamano <gitster@pobox.com>2024-06-12 21:57:18 +0200
commit037df60013bb3f1534d4db6bf850d7547f1c1d13 (patch)
treedb27f3b5ad714d311926cfd1f362f760eb4176e4 /object-name.c
parentparse-options-cb: stop clamping "--abbrev=" to hash length (diff)
downloadgit-037df60013bb3f1534d4db6bf850d7547f1c1d13.tar.xz
git-037df60013bb3f1534d4db6bf850d7547f1c1d13.zip
object-name: don't try to abbreviate to lengths greater than hexsz
When given a length that equals the current hash algorithm's hex size, then `repo_find_unique_abbrev_r()` exits early without trying to find an abbreviation. This is only sensible because there is nothing to abbreviate in the first place, so searching through objects to find a unique prefix would be a waste of compute. What we don't handle though is the case where the user passes a length greater than the hash length. This is fine in practice as we still compute the correct result. But at the very least, this is a waste of resources as we try to abbreviate a value that cannot be abbreviated, which causes us to hit the object database. Start to explicitly handle values larger than hexsz to avoid this performance penalty, which leads to a measureable speedup. The following benchmark has been executed in linux.git: Benchmark 1: git -c core.abbrev=9000 log --abbrev-commit (revision = HEAD~) Time (mean ± σ): 12.812 s ± 0.040 s [User: 12.225 s, System: 0.554 s] Range (min … max): 12.723 s … 12.857 s 10 runs Benchmark 2: git -c core.abbrev=9000 log --abbrev-commit (revision = HEAD) Time (mean ± σ): 11.095 s ± 0.029 s [User: 10.546 s, System: 0.521 s] Range (min … max): 11.037 s … 11.122 s 10 runs Summary git -c core.abbrev=9000 log --abbrev-commit HEAD (revision = HEAD) ran 1.15 ± 0.00 times faster than git -c core.abbrev=9000 log --abbrev-commit HEAD (revision = HEAD~) Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'object-name.c')
-rw-r--r--object-name.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/object-name.c b/object-name.c
index 523af6f64f..1be2ad1a16 100644
--- a/object-name.c
+++ b/object-name.c
@@ -837,7 +837,7 @@ int repo_find_unique_abbrev_r(struct repository *r, char *hex,
}
oid_to_hex_r(hex, oid);
- if (len == hexsz || !len)
+ if (len >= hexsz || !len)
return hexsz;
mad.repo = r;