Both callsites that call `format_display()` and then print the result to standard error use the same formatting directive " %s\n" to print the reference to disk, thus duplicating a small part of the logic. Refactor the code to handle this in `format_display()` itself. This paves the way for handling the printing logic in that function completely. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index bf2f01245a..6fc2fd0d46 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -885,13 +885,14 @@ static void format_display(struct display_state *display, width = (summary_width + strlen(summary) - gettext_width(summary)); - strbuf_addf(display_buffer, "%c %-*s ", code, width, summary); + strbuf_addf(display_buffer, " %c %-*s ", code, width, summary); if (!display->compact_format) print_remote_to_local(display, display_buffer, remote, prettify_refname(local)); else print_compact(display, display_buffer, remote, prettify_refname(local)); if (error) strbuf_addf(display_buffer, " (%s)", error); + strbuf_addch(display_buffer, '\n'); } static int update_local_ref(struct ref *ref, @@ -1271,7 +1272,7 @@ static int store_updated_refs(struct display_state *display, url_len, url); shown_url = 1; } - fprintf(stderr, " %s\n", note.buf); + fputs(note.buf, stderr); } } } @@ -1432,7 +1433,7 @@ static int prune_refs(struct display_state *display, format_display(display, &sb, '-', _("[deleted]"), NULL, _("(none)"), ref->name, summary_width); - fprintf(stderr, " %s\n",sb.buf); + fputs(sb.buf, stderr); strbuf_release(&sb); warn_dangling_symref(stderr, dangling_msg, ref->name); } -- 2.40.0