Skip to content

Commit 2ade054

Browse files
listxgitster
authored andcommitted
sequencer: use the trailer iterator
Instead of calling "trailer_info_get()", which is a low-level function in the trailers implementation (trailer.c), call trailer_iterator_advance(), which was specifically designed for public consumption in f0939a0 (trailer: add interface for iterating over commit trailers, 2020-09-27). Avoiding "trailer_info_get()" means we don't have to worry about options like "no_divider" (relevant for parsing trailers). We also don't have to check for things like "info.trailer_start == info.trailer_end" to see whether there were any trailers (instead we can just check to see whether the iterator advanced at all). Note how we have to use "iter.raw" in order to get the same behavior as before when we iterated over the unparsed string array (char **trailers) in trailer_info. Signed-off-by: Linus Arver <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3be65e6 commit 2ade054

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

sequencer.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -319,35 +319,32 @@ static const char *get_todo_path(const struct replay_opts *opts)
319319
static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
320320
size_t ignore_footer)
321321
{
322-
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
323-
struct trailer_info info;
324-
size_t i;
322+
struct trailer_iterator iter;
323+
size_t i = 0;
325324
int found_sob = 0, found_sob_last = 0;
326325
char saved_char;
327326

328-
opts.no_divider = 1;
329-
330327
if (ignore_footer) {
331328
saved_char = sb->buf[sb->len - ignore_footer];
332329
sb->buf[sb->len - ignore_footer] = '\0';
333330
}
334331

335-
trailer_info_get(&opts, sb->buf, &info);
332+
trailer_iterator_init(&iter, sb->buf);
336333

337334
if (ignore_footer)
338335
sb->buf[sb->len - ignore_footer] = saved_char;
339336

340-
if (info.trailer_block_start == info.trailer_block_end)
341-
return 0;
337+
while (trailer_iterator_advance(&iter)) {
338+
i++;
339+
if (sob && !strncmp(iter.raw, sob->buf, sob->len))
340+
found_sob = i;
341+
}
342+
trailer_iterator_release(&iter);
342343

343-
for (i = 0; i < info.trailer_nr; i++)
344-
if (sob && !strncmp(info.trailers[i], sob->buf, sob->len)) {
345-
found_sob = 1;
346-
if (i == info.trailer_nr - 1)
347-
found_sob_last = 1;
348-
}
344+
if (!i)
345+
return 0;
349346

350-
trailer_info_release(&info);
347+
found_sob_last = (int)i == found_sob;
351348

352349
if (found_sob_last)
353350
return 3;

0 commit comments

Comments
 (0)