Subject: Re: [PATCH 01/14] oidtree: modernize the code a bit

From: Junio C Hamano <[email-masked]>
Date: Thu, 19 Mar 2026 09:08:44 -0700

Patrick Steinhardt <[email-masked]> writes:

> +void oidtree_each(struct oidtree *ot, const struct object_id *prefix,
> +		  size_t prefix_hex_len, oidtree_each_cb cb, void *cb_data)
>  {
> -	size_t klen = oidhexsz / 2;
> -	struct oidtree_iter_data x = { 0 };
> -	assert(oidhexsz <= GIT_MAX_HEXSZ);
> -
> -	x.fn = fn;
> -	x.arg = arg;
> -	x.algo = oid->algo;
> -	if (oidhexsz & 1) {
> -		x.last_byte = oid->hash[klen];
> -		x.last_nibble_at = &klen;
> +	struct oidtree_each_data data = {
> +		.cb = cb,
> +		.cb_data = cb_data,
> +		.algo = prefix->algo,
> +	};
> +	size_t klen = prefix_hex_len / 2;
> +	assert(prefix_hex_len <= GIT_MAX_HEXSZ);

I know the original also used GIT_MAX_HEXSZ to clamp the length for
sanity, but because we know what algorithm is in use, I wonder if we
want to use the limit more specific to it.