sha1_name: don't resolve refs when core.warnambiguousrefs is false
authorBrodie Rao <brodie@sf.io>
Tue, 7 Jan 2014 03:32:01 +0000 (19:32 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 7 Jan 2014 17:51:56 +0000 (09:51 -0800)
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 <brodie@sf.io>
Acked-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_name.c
index e9c299943b817b5b3b5b700ac3979211d5688e2e..10bd0071628f1875c31d54ba63dd83e3445f2283 100644 (file)
@@ -451,9 +451,9 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
        int at, reflog_len, nth_prior = 0;
 
        if (len == 40 && !get_sha1_hex(str, sha1)) {
-               if (warn_on_object_refname_ambiguity) {
+               if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
                        refs_found = dwim_ref(str, len, tmp_sha1, &real_ref);
-                       if (refs_found > 0 && warn_ambiguous_refs) {
+                       if (refs_found > 0) {
                                warning(warn_msg, len, str);
                                if (advice_object_name_warning)
                                        fprintf(stderr, "%s\n", _(object_name_msg));