Re: [PATCH 02/14] oidtree: extend iteration to allow for arbitrary return codes
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 19, 2026, 16:27 UTC
- Message-ID
- <xmqqa4w3n5se.fsf@gitster.g>
- In-Reply-To
- <20260319-b4-pks-odb-source-abbrev-v1-2-5ddebad292b0@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 20 quoted lines
> diff --git a/cbtree.h b/cbtree.h
> index 43193abdda..4f644d6e45 100644
> --- a/cbtree.h
> +++ b/cbtree.h
> @@ -30,11 +30,6 @@ struct cb_tree {
> struct cb_node *root;
> };
>
> -enum cb_next {
> - CB_CONTINUE = 0,
> - CB_BREAK = 1
> -};
> -
> #define CBTREE_INIT { 0 }
>
> static inline void cb_init(struct cb_tree *t)
> @@ -46,9 +41,9 @@ static inline void cb_init(struct cb_tree *t)
> struct cb_node *cb_lookup(struct cb_tree *, const uint8_t *k, size_t klen);
> struct cb_node *cb_insert(struct cb_tree *, struct cb_node *, size_t klen);
> This change does make sense,...
> -typedef enum cb_next (*cb_iter)(struct cb_node *, void *arg); > +typedef int (*cb_iter)(struct cb_node *, void *arg);
... but it probably now warrants a bit of comment as readers cannot guess from the values in cb_next enum that is gone.
cb_each() keeps iterating while this function returns 0; a non-zero value returned from the iterator callback is relayed back to the caller of cb_each() after immediately stopping iteration.
> -void cb_each(struct cb_tree *, const uint8_t *kpfx, size_t klen, > - cb_iter, void *arg); > +int cb_each(struct cb_tree *, const uint8_t *kpfx, size_t klen, > + cb_iter, void *arg);
or something like that, perhaps.