Re: [PATCH v4 02/16] object-name: allow skipping ambiguity checks in `get_oid()` family
Patrick Steinhardt <ps@pks.im> writes:
Show 25 quoted lines
> 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>
> ---
> hash.h | 1 +
> object-name.c | 4 +++-
> 2 files changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/hash.h b/hash.h
> index 4367acfec50..79419016513 100644
> --- a/hash.h
> +++ b/hash.h
> @@ -204,6 +204,7 @@ struct object_id {
> #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
>Nit: not worth re-rolling for, but the other macros are aligned. Our
styling guide is to align them and this is only set in our
'clang-format' [1].
[1] : https://clang.llvm.org/docs/ClangFormatStyleOptions.html#alignconsecutiveassignments
Show 20 quoted lines
> #define GET_OID_DISAMBIGUATORS \
> (GET_OID_COMMIT | GET_OID_COMMITTISH | \
> diff --git a/object-name.c b/object-name.c
> index 233f3f861e3..85444dbb15b 100644
> --- a/object-name.c
> +++ b/object-name.c
> @@ -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);
>
> --
> 2.49.0.rc0.375.gae4b89d849.dirty