]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-name: allow skipping ambiguity checks in `get_oid()` family
authorPatrick Steinhardt <ps@pks.im>
Wed, 12 Mar 2025 15:56:08 +0000 (16:56 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Mar 2025 18:31:16 +0000 (11:31 -0700)
When reading an object ID via `get_oid_basic()` or any of its related
functions we perform a check whether the object ID is ambiguous, which
can be the case when a reference with the same name exists. While the
check is generally helpful, there are cases where it only adds to the
runtime overhead without providing much of a benefit.

Add a new flag that allows us to disable the check. The flag will be
used in a subsequent commit.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
hash.h
object-name.c

diff --git a/hash.h b/hash.h
index 4367acfec5098ac1fec0c1d5c2fba6ce0acd7f5d..5e3c462dc5ed082d079ad7d9bd26534230929090 100644 (file)
--- a/hash.h
+++ b/hash.h
@@ -193,17 +193,18 @@ struct object_id {
        int algo;       /* XXX requires 4-byte alignment */
 };
 
-#define GET_OID_QUIETLY           01
-#define GET_OID_COMMIT            02
-#define GET_OID_COMMITTISH        04
-#define GET_OID_TREE             010
-#define GET_OID_TREEISH          020
-#define GET_OID_BLOB             040
-#define GET_OID_FOLLOW_SYMLINKS 0100
-#define GET_OID_RECORD_PATH     0200
-#define GET_OID_ONLY_TO_DIE    04000
-#define GET_OID_REQUIRE_PATH  010000
-#define GET_OID_HASH_ANY      020000
+#define GET_OID_QUIETLY                  01
+#define GET_OID_COMMIT                   02
+#define GET_OID_COMMITTISH               04
+#define GET_OID_TREE                    010
+#define GET_OID_TREEISH                 020
+#define GET_OID_BLOB                    040
+#define GET_OID_FOLLOW_SYMLINKS        0100
+#define GET_OID_RECORD_PATH            0200
+#define GET_OID_ONLY_TO_DIE           04000
+#define GET_OID_REQUIRE_PATH         010000
+#define GET_OID_HASH_ANY             020000
+#define GET_OID_SKIP_AMBIGUITY_CHECK 040000
 
 #define GET_OID_DISAMBIGUATORS \
        (GET_OID_COMMIT | GET_OID_COMMITTISH | \
index 233f3f861e36817b21001793d8fa7c9bc2e2f293..85444dbb15b5a255b9b6e32ba56c317290adcb70 100644 (file)
@@ -961,7 +961,9 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
        int fatal = !(flags & GET_OID_QUIETLY);
 
        if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
-               if (repo_settings_get_warn_ambiguous_refs(r) && warn_on_object_refname_ambiguity) {
+               if (!(flags & GET_OID_SKIP_AMBIGUITY_CHECK) &&
+                   repo_settings_get_warn_ambiguous_refs(r) &&
+                   warn_on_object_refname_ambiguity) {
                        refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0);
                        if (refs_found > 0) {
                                warning(warn_msg, len, str);