Thread (21 messages) 21 messages, 2 authors, 2023-03-22
STALE1189d
Revisions (2)
  1. v1 current
  2. v2 [diff vs current]

[PATCH 5/8] fetch: deduplicate handling of per-reference format

From: Patrick Steinhardt <hidden>
Date: 2023-03-15 11:24:53
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 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

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help