From: Karthik Nayak Date: Thu, 27 Aug 2015 18:00:41 GMT Subject: Re: [PATCH v13 00/12] port tag.c to use ref-filter APIs Message-ID: In-Reply-To: On Thu, Aug 27, 2015 at 1:49 AM, Junio C Hamano wrote: > Karthik Nayak writes: > >> On Wed, Aug 26, 2015 at 8:07 PM, Junio C Hamano 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. > > > This is exactly what I did at the moment, I'm also trying to get %(contents:lines=N) work. Thanks for explaining though. -- Regards, Karthik Nayak