Skip to content

Commit 7593d66

Browse files
committed
Merge branch 'la/hide-trailer-info'
The trailer API has been reshuffled a bit. * la/hide-trailer-info: trailer unit tests: inspect iterator contents trailer: document parse_trailers() usage trailer: retire trailer_info_get() from API trailer: make trailer_info struct private trailer: make parse_trailers() return trailer_info pointer interpret-trailers: access trailer_info with new helpers sequencer: use the trailer iterator trailer: teach iterator about non-trailer lines trailer: add unit tests for trailer iterator Makefile: sort UNIT_TEST_PROGRAMS
2 parents 4365c6f + dc88e52 commit 7593d66

File tree

6 files changed

+505
-114
lines changed

6 files changed

+505
-114
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,10 +1334,11 @@ THIRD_PARTY_SOURCES += compat/regex/%
13341334
THIRD_PARTY_SOURCES += sha1collisiondetection/%
13351335
THIRD_PARTY_SOURCES += sha1dc/%
13361336

1337-
UNIT_TEST_PROGRAMS += t-mem-pool
1338-
UNIT_TEST_PROGRAMS += t-strbuf
13391337
UNIT_TEST_PROGRAMS += t-ctype
1338+
UNIT_TEST_PROGRAMS += t-mem-pool
13401339
UNIT_TEST_PROGRAMS += t-prio-queue
1340+
UNIT_TEST_PROGRAMS += t-strbuf
1341+
UNIT_TEST_PROGRAMS += t-trailer
13411342
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
13421343
UNIT_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(UNIT_TEST_PROGRAMS))
13431344
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o

builtin/interpret-trailers.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void interpret_trailers(const struct process_trailer_options *opts,
141141
LIST_HEAD(head);
142142
struct strbuf sb = STRBUF_INIT;
143143
struct strbuf trailer_block = STRBUF_INIT;
144-
struct trailer_info info;
144+
struct trailer_info *info;
145145
FILE *outfile = stdout;
146146

147147
trailer_config_init();
@@ -151,13 +151,13 @@ static void interpret_trailers(const struct process_trailer_options *opts,
151151
if (opts->in_place)
152152
outfile = create_in_place_tempfile(file);
153153

154-
parse_trailers(opts, &info, sb.buf, &head);
154+
info = parse_trailers(opts, sb.buf, &head);
155155

156156
/* Print the lines before the trailers */
157157
if (!opts->only_trailers)
158-
fwrite(sb.buf, 1, info.trailer_block_start, outfile);
158+
fwrite(sb.buf, 1, trailer_block_start(info), outfile);
159159

160-
if (!opts->only_trailers && !info.blank_line_before_trailer)
160+
if (!opts->only_trailers && !blank_line_before_trailer_block(info))
161161
fprintf(outfile, "\n");
162162

163163

@@ -178,8 +178,8 @@ static void interpret_trailers(const struct process_trailer_options *opts,
178178

179179
/* Print the lines after the trailers as is */
180180
if (!opts->only_trailers)
181-
fwrite(sb.buf + info.trailer_block_end, 1, sb.len - info.trailer_block_end, outfile);
182-
trailer_info_release(&info);
181+
fwrite(sb.buf + trailer_block_end(info), 1, sb.len - trailer_block_end(info), outfile);
182+
trailer_info_release(info);
183183

184184
if (opts->in_place)
185185
if (rename_tempfile(&trailers_tempfile, file))

sequencer.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -359,35 +359,32 @@ static const char *get_todo_path(const struct replay_opts *opts)
359359
static int has_conforming_footer(struct strbuf *sb, struct strbuf *sob,
360360
size_t ignore_footer)
361361
{
362-
struct process_trailer_options opts = PROCESS_TRAILER_OPTIONS_INIT;
363-
struct trailer_info info;
364-
size_t i;
362+
struct trailer_iterator iter;
363+
size_t i = 0;
365364
int found_sob = 0, found_sob_last = 0;
366365
char saved_char;
367366

368-
opts.no_divider = 1;
369-
370367
if (ignore_footer) {
371368
saved_char = sb->buf[sb->len - ignore_footer];
372369
sb->buf[sb->len - ignore_footer] = '\0';
373370
}
374371

375-
trailer_info_get(&opts, sb->buf, &info);
372+
trailer_iterator_init(&iter, sb->buf);
376373

377374
if (ignore_footer)
378375
sb->buf[sb->len - ignore_footer] = saved_char;
379376

380-
if (info.trailer_block_start == info.trailer_block_end)
381-
return 0;
377+
while (trailer_iterator_advance(&iter)) {
378+
i++;
379+
if (sob && !strncmp(iter.raw, sob->buf, sob->len))
380+
found_sob = i;
381+
}
382+
trailer_iterator_release(&iter);
382383

383-
for (i = 0; i < info.trailer_nr; i++)
384-
if (sob && !strncmp(info.trailers[i], sob->buf, sob->len)) {
385-
found_sob = 1;
386-
if (i == info.trailer_nr - 1)
387-
found_sob_last = 1;
388-
}
384+
if (!i)
385+
return 0;
389386

390-
trailer_info_release(&info);
387+
found_sob_last = (int)i == found_sob;
391388

392389
if (found_sob_last)
393390
return 3;

0 commit comments

Comments
 (0)