aboutsummaryrefslogtreecommitdiff
path: root/hash.h
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-20 08:07:37 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-20 13:16:42 -0700
commit1a2842d1b1e91d5e068d231cf4df4e783bdf9205 (patch)
tree40dbc8c53872fb0f02b8030d59ecb9e24171ba3a /hash.h
parent67f47eab61c3a2c14f2d0351c3844f12fbd95dd2 (diff)
downloadgit-1a2842d1b1e91d5e068d231cf4df4e783bdf9205.tar.xz
object-name: simplify computing common prefixes
The function `extend_abbrev_len()` computes the length of common hex characters between two object IDs. This is done by: - Making the caller provide the `hex` string for the needle object ID. - Comparing every hex position of the haystack object ID with `get_hex_char_from_oid()`. Turning the binary representation into hex first is roundabout though: we can simply compare the binary representation and give some special attention to the final nibble. Introduce a new function `oid_common_prefix_hexlen()` that does exactly this and refactor the code to use the new function. This allows us to drop the `struct min_abbrev_data::hex` field. Furthermore, this function will be used in by some other callsites in subsequent commits. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hash.h')
-rw-r--r--hash.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/hash.h b/hash.h
index d51efce1d3..c082a53c9a 100644
--- a/hash.h
+++ b/hash.h
@@ -396,6 +396,9 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi
return !memcmp(oid1->hash, oid2->hash, GIT_MAX_RAWSZ);
}
+unsigned oid_common_prefix_hexlen(const struct object_id *a,
+ const struct object_id *b);
+
static inline void oidcpy(struct object_id *dst, const struct object_id *src)
{
memcpy(dst->hash, src->hash, GIT_MAX_RAWSZ);