Re: [PATCH v13 00/12] port tag.c to use ref-filter APIs
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 26, 2015, 20:19 UTC
- Message-ID
- <xmqq61413iqy.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <CAOLa=ZS3Fj8EFMp+BXEomeW2PfkBJemoO2-8Tv=RBRb9xGmEyw@mail.gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
Show 10 quoted lines
> On Wed, Aug 26, 2015 at 8:07 PM, Junio C Hamano <gitster@pobox.com> wrote: >> >> ... You can give a new format_ref_array_item() >> that does not print but fills a strbuf to this caller, make >> show_ref_array_item() a thin wrapper that calls it and prints it >> with the final LF for other callers. >> > You're saying remove show_ref_array_item() (even the wrapper you mentioned > above) and just have something like format_ref_array_item() which > would output to a strbuf. and let the caller worry about the printing?
Among the current callers, the one in builtin/tag.c that wants to trigger show_tag_lines() hack embedded in show_ref_array_item() function can stop calling show_ref_array_item() and instead can do
for (i = 0; i < array.nr; i++) {
struct strbuf out = STRBUF_INIT;
format_ref_array_item(&out, ...);
if (filter->lines) {
... append tag lines to out ...
}
printf("%s\n", out.buf);
strbuf_reset(&out);
}
The current and future callers of show_ref_array_item() that do not
want to trigger the show_tag_liens() hack embedded in there may
still want it to print the formatted string including the trailing
LF, so you can keep show_ref_array_item() as a thin wrapper around
format_ref_array_item() for them to call, e.g. show_ref_array_item(...) {
struct strbuf out = STRBUF_INIT;
format_ref_array_item(&out, ...);
printf("%s\n", out.buf);
strbuf_release(&out);
}But if it has only one caller each, you may not even want to have show_ref_array_item(), if you are going to do the "output to strbuf" variant.