Skip to content

Commit 832cf74

Browse files
aiiiegitster
authored andcommitted
sha1_name: don't resolve refs when core.warnambiguousrefs is false
When seeing a full 40-hex object name, get_sha1_basic() unconditionally checks if the string can also be interpreted as a refname, but the result will not be used unless warn_ambiguous_refs is in effect. Omitting this unnecessary ref resolution provides a substantial performance improvement, especially when passing many hashes to a command (like "git rev-list --stdin") and core.warnambiguousrefs is set to false. The check incurs 6 stat()s for every hash supplied, which can be costly over NFS. Signed-off-by: Brodie Rao <[email protected]> Acked-by: Nguyễn Thái Ngọc Duy <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c90d3db commit 832cf74

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sha1_name.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,9 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
451451
int at, reflog_len, nth_prior = 0;
452452

453453
if (len == 40 && !get_sha1_hex(str, sha1)) {
454-
if (warn_on_object_refname_ambiguity) {
454+
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
455455
refs_found = dwim_ref(str, len, tmp_sha1, &real_ref);
456-
if (refs_found > 0 && warn_ambiguous_refs) {
456+
if (refs_found > 0) {
457457
warning(warn_msg, len, str);
458458
if (advice_object_name_warning)
459459
fprintf(stderr, "%s\n", _(object_name_msg));

0 commit comments

Comments
 (0)