Skip to content

Commit 46a2b52

Browse files
pks-tgitster
authored andcommitted
object-name: allow skipping ambiguity checks in get_oid() family
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 37e7546 commit 46a2b52

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

hash.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,18 @@ struct object_id {
193193
int algo; /* XXX requires 4-byte alignment */
194194
};
195195

196-
#define GET_OID_QUIETLY 01
197-
#define GET_OID_COMMIT 02
198-
#define GET_OID_COMMITTISH 04
199-
#define GET_OID_TREE 010
200-
#define GET_OID_TREEISH 020
201-
#define GET_OID_BLOB 040
202-
#define GET_OID_FOLLOW_SYMLINKS 0100
203-
#define GET_OID_RECORD_PATH 0200
204-
#define GET_OID_ONLY_TO_DIE 04000
205-
#define GET_OID_REQUIRE_PATH 010000
206-
#define GET_OID_HASH_ANY 020000
196+
#define GET_OID_QUIETLY 01
197+
#define GET_OID_COMMIT 02
198+
#define GET_OID_COMMITTISH 04
199+
#define GET_OID_TREE 010
200+
#define GET_OID_TREEISH 020
201+
#define GET_OID_BLOB 040
202+
#define GET_OID_FOLLOW_SYMLINKS 0100
203+
#define GET_OID_RECORD_PATH 0200
204+
#define GET_OID_ONLY_TO_DIE 04000
205+
#define GET_OID_REQUIRE_PATH 010000
206+
#define GET_OID_HASH_ANY 020000
207+
#define GET_OID_SKIP_AMBIGUITY_CHECK 040000
207208

208209
#define GET_OID_DISAMBIGUATORS \
209210
(GET_OID_COMMIT | GET_OID_COMMITTISH | \

object-name.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,9 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
961961
int fatal = !(flags & GET_OID_QUIETLY);
962962

963963
if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
964-
if (repo_settings_get_warn_ambiguous_refs(r) && warn_on_object_refname_ambiguity) {
964+
if (!(flags & GET_OID_SKIP_AMBIGUITY_CHECK) &&
965+
repo_settings_get_warn_ambiguous_refs(r) &&
966+
warn_on_object_refname_ambiguity) {
965967
refs_found = repo_dwim_ref(r, str, len, &tmp_oid, &real_ref, 0);
966968
if (refs_found > 0) {
967969
warning(warn_msg, len, str);

0 commit comments

Comments
 (0)