Re: [PATCH 3/8] trailer: add interface for iterating over commit trailers
On Fri, 25 Sep 2020 at 09:04, Jeff King <peff@peff.net> wrote:
Show 6 quoted lines
>
> The trailer code knows how to parse out the trailers and re-format them,
> but there's no easy way to iterate over the trailers (you can use
> trailer_info, but you have to then do a bunch of extra parsing).
>
> Let's add an iteration interface that makes this easy to do.
Show 9 quoted lines
> +void trailer_iterator_init(struct trailer_iterator *iter, const char *msg)
> +{
> + struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
> + strbuf_init(&iter->key, 0);
> + strbuf_init(&iter->val, 0);
> + opts.no_divider = 1;
> + trailer_info_get(&iter->info, msg, &opts);
> + iter->cur = 0;
> +}Ok, this does initialize everything...
Show 6 quoted lines
> +void trailer_iterator_release(struct trailer_iterator *iter)
> +{
> + trailer_info_release(&iter->info);
> + strbuf_release(&iter->val);
> + strbuf_release(&iter->key);
> +}... and this side takes care of everything, too.
Show 6 quoted lines
> #define TRAILER_H
>
> #include "list.h"
> -
> -struct strbuf;
> +#include "strbuf.h"
Spotting and removing the forward declaration, ok.
Show 18 quoted lines
> +/*
> + * An interface for iterating over the trailers found in a particular commit
> + * message. Use like:
> + *
> + * struct trailer_iterator iter;
> + * trailer_iterator_init(&iter, msg);
> + * while (trailer_iterator_advance(&iter))
> + * ... do something with iter.key and iter.val ...
> + * trailer_iterator_release(&iter);
> + */
> +struct trailer_iterator {
> + struct strbuf key;
> + struct strbuf val;
> +
> + /* private */
> + struct trailer_info info;
> + size_t cur;
> +};Show 7 quoted lines
> +/*
> + * Initialize "iter" in preparation for walking over the trailers in the commit
> + * message "msg". The "msg" pointer must remain valid until the iterator is
> + * released.
> + *
> + * After initializing, we are not yet pointing
> + */
Truncated sentence. "... not yet pointing at any trailer"?
Martin