From patchwork Wed Mar 15 11:21:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13175662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C88B0C6FD1D for ; Wed, 15 Mar 2023 11:24:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231812AbjCOLYn (ORCPT ); Wed, 15 Mar 2023 07:24:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231536AbjCOLYZ (ORCPT ); Wed, 15 Mar 2023 07:24:25 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 511ED7A91B for ; Wed, 15 Mar 2023 04:23:33 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id D8BF65C0778 for ; Wed, 15 Mar 2023 07:21:26 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 15 Mar 2023 07:21:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1678879286; x=1678965686; bh=6P sezHLbaOahrxeDzZ7Bbr16bCQWUSGeE2hAekhrP8Y=; b=caZaVAU2lEtb+OolZm kGY9MZXsH6w7vKVDjoRiNUs0Oq9vZfpWt7wCmfKDChIIYa7JZpwrtjxLFyD3uP1F at7Rdb5b0XBK7HumLDgtTRgpTaUY6lBxlVMROv8Sa5cQxbhR06KG853liJOIOXHd kbEfEwGry6O/J2TOaELri4cKyQav7HdfC0McuZ85nI/pZaI8CAEikwFwm0+EymPT T8L0PxlErLCN92Yb2EWoKYjO5sL8kN/cmwGjnreRAenvWs5Gy8TCiDW79mrxbFw9 wpqjAjT+iPz6C7/5Z0U132VzWA3RMvYebnyTaeSwzdTCh0OarGp32Lm7vdmUGYw0 1pAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1678879286; x=1678965686; bh=6PsezHLbaOahr xeDzZ7Bbr16bCQWUSGeE2hAekhrP8Y=; b=PZkDVJe20uZxG59Pvip7K9GEdwb65 Ugb6kajDk6vfQcyoyfeGeiaCyCalBth9gWQyU5/9FRTAzA9SRuc1SCfkrmWPIyCa y2/Ue11JCAHp/U267R0t2JANEONEevO+4zcKVc1O0nVJGtuJ7EY/7SJiQAZil8Nq qhXpBmbD3Xua+z5E2QR0+NNdAZO1oqjebgoA7vaLVSE2fZpH4S/9bwRQjMwgvikj bJfv4hliNaJ1UQ/uoVpd/1nTyNJTS5YkO34tXJ562Z0W3SB9DPVO/2O6lU+LP4fJ 7HirZYf5duMeqBO+Cq4jZrK347njul03+sWNu0Wr2wswmUnkH//Ocm+ZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddvkedgvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesghdtre ertddtvdenucfhrhhomheprfgrthhrihgtkhcuufhtvghinhhhrghrughtuceophhssehp khhsrdhimheqnecuggftrfgrthhtvghrnhepheeghfdtfeeuffehkefgffduleffjedthf dvjeektdfhhedvlefgtefgvdettdfhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomhepphhssehpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 15 Mar 2023 07:21:26 -0400 (EDT) Received: by pks.im (OpenSMTPD) with ESMTPSA id 52eca9bd (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 15 Mar 2023 11:21:03 +0000 (UTC) Date: Wed, 15 Mar 2023 12:21:23 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 5/8] fetch: deduplicate handling of per-reference format Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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); }