From patchwork Mon Mar 20 12:35:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13181116 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 42F8BC7618D for ; Mon, 20 Mar 2023 12:35:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231331AbjCTMf3 (ORCPT ); Mon, 20 Mar 2023 08:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbjCTMf0 (ORCPT ); Mon, 20 Mar 2023 08:35:26 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3378FD517 for ; Mon, 20 Mar 2023 05:35:24 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 9F3E05C0131; Mon, 20 Mar 2023 08:35:23 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 20 Mar 2023 08:35:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1679315723; x=1679402123; bh=ze Pk+adjeNJUh6bIMny3H9G2s901LOOB0okWYhb+Sgc=; b=nedArSYE4+lb0GEE/T imvBNJXS4Rn3bQav9icQsLHFLdAW4O2dlrd0oqXerwX0fHQnOVEB7HUJ7sjao0zn 557D3vvGj6QYk/PM1+JEFqtCJju4d2jIYelE5bptoau6hnokDYP+AUUH1orQhDCu pWf2LvNU6VuFovu1y3mv0YVBlaBr21h7SusmVLHTDdHsSL2bXoT+iAmnuoOhOE8A j7pC8ATsKiffaeZouweKybWJ0Zo/fYOP4+afpTzROd2OMZH9p+lKxDpGokNTgqil IAezfWD7j3pxMdSM2nYMM8DoE6dYlibWuxIGqqCsVNF3BOTs3wruWiObbE4e8Ddk GiYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1679315723; x=1679402123; bh=zePk+adjeNJUh 6bIMny3H9G2s901LOOB0okWYhb+Sgc=; b=eySxhxeMLzQwQxZYxduHnd1O197mU PVzcWIaHcJAJLHcPgP9sRHDJsR4zw7kaKCigCWSoX1AcM2crny8dw5/K2aJApXGQ 2/0Sk5kXYEKRYJSLvwfOV+jPpQd8Xzq/6gbN/WsOLleKRLth/YTsoQcj/+NGDXvT tEUmGUW0WzdvRqPI7Q7glz3iOBM54VFbyD4oOol2Mo3DGCwqhak8OMgjEf1tr+gp 6l3DMXIW3G7h9o5Uv0gdGfnBDrxHwcNJxMorKWwzOmeYkYX3Tw7dza/iWJXlXPNK ZrE17pQC6gZh5I68Obt/GHZKKDHHoh26KT+pnADfZDD/SUgyYfNcxpVEA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdefkedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Mar 2023 08:35:22 -0400 (EDT) Received: by pks.im (OpenSMTPD) with ESMTPSA id a45c5f95 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 20 Mar 2023 12:34:49 +0000 (UTC) Date: Mon, 20 Mar 2023 13:35:20 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan Subject: [PATCH v2 1/6] fetch: move reference width calculation into `display_state` Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In order to print references in proper columns we need to calculate the width of the reference column before starting to print the references. This is done with the help of a global variable `refcol_width`. Refactor the code to instead use a new structure `display_state` that contains the computed width and plumb it through the stack as required. This is only the first step towards de-globalizing the state required to print references. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 111 ++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index a09606b472..391959ad3d 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -47,6 +47,10 @@ enum { TAGS_SET = 2 }; +struct display_state { + int refcol_width; +}; + static int fetch_prune_config = -1; /* unspecified */ static int fetch_show_forced_updates = 1; static uint64_t forced_updates_ms = 0; @@ -741,16 +745,15 @@ static int s_update_ref(const char *action, return ret; } -static int refcol_width = 10; static int compact_format; -static void adjust_refcol_width(const struct ref *ref) +static int refcol_width(const struct ref *ref) { int max, rlen, llen, len; /* uptodate lines are only shown on high verbosity level */ if (verbosity <= 0 && oideq(&ref->peer_ref->old_oid, &ref->old_oid)) - return; + return 0; max = term_columns(); rlen = utf8_strwidth(prettify_refname(ref->name)); @@ -769,22 +772,18 @@ static void adjust_refcol_width(const struct ref *ref) } len = 21 /* flag and summary */ + rlen + 4 /* -> */ + llen; if (len >= max) - return; + return 0; - /* - * Not precise calculation for compact mode because '*' can - * appear on the left hand side of '->' and shrink the column - * back. - */ - if (refcol_width < rlen) - refcol_width = rlen; + return rlen; } -static void prepare_format_display(struct ref *ref_map) +static void display_state_init(struct display_state *display_state, struct ref *ref_map) { struct ref *rm; const char *format = "full"; + memset(display_state, 0, sizeof(*display_state)); + if (verbosity < 0) return; @@ -797,20 +796,32 @@ static void prepare_format_display(struct ref *ref_map) die(_("invalid value for '%s': '%s'"), "fetch.output", format); + display_state->refcol_width = 10; for (rm = ref_map; rm; rm = rm->next) { + int width; + if (rm->status == REF_STATUS_REJECT_SHALLOW || !rm->peer_ref || !strcmp(rm->name, "HEAD")) continue; - adjust_refcol_width(rm); + width = refcol_width(rm); + + /* + * Not precise calculation for compact mode because '*' can + * appear on the left hand side of '->' and shrink the column + * back. + */ + if (display_state->refcol_width < width) + display_state->refcol_width = width; } } -static void print_remote_to_local(struct strbuf *display, +static void print_remote_to_local(struct display_state *display_state, + struct strbuf *display_buffer, const char *remote, const char *local) { - strbuf_addf(display, "%-*s -> %s", refcol_width, remote, local); + strbuf_addf(display_buffer, "%-*s -> %s", display_state->refcol_width, remote, local); } static int find_and_replace(struct strbuf *haystack, @@ -840,14 +851,14 @@ static int find_and_replace(struct strbuf *haystack, return 1; } -static void print_compact(struct strbuf *display, +static void print_compact(struct display_state *display_state, struct strbuf *display_buffer, const char *remote, const char *local) { struct strbuf r = STRBUF_INIT; struct strbuf l = STRBUF_INIT; if (!strcmp(remote, local)) { - strbuf_addf(display, "%-*s -> *", refcol_width, remote); + strbuf_addf(display_buffer, "%-*s -> *", display_state->refcol_width, remote); return; } @@ -856,13 +867,14 @@ static void print_compact(struct strbuf *display, if (!find_and_replace(&r, local, "*")) find_and_replace(&l, remote, "*"); - print_remote_to_local(display, r.buf, l.buf); + print_remote_to_local(display_state, display_buffer, r.buf, l.buf); strbuf_release(&r); strbuf_release(&l); } -static void format_display(struct strbuf *display, char code, +static void format_display(struct display_state *display_state, + struct strbuf *display_buffer, char code, const char *summary, const char *error, const char *remote, const char *local, int summary_width) @@ -874,17 +886,18 @@ static void format_display(struct strbuf *display, char code, width = (summary_width + strlen(summary) - gettext_width(summary)); - strbuf_addf(display, "%c %-*s ", code, width, summary); + strbuf_addf(display_buffer, "%c %-*s ", code, width, summary); if (!compact_format) - print_remote_to_local(display, remote, local); + print_remote_to_local(display_state, display_buffer, remote, local); else - print_compact(display, remote, local); + print_compact(display_state, display_buffer, remote, local); if (error) - strbuf_addf(display, " (%s)", error); + strbuf_addf(display_buffer, " (%s)", error); } static int update_local_ref(struct ref *ref, struct ref_transaction *transaction, + struct display_state *display_state, const char *remote, const struct ref *remote_ref, struct strbuf *display, int summary_width) { @@ -897,7 +910,7 @@ static int update_local_ref(struct ref *ref, if (oideq(&ref->old_oid, &ref->new_oid)) { if (verbosity > 0) - format_display(display, '=', _("[up to date]"), NULL, + format_display(display_state, display, '=', _("[up to date]"), NULL, remote, pretty_ref, summary_width); return 0; } @@ -909,7 +922,7 @@ static int update_local_ref(struct ref *ref, * If this is the head, and it's not okay to update * the head, and the old value of the head isn't empty... */ - format_display(display, '!', _("[rejected]"), + format_display(display_state, display, '!', _("[rejected]"), _("can't fetch into checked-out branch"), remote, pretty_ref, summary_width); return 1; @@ -920,12 +933,13 @@ static int update_local_ref(struct ref *ref, if (force || ref->force) { int r; r = s_update_ref("updating tag", ref, transaction, 0); - format_display(display, r ? '!' : 't', _("[tag update]"), + format_display(display_state, display, r ? '!' : 't', _("[tag update]"), r ? _("unable to update local ref") : NULL, remote, pretty_ref, summary_width); return r; } else { - format_display(display, '!', _("[rejected]"), _("would clobber existing tag"), + format_display(display_state, display, '!', _("[rejected]"), + _("would clobber existing tag"), remote, pretty_ref, summary_width); return 1; } @@ -957,7 +971,7 @@ static int update_local_ref(struct ref *ref, } r = s_update_ref(msg, ref, transaction, 0); - format_display(display, r ? '!' : '*', what, + format_display(display_state, display, r ? '!' : '*', what, r ? _("unable to update local ref") : NULL, remote, pretty_ref, summary_width); return r; @@ -979,7 +993,7 @@ static int update_local_ref(struct ref *ref, strbuf_addstr(&quickref, ".."); strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); r = s_update_ref("fast-forward", ref, transaction, 1); - format_display(display, r ? '!' : ' ', quickref.buf, + format_display(display_state, display, r ? '!' : ' ', quickref.buf, r ? _("unable to update local ref") : NULL, remote, pretty_ref, summary_width); strbuf_release(&quickref); @@ -991,13 +1005,13 @@ static int update_local_ref(struct ref *ref, strbuf_addstr(&quickref, "..."); strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); r = s_update_ref("forced-update", ref, transaction, 1); - format_display(display, r ? '!' : '+', quickref.buf, + format_display(display_state, display, r ? '!' : '+', quickref.buf, r ? _("unable to update local ref") : _("forced update"), remote, pretty_ref, summary_width); strbuf_release(&quickref); return r; } else { - format_display(display, '!', _("[rejected]"), _("non-fast-forward"), + format_display(display_state, display, '!', _("[rejected]"), _("non-fast-forward"), remote, pretty_ref, summary_width); return 1; } @@ -1108,7 +1122,8 @@ N_("it took %.2f seconds to check forced updates; you can use\n" "'--no-show-forced-updates' or run 'git config fetch.showForcedUpdates false'\n" "to avoid this check\n"); -static int store_updated_refs(const char *raw_url, const char *remote_name, +static int store_updated_refs(struct display_state *display_state, + const char *raw_url, const char *remote_name, int connectivity_checked, struct ref_transaction *transaction, struct ref *ref_map, struct fetch_head *fetch_head) @@ -1139,8 +1154,6 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, } } - prepare_format_display(ref_map); - /* * We do a pass for each fetch_head_status type in their enum order, so * merged entries are written before not-for-merge. That lets readers @@ -1240,7 +1253,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, strbuf_reset(¬e); if (ref) { - rc |= update_local_ref(ref, transaction, what, + rc |= update_local_ref(ref, transaction, display_state, what, rm, ¬e, summary_width); free(ref); } else if (write_fetch_head || dry_run) { @@ -1249,7 +1262,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, * would be written to FETCH_HEAD, if --dry-run * is set). */ - format_display(¬e, '*', + format_display(display_state, ¬e, '*', *kind ? kind : "branch", NULL, *what ? what : "HEAD", "FETCH_HEAD", summary_width); @@ -1328,7 +1341,8 @@ static int check_exist_and_connected(struct ref *ref_map) return check_connected(iterate_ref_map, &rm, &opt); } -static int fetch_and_consume_refs(struct transport *transport, +static int fetch_and_consume_refs(struct display_state *display_state, + struct transport *transport, struct ref_transaction *transaction, struct ref *ref_map, struct fetch_head *fetch_head) @@ -1352,7 +1366,7 @@ static int fetch_and_consume_refs(struct transport *transport, } trace2_region_enter("fetch", "consume_refs", the_repository); - ret = store_updated_refs(transport->url, transport->remote->name, + ret = store_updated_refs(display_state, transport->url, transport->remote->name, connectivity_checked, transaction, ref_map, fetch_head); trace2_region_leave("fetch", "consume_refs", the_repository); @@ -1362,7 +1376,8 @@ static int fetch_and_consume_refs(struct transport *transport, return ret; } -static int prune_refs(struct refspec *rs, +static int prune_refs(struct display_state *display_state, + struct refspec *rs, struct ref_transaction *transaction, struct ref *ref_map, const char *raw_url) @@ -1416,7 +1431,7 @@ static int prune_refs(struct refspec *rs, fprintf(stderr, _("From %.*s\n"), url_len, url); shown_url = 1; } - format_display(&sb, '-', _("[deleted]"), NULL, + format_display(display_state, &sb, '-', _("[deleted]"), NULL, _("(none)"), prettify_refname(ref->name), summary_width); fprintf(stderr, " %s\n",sb.buf); @@ -1542,7 +1557,8 @@ static struct transport *prepare_transport(struct remote *remote, int deepen) return transport; } -static int backfill_tags(struct transport *transport, +static int backfill_tags(struct display_state *display_state, + struct transport *transport, struct ref_transaction *transaction, struct ref *ref_map, struct fetch_head *fetch_head) @@ -1566,7 +1582,7 @@ static int backfill_tags(struct transport *transport, transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, NULL); transport_set_option(transport, TRANS_OPT_DEPTH, "0"); transport_set_option(transport, TRANS_OPT_DEEPEN_RELATIVE, NULL); - retcode = fetch_and_consume_refs(transport, transaction, ref_map, fetch_head); + retcode = fetch_and_consume_refs(display_state, transport, transaction, ref_map, fetch_head); if (gsecondary) { transport_disconnect(gsecondary); @@ -1581,6 +1597,7 @@ static int do_fetch(struct transport *transport, { struct ref_transaction *transaction = NULL; struct ref *ref_map = NULL; + struct display_state display_state; int autotags = (transport->remote->fetch_tags == 1); int retcode = 0; const struct ref *remote_refs; @@ -1662,6 +1679,8 @@ static int do_fetch(struct transport *transport, if (retcode) goto cleanup; + display_state_init(&display_state, ref_map); + if (atomic_fetch) { transaction = ref_transaction_begin(&err); if (!transaction) { @@ -1679,9 +1698,9 @@ static int do_fetch(struct transport *transport, * don't care whether --tags was specified. */ if (rs->nr) { - retcode = prune_refs(rs, transaction, ref_map, transport->url); + retcode = prune_refs(&display_state, rs, transaction, ref_map, transport->url); } else { - retcode = prune_refs(&transport->remote->fetch, + retcode = prune_refs(&display_state, &transport->remote->fetch, transaction, ref_map, transport->url); } @@ -1689,7 +1708,7 @@ static int do_fetch(struct transport *transport, retcode = 1; } - if (fetch_and_consume_refs(transport, transaction, ref_map, &fetch_head)) { + if (fetch_and_consume_refs(&display_state, transport, transaction, ref_map, &fetch_head)) { retcode = 1; goto cleanup; } @@ -1711,7 +1730,7 @@ static int do_fetch(struct transport *transport, * when `--atomic` is passed: in that case we'll abort * the transaction and don't commit anything. */ - if (backfill_tags(transport, transaction, tags_ref_map, + if (backfill_tags(&display_state, transport, transaction, tags_ref_map, &fetch_head)) retcode = 1; } From patchwork Mon Mar 20 12:35:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13181117 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 E9E30C7618A for ; Mon, 20 Mar 2023 12:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231400AbjCTMfj (ORCPT ); Mon, 20 Mar 2023 08:35:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231251AbjCTMf3 (ORCPT ); Mon, 20 Mar 2023 08:35:29 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 946211E1F6 for ; Mon, 20 Mar 2023 05:35:27 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 0FEA15C012A; Mon, 20 Mar 2023 08:35:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 20 Mar 2023 08:35:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1679315727; x=1679402127; bh=j1 TJKT+Db9uRZq35IyOPM458YgvTXanWdJd5ewctBZM=; b=GN9NBRQb+9TzZIUp4Y lLhWsIfHbW68LQM0Jtw/ZqA5a18vVixeXzXfmSwXuXNIjNDoRmK2EJHKOYAPv8n9 mMVRv45V9NXHJsnWNkmUUCJ05Pul0ntzr7UquWZGoCH5dZIN4lSKIvDEGbuHMGMX hy1KeUkjnvJnyE+gAD93dI3Z1cjbI0brjbnNU2o5nT58mi4kbiZ7ulnLQQssAaVa WgkxBqrHqHXlZezd9Ara5N9vdsF4veMZehntd+MkEI16aO0lePUhCMKij8RqFIe3 4WO4iPZ/kgoy825QOaJj/QSd10NATN/LZDq9qNj291tOZtb9sc+KGxHNTK9is0Ez 1gRQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1679315727; x=1679402127; bh=j1TJKT+Db9uRZ q35IyOPM458YgvTXanWdJd5ewctBZM=; b=FXei37DdF92J3S5WIaWFMgRP3CA7k QlFotWXtstaQMKzo4XDn9t+Kj8+7jkUvhcmNpaiq6XG8i8pgjdnbh/BkqTCzs2qj ptxvsO5Pjs3mxG9bHeSe4tRrwB54ccsjORHdLfPw5sJNB5dckDk4/vwNEvetpYED o1/1PwzxvAq82UVYB7DiWxVoHlVt5KLLzWQFp61rGFANCbyTfEb3efuZlvJW0HFP UlR0q7jdMm1VrzXU/tTuXnkpcgyZ6bqS793HODyhwgeKJb0sWiXojpPcXxy0fTuB DqZWg+bWkgBOugkiEbKE0lrjqkaQ+Yn2z/+lwGJ16Emq9BmTc+ziVNr7w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdefkedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Mar 2023 08:35:25 -0400 (EDT) Received: by pks.im (OpenSMTPD) with ESMTPSA id 79e3e5a9 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 20 Mar 2023 12:34:53 +0000 (UTC) Date: Mon, 20 Mar 2023 13:35:24 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan Subject: [PATCH v2 2/6] fetch: move output format into `display_state` Message-ID: <34eedb882cf06ddc6dba9027d15872527c4500b6.1679315383.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The git-fetch(1) command supports printing references either in "full" or "compact" format depending on the `fetch.ouput` config key. The format that is to be used is tracked in a global variable. De-globalize the variable by moving it into the `display_state` structure. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 391959ad3d..6d6146b0f0 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -49,6 +49,7 @@ enum { struct display_state { int refcol_width; + int compact_format; }; static int fetch_prune_config = -1; /* unspecified */ @@ -745,9 +746,7 @@ static int s_update_ref(const char *action, return ret; } -static int compact_format; - -static int refcol_width(const struct ref *ref) +static int refcol_width(const struct ref *ref, int compact_format) { int max, rlen, llen, len; @@ -789,9 +788,9 @@ static void display_state_init(struct display_state *display_state, struct ref * git_config_get_string_tmp("fetch.output", &format); if (!strcasecmp(format, "full")) - compact_format = 0; + display_state->compact_format = 0; else if (!strcasecmp(format, "compact")) - compact_format = 1; + display_state->compact_format = 1; else die(_("invalid value for '%s': '%s'"), "fetch.output", format); @@ -805,7 +804,7 @@ static void display_state_init(struct display_state *display_state, struct ref * !strcmp(rm->name, "HEAD")) continue; - width = refcol_width(rm); + width = refcol_width(rm, display_state->compact_format); /* * Not precise calculation for compact mode because '*' can @@ -887,7 +886,7 @@ static void format_display(struct display_state *display_state, width = (summary_width + strlen(summary) - gettext_width(summary)); strbuf_addf(display_buffer, "%c %-*s ", code, width, summary); - if (!compact_format) + if (!display_state->compact_format) print_remote_to_local(display_state, display_buffer, remote, local); else print_compact(display_state, display_buffer, remote, local); From patchwork Mon Mar 20 12:35:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13181118 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 BA535C7618D for ; Mon, 20 Mar 2023 12:35:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231240AbjCTMfm (ORCPT ); Mon, 20 Mar 2023 08:35:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231386AbjCTMfh (ORCPT ); Mon, 20 Mar 2023 08:35:37 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1E7B25E3F for ; Mon, 20 Mar 2023 05:35:31 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 6707F5C0131; Mon, 20 Mar 2023 08:35:31 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 20 Mar 2023 08:35:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1679315731; x=1679402131; bh=BR uIpMH3CafjO0UcNT8YNKhcmfP39jg6jFYc0/V2bQA=; b=GCBhSSMhfTUhm+7Uim EvCb6kUbrhWzozqbQhsfrgDCxL+XZidfJeyShHfOOWs0+aewEVQ64Zlvfg45tYma c7Zy3uky65atuwfziZGcHJ5oDPP+WBahClyNdbbY2M8msay7MkJcEX1nQwOr2YSR caNVo7t8rBfy4m7krJuYT2AJDqH5RTTF3j+CcYz0cfELKj/jLqIbWxigckt4lVYp cdQq2aoGQTASdcLQILgwzKog2cWpCGPo1sS824lrEGddnOxYKggK9Z50VUeSK1aY /i4Gq2bj+jH7XLTspEaEJvrNEDSUDI+SppyJQu1mdI08Xx6Q6A84KkrIu6HLPXVs hFHw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1679315731; x=1679402131; bh=BRuIpMH3CafjO 0UcNT8YNKhcmfP39jg6jFYc0/V2bQA=; b=ValJ+5cBblS6o6kG6PnEylY+0aVvn y+p4NOVkA6sXBDTOUFxr5N1s0y57iG8tYnSQYWwSgJFnrSePXM4rlCPS6fO8muc5 bVB9bJdN1GrbDyV0S62fS2DllgnXZcFdFjf380GAjxYsHDITNpq7THiHb5KAb7rd 11vVtmrE3CnRM6bc/bMg450ZVo5mBS06zTbpzKdVpTJAVsMEGHQn4EnR6YI2hFWH WNMattF9lnEFzHYZJytu9c0q/zDnnoQqqi19GvIw8Sfb9rr0ges2MY363QALBQ80 90h0tFGIyHS/Ig6KhLHucAFCB6LVPMjMQuMFUkc9AK3dz1dNAUtX5qGdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdefkedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Mar 2023 08:35:30 -0400 (EDT) Received: by pks.im (OpenSMTPD) with ESMTPSA id a95865ca (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 20 Mar 2023 12:34:57 +0000 (UTC) Date: Mon, 20 Mar 2023 13:35:28 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan Subject: [PATCH v2 3/6] fetch: pass the full local reference name to `format_display` Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Before printing the name of the local references that would be updated by a fetch we first prettify the reference name. This is done at the calling side so that `format_display()` never sees the full name of the local reference. This restricts our ability to introduce new output formats that might want to print the full reference name. Right now, all callsites except one are prettifying the reference name anyway. And the only callsite that doesn't passes `FETCH_HEAD` as the hardcoded reference name to `format_display()`, which would never be changed by a call to `prettify_refname()` anyway. So let's refactor the code to pass in the full local reference name and then prettify it in the formatting code. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 6d6146b0f0..81ba3900cb 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -887,9 +887,9 @@ static void format_display(struct display_state *display_state, strbuf_addf(display_buffer, "%c %-*s ", code, width, summary); if (!display_state->compact_format) - print_remote_to_local(display_state, display_buffer, remote, local); + print_remote_to_local(display_state, display_buffer, remote, prettify_refname(local)); else - print_compact(display_state, display_buffer, remote, local); + print_compact(display_state, display_buffer, remote, prettify_refname(local)); if (error) strbuf_addf(display_buffer, " (%s)", error); } @@ -901,7 +901,6 @@ static int update_local_ref(struct ref *ref, struct strbuf *display, int summary_width) { struct commit *current = NULL, *updated; - const char *pretty_ref = prettify_refname(ref->name); int fast_forward = 0; if (!repo_has_object_file(the_repository, &ref->new_oid)) @@ -910,7 +909,7 @@ static int update_local_ref(struct ref *ref, if (oideq(&ref->old_oid, &ref->new_oid)) { if (verbosity > 0) format_display(display_state, display, '=', _("[up to date]"), NULL, - remote, pretty_ref, summary_width); + remote, ref->name, summary_width); return 0; } @@ -923,7 +922,7 @@ static int update_local_ref(struct ref *ref, */ format_display(display_state, display, '!', _("[rejected]"), _("can't fetch into checked-out branch"), - remote, pretty_ref, summary_width); + remote, ref->name, summary_width); return 1; } @@ -934,12 +933,12 @@ static int update_local_ref(struct ref *ref, r = s_update_ref("updating tag", ref, transaction, 0); format_display(display_state, display, r ? '!' : 't', _("[tag update]"), r ? _("unable to update local ref") : NULL, - remote, pretty_ref, summary_width); + remote, ref->name, summary_width); return r; } else { format_display(display_state, display, '!', _("[rejected]"), _("would clobber existing tag"), - remote, pretty_ref, summary_width); + remote, ref->name, summary_width); return 1; } } @@ -972,7 +971,7 @@ static int update_local_ref(struct ref *ref, r = s_update_ref(msg, ref, transaction, 0); format_display(display_state, display, r ? '!' : '*', what, r ? _("unable to update local ref") : NULL, - remote, pretty_ref, summary_width); + remote, ref->name, summary_width); return r; } @@ -994,7 +993,7 @@ static int update_local_ref(struct ref *ref, r = s_update_ref("fast-forward", ref, transaction, 1); format_display(display_state, display, r ? '!' : ' ', quickref.buf, r ? _("unable to update local ref") : NULL, - remote, pretty_ref, summary_width); + remote, ref->name, summary_width); strbuf_release(&quickref); return r; } else if (force || ref->force) { @@ -1006,12 +1005,12 @@ static int update_local_ref(struct ref *ref, r = s_update_ref("forced-update", ref, transaction, 1); format_display(display_state, display, r ? '!' : '+', quickref.buf, r ? _("unable to update local ref") : _("forced update"), - remote, pretty_ref, summary_width); + remote, ref->name, summary_width); strbuf_release(&quickref); return r; } else { format_display(display_state, display, '!', _("[rejected]"), _("non-fast-forward"), - remote, pretty_ref, summary_width); + remote, ref->name, summary_width); return 1; } } @@ -1431,7 +1430,7 @@ static int prune_refs(struct display_state *display_state, shown_url = 1; } format_display(display_state, &sb, '-', _("[deleted]"), NULL, - _("(none)"), prettify_refname(ref->name), + _("(none)"), ref->name, summary_width); fprintf(stderr, " %s\n",sb.buf); strbuf_release(&sb); From patchwork Mon Mar 20 12:35:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13181119 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 C0EF8C7618A for ; Mon, 20 Mar 2023 12:35:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231422AbjCTMfu (ORCPT ); Mon, 20 Mar 2023 08:35:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231395AbjCTMfj (ORCPT ); Mon, 20 Mar 2023 08:35:39 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49A421C7F9 for ; Mon, 20 Mar 2023 05:35:35 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id B6C745C0176; Mon, 20 Mar 2023 08:35:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 20 Mar 2023 08:35:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1679315734; x=1679402134; bh=tM OWCJ/PUxNppbY0RHiJmakpjYgYT/Ht+AFXXQNinDw=; b=jIJN+C7Y+Z6ym5exIS d3BmS6HCP8IinFuQ3xzzNTYLtncL5gIQOjVpEoJT7FAn1ryVElvMnESmn6vYV5xC NH7KYApHGsnEIzZaGIaK+ZO43rzSSPQnYzQz429Wc+EsdHUOmnMPKJKYhkkWDmXz s+j3E9eUAAVzm9pDzJ/aJDGeNTb4RWaoxQ4lyR+ZO/ZJbvVz26p9wIhKT8Srys6Q CPVy887EbGUmv1J6KGI8ZbQ/u9J9m6Tgrro2BGzD/2hH3F4V5iyZbnRu1yfk6zLF 6heXLO4h2nk6NyI62XKsnzEo5iPZCrp23RGpAGIZYr1ti9MHI6N7FpmLo/llLWvT 3EMg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1679315734; x=1679402134; bh=tMOWCJ/PUxNpp bY0RHiJmakpjYgYT/Ht+AFXXQNinDw=; b=GPcUSXUYkQ22CXOiDzvaS5h/wrOdf mmu7UuOVDO2l4ObGJz9thEoyDfJ9syGLAebrArh/Js2Ezl1mb+WIE1IFTwHAF9JK rKHLnvxArvxjFaNKAjQZv+fVvJzhI6xOxR8pWQd5v2J1pjCaYdiuv0HuzoBSc8qU Zs/Ew7qYRzc/MjBImY1L2C+C4lR1NGwlUBG4uvPxqoNNys6w72fbV7ejafy4eIWU CWNoxAANL8oozKytbp+0F0xTIN8/Wy8PwFZdSizxJjot+H++0s5MHIyAxEBMyYys aiOKrXn6Q8x3Y35R/VNtLSBakg+GCrOvtw09m9s0pJk74jG32F99uqp/w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdefkedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Mar 2023 08:35:33 -0400 (EDT) Received: by pks.im (OpenSMTPD) with ESMTPSA id 059b5e82 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 20 Mar 2023 12:35:01 +0000 (UTC) Date: Mon, 20 Mar 2023 13:35:32 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan Subject: [PATCH v2 4/6] fetch: centralize 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 The function `format_display()` is used to print a single reference update to a buffer which will then ultimately be printed by the caller. This architecture causes us to duplicate some logic across the different callsites of this function. This makes it hard to follow the code as some parts of the logic are located in one place, while other parts of the logic are located in a different place. Furthermore, by having the logic scattered around it becomes quite hard to implement a new output format for the reference updates. We can make the logic a whole lot easier to understand by making the `format_display()` function self-contained so that it handles formatting and printing of the references. This will eventually allow us to easily implement a completely different output format, but also opens the door to conditionally print to either stdout or stderr depending on the output format. As a first step towards that goal we move the formatting directive used by both callers to print a single reference update into this function. 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 81ba3900cb..a66428dfd8 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -885,13 +885,14 @@ static void format_display(struct display_state *display_state, 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_state->compact_format) print_remote_to_local(display_state, display_buffer, remote, prettify_refname(local)); else print_compact(display_state, 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_state, 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_state, format_display(display_state, &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); } From patchwork Mon Mar 20 12:35:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13181120 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 D49AFC6FD1D for ; Mon, 20 Mar 2023 12:35:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231426AbjCTMf4 (ORCPT ); Mon, 20 Mar 2023 08:35:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbjCTMfn (ORCPT ); Mon, 20 Mar 2023 08:35:43 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 069B4EC7E for ; Mon, 20 Mar 2023 05:35:40 -0700 (PDT) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 1B5B75C0131; Mon, 20 Mar 2023 08:35:39 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 20 Mar 2023 08:35:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1679315739; x=1679402139; bh=Xk vtuEbi8/79oCRjxPo+Uf9KGO+92MC1P1zYUnQeGLg=; b=dxpci67aOkgxyJldGa MZbm03utOgzEaNG85w3lgGRB1+ct6MFD7YsadfaNj9nnNkPxYF2Gf7yWL6KoqaV7 RnX8Hx3djYCYtzSGdhNGJWoimoRdMnrK85FAeIHnHEIgMKoHzMC6azow3yVfBVHS 6GNmdaStcGUzl1RGkvdy9+o13nKsL9u6Lq7yxAJMtRMWU/oVNxd4jPnGQTkYL5ia +o8+GXADzG37ByaCP3+WLAYDn5cHvKIK/w/UE6uGqj7ZTHDG06AUCpXz5ZVAinzp 2rXxkodT59j9zIcOEO2otnpXU1GaX0Mjx/7xjBPs9ECG0vVqGXloV/q8i1RZTQgp SOjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1679315739; x=1679402139; bh=XkvtuEbi8/79o CRjxPo+Uf9KGO+92MC1P1zYUnQeGLg=; b=XfTKdrGX2RV+sdCuXrfAPfln2tkbh g1/M0Yr6PTz4MwXkwWesoY3+1LABE1x0Q71JPbacBndJRDVp1A4omz+AlDa+7OQR vv0fUE4eNyj953fBATKJxRYIMmGz2Zw7MsZk4u+Pzud9tGDmVsEZTTSLqLeW4V93 +uJN3JDoc2vEHoeR+yd6iizy0mj3qt/BXGN1RgLvaJ4aXRCG3qhIDv+eMjs3KVaH vJaYEepj+ZVwBptD/STxOqZ3+iXQ/DzDB7y6uD/Oj4kHdwAImMFwRGzAbzMiXBOd bYpkc5AJQbYxg9dTXuhYt8vbqh2KmUGqxIyIZ06P02KUxK+t1Aptg2iUQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdefkedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpeefnecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Mar 2023 08:35:37 -0400 (EDT) Received: by pks.im (OpenSMTPD) with ESMTPSA id a5b0691d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 20 Mar 2023 12:35:05 +0000 (UTC) Date: Mon, 20 Mar 2023 13:35:36 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan Subject: [PATCH v2 5/6] fetch: centralize logic to print remote URL Message-ID: <98b799af713b2ff22cc79531d5057fda64ddfb2a.1679315383.git.ps@pks.im> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When fetching from a remote, we not only print the actual references that have changed, but will also print the URL from which we have fetched them to standard output. The logic to handle this is duplicated across two different callsites with some non-trivial logic to compute the anonymized URL. Furthermore, we're using global state to track whether we have already shown the URL to the user or not. Refactor the code by moving it into `format_display()`. Like this, we can convert the global variable into a member of `display_state`. And second, we can deduplicate the logic to compute the anonymized URL. This also works as expected when fetching from multiple remotes, for example via a group of remotes, as we do this by forking a standalone git-fetch(1) process per remote that is to be fetched. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 99 ++++++++++++++++++++++--------------------------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index a66428dfd8..1e3599cb74 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -50,6 +50,9 @@ enum { struct display_state { int refcol_width; int compact_format; + + char *url; + int url_len, shown_url; }; static int fetch_prune_config = -1; /* unspecified */ @@ -84,7 +87,6 @@ static const char *submodule_prefix = ""; static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; static int recurse_submodules_cli = RECURSE_SUBMODULES_DEFAULT; static int recurse_submodules_default = RECURSE_SUBMODULES_ON_DEMAND; -static int shown_url = 0; static struct refspec refmap = REFSPEC_INIT_FETCH; static struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT; static struct string_list server_options = STRING_LIST_INIT_DUP; @@ -776,13 +778,27 @@ static int refcol_width(const struct ref *ref, int compact_format) return rlen; } -static void display_state_init(struct display_state *display_state, struct ref *ref_map) +static void display_state_init(struct display_state *display_state, struct ref *ref_map, + const char *raw_url) { struct ref *rm; const char *format = "full"; + int i; memset(display_state, 0, sizeof(*display_state)); + if (raw_url) + display_state->url = transport_anonymize_url(raw_url); + else + display_state->url = xstrdup("foreign"); + + display_state->url_len = strlen(display_state->url); + for (i = display_state->url_len - 1; display_state->url[i] == '/' && 0 <= i; i--) + ; + display_state->url_len = i + 1; + if (4 < i && !strncmp(".git", display_state->url + i - 3, 4)) + display_state->url_len = i - 3; + if (verbosity < 0) return; @@ -816,6 +832,11 @@ static void display_state_init(struct display_state *display_state, struct ref * } } +static void display_state_release(struct display_state *display_state) +{ + free(display_state->url); +} + static void print_remote_to_local(struct display_state *display_state, struct strbuf *display_buffer, const char *remote, const char *local) @@ -883,6 +904,12 @@ static void format_display(struct display_state *display_state, if (verbosity < 0) return; + if (!display_state->shown_url) { + strbuf_addf(display_buffer, _("From %.*s\n"), + display_state->url_len, display_state->url); + display_state->shown_url = 1; + } + width = (summary_width + strlen(summary) - gettext_width(summary)); strbuf_addf(display_buffer, " %c %-*s ", code, width, summary); @@ -1122,33 +1149,28 @@ N_("it took %.2f seconds to check forced updates; you can use\n" "to avoid this check\n"); static int store_updated_refs(struct display_state *display_state, - const char *raw_url, const char *remote_name, + const char *remote_name, int connectivity_checked, struct ref_transaction *transaction, struct ref *ref_map, struct fetch_head *fetch_head) { - int url_len, i, rc = 0; + int rc = 0; struct strbuf note = STRBUF_INIT; const char *what, *kind; struct ref *rm; - char *url; int want_status; int summary_width = 0; if (verbosity >= 0) summary_width = transport_summary_width(ref_map); - if (raw_url) - url = transport_anonymize_url(raw_url); - else - url = xstrdup("foreign"); - if (!connectivity_checked) { struct check_connected_options opt = CHECK_CONNECTED_INIT; rm = ref_map; if (check_connected(iterate_ref_map, &rm, &opt)) { - rc = error(_("%s did not send all necessary objects\n"), url); + rc = error(_("%s did not send all necessary objects\n"), + display_state->url); goto abort; } } @@ -1232,13 +1254,6 @@ static int store_updated_refs(struct display_state *display_state, what = rm->name; } - url_len = strlen(url); - for (i = url_len - 1; url[i] == '/' && 0 <= i; i--) - ; - url_len = i + 1; - if (4 < i && !strncmp(".git", url + i - 3, 4)) - url_len = i - 3; - strbuf_reset(¬e); if (*what) { if (*kind) @@ -1248,7 +1263,8 @@ static int store_updated_refs(struct display_state *display_state, append_fetch_head(fetch_head, &rm->old_oid, rm->fetch_head_status, - note.buf, url, url_len); + note.buf, display_state->url, + display_state->url_len); strbuf_reset(¬e); if (ref) { @@ -1266,14 +1282,8 @@ static int store_updated_refs(struct display_state *display_state, *what ? what : "HEAD", "FETCH_HEAD", summary_width); } - if (note.len) { - if (!shown_url) { - fprintf(stderr, _("From %.*s\n"), - url_len, url); - shown_url = 1; - } + if (note.len) fputs(note.buf, stderr); - } } } @@ -1293,7 +1303,6 @@ static int store_updated_refs(struct display_state *display_state, abort: strbuf_release(¬e); - free(url); return rc; } @@ -1365,7 +1374,7 @@ static int fetch_and_consume_refs(struct display_state *display_state, } trace2_region_enter("fetch", "consume_refs", the_repository); - ret = store_updated_refs(display_state, transport->url, transport->remote->name, + ret = store_updated_refs(display_state, transport->remote->name, connectivity_checked, transaction, ref_map, fetch_head); trace2_region_leave("fetch", "consume_refs", the_repository); @@ -1378,30 +1387,15 @@ static int fetch_and_consume_refs(struct display_state *display_state, static int prune_refs(struct display_state *display_state, struct refspec *rs, struct ref_transaction *transaction, - struct ref *ref_map, - const char *raw_url) + struct ref *ref_map) { - int url_len, i, result = 0; + int result = 0; struct ref *ref, *stale_refs = get_stale_heads(rs, ref_map); struct strbuf err = STRBUF_INIT; - char *url; const char *dangling_msg = dry_run ? _(" (%s will become dangling)") : _(" (%s has become dangling)"); - if (raw_url) - url = transport_anonymize_url(raw_url); - else - url = xstrdup("foreign"); - - url_len = strlen(url); - for (i = url_len - 1; url[i] == '/' && 0 <= i; i--) - ; - - url_len = i + 1; - if (4 < i && !strncmp(".git", url + i - 3, 4)) - url_len = i - 3; - if (!dry_run) { if (transaction) { for (ref = stale_refs; ref; ref = ref->next) { @@ -1426,10 +1420,6 @@ static int prune_refs(struct display_state *display_state, for (ref = stale_refs; ref; ref = ref->next) { struct strbuf sb = STRBUF_INIT; - if (!shown_url) { - fprintf(stderr, _("From %.*s\n"), url_len, url); - shown_url = 1; - } format_display(display_state, &sb, '-', _("[deleted]"), NULL, _("(none)"), ref->name, summary_width); @@ -1441,7 +1431,6 @@ static int prune_refs(struct display_state *display_state, cleanup: strbuf_release(&err); - free(url); free_refs(stale_refs); return result; } @@ -1596,7 +1585,7 @@ static int do_fetch(struct transport *transport, { struct ref_transaction *transaction = NULL; struct ref *ref_map = NULL; - struct display_state display_state; + struct display_state display_state = { 0 }; int autotags = (transport->remote->fetch_tags == 1); int retcode = 0; const struct ref *remote_refs; @@ -1678,7 +1667,7 @@ static int do_fetch(struct transport *transport, if (retcode) goto cleanup; - display_state_init(&display_state, ref_map); + display_state_init(&display_state, ref_map, transport->url); if (atomic_fetch) { transaction = ref_transaction_begin(&err); @@ -1697,11 +1686,10 @@ static int do_fetch(struct transport *transport, * don't care whether --tags was specified. */ if (rs->nr) { - retcode = prune_refs(&display_state, rs, transaction, ref_map, transport->url); + retcode = prune_refs(&display_state, rs, transaction, ref_map); } else { retcode = prune_refs(&display_state, &transport->remote->fetch, - transaction, ref_map, - transport->url); + transaction, ref_map); } if (retcode != 0) retcode = 1; @@ -1812,6 +1800,7 @@ static int do_fetch(struct transport *transport, error("%s", err.buf); } + display_state_release(&display_state); close_fetch_head(&fetch_head); strbuf_release(&err); free_refs(ref_map); From patchwork Mon Mar 20 12:35:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13181121 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 9E646C7618A for ; Mon, 20 Mar 2023 12:36:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231375AbjCTMgE (ORCPT ); Mon, 20 Mar 2023 08:36:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjCTMft (ORCPT ); Mon, 20 Mar 2023 08:35:49 -0400 Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0B5628219 for ; Mon, 20 Mar 2023 05:35:43 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6C0515C0131; Mon, 20 Mar 2023 08:35:43 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 20 Mar 2023 08:35:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=1679315743; x=1679402143; bh=GJ G8A1NozrmjANtZ3xGP4FDklDMDoebYbjSVqwexazM=; b=CMQWTc+IA7aodqCmB7 2A5mkP2i3QZ3yhKJzqrYP5y/xERrI87s8P6tILaeqAF2eTmhuJSOacGoAMSG6tZi yYiJDzWJU4jQ7d0WvnMqsz3WKNGo/fJfxdmWHud1QB0h5qZMqL+vYcH4AHqkYBBo 2m5xg7Ca6wgGdGUz07OXeSFjTYb5N9rqZpqIFhrIQK8vvk3gMTJTEU1+8h0BiHna ilHE4RSP54UtbKXigZhvs2G28yuvbWdUkSAk5nrujtcNdJ1DGX0DlZF5fHWODY+T 69yFY7JIn79/vSkhJgBHnAM8fnxDSCAfXt1nVXHx/o8APZQevKr8s+tLlbNMmBFA LXsg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=1679315743; x=1679402143; bh=GJG8A1NozrmjA NtZ3xGP4FDklDMDoebYbjSVqwexazM=; b=hG6IC+fxMeg4X4R1L3g8mDpT2JO6F tCQV9+rYzLy5R/xMMt3FEsB8PbNMQw3m1GcohknnBMvhv10KKZLlZGxF8HhgVjYH modPzIBa/f28SMTH1pzssvDHCzsqSdtlhV6zhVP+x0dII+Aj7ShTp2P81Q+Z5caW NmBCKD+ZUHxPlXQEXOQnJFV+m9nzheMqv9QMd8iTxd4eM9ebUR46QmghgxO1wuAy yL/EPh7kP4VcDioflWgLPUa/Gu5CXCxIGQTklyPtnTJDpyRi3R0fYcGlysc/bnEF ewcdUElvbDRLRF2pz3oA/DmrjvGTtXOs7h3Ay0ptYqGlSIghy2IETIlSg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdefkedggeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvvefukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeeukedtvedtffevleejtefgheehieegke eluddvfeefgeehgfeltddtheejleffteenucevlhhushhtvghrufhiiigvpedunecurfgr rhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Mar 2023 08:35:42 -0400 (EDT) Received: by pks.im (OpenSMTPD) with ESMTPSA id ab484e99 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 20 Mar 2023 12:35:09 +0000 (UTC) Date: Mon, 20 Mar 2023 13:35:40 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Jonathan Tan Subject: [PATCH v2 6/6] fetch: centralize printing of reference updates Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In order to print updated references during a fetch, the two different call sites that do this will first call `format_display()` followed by a call to `fputs()`. This is needlessly roundabout now that we have the `display_state` structure that encapsulates all of the printing logic for references. Move displaying the reference updates into `format_display()` and rename it to `display_ref_update()` to better match its new purpose, which finalizes the conversion to make both the formatting and printing logic of reference updates self-contained. This will make it easier to add new output formats and printing to a different file descriptor than stderr. Signed-off-by: Patrick Steinhardt --- builtin/fetch.c | 108 ++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 53 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 1e3599cb74..c202c18fb4 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -48,6 +48,8 @@ enum { }; struct display_state { + struct strbuf buf; + int refcol_width; int compact_format; @@ -787,6 +789,8 @@ static void display_state_init(struct display_state *display_state, struct ref * memset(display_state, 0, sizeof(*display_state)); + strbuf_init(&display_state->buf, 0); + if (raw_url) display_state->url = transport_anonymize_url(raw_url); else @@ -834,14 +838,15 @@ static void display_state_init(struct display_state *display_state, struct ref * static void display_state_release(struct display_state *display_state) { + strbuf_release(&display_state->buf); free(display_state->url); } static void print_remote_to_local(struct display_state *display_state, - struct strbuf *display_buffer, const char *remote, const char *local) { - strbuf_addf(display_buffer, "%-*s -> %s", display_state->refcol_width, remote, local); + strbuf_addf(&display_state->buf, "%-*s -> %s", + display_state->refcol_width, remote, local); } static int find_and_replace(struct strbuf *haystack, @@ -871,14 +876,14 @@ static int find_and_replace(struct strbuf *haystack, return 1; } -static void print_compact(struct display_state *display_state, struct strbuf *display_buffer, +static void print_compact(struct display_state *display_state, const char *remote, const char *local) { struct strbuf r = STRBUF_INIT; struct strbuf l = STRBUF_INIT; if (!strcmp(remote, local)) { - strbuf_addf(display_buffer, "%-*s -> *", display_state->refcol_width, remote); + strbuf_addf(&display_state->buf, "%-*s -> *", display_state->refcol_width, remote); return; } @@ -887,46 +892,49 @@ static void print_compact(struct display_state *display_state, struct strbuf *di if (!find_and_replace(&r, local, "*")) find_and_replace(&l, remote, "*"); - print_remote_to_local(display_state, display_buffer, r.buf, l.buf); + print_remote_to_local(display_state, r.buf, l.buf); strbuf_release(&r); strbuf_release(&l); } -static void format_display(struct display_state *display_state, - struct strbuf *display_buffer, char code, - const char *summary, const char *error, - const char *remote, const char *local, - int summary_width) +static void display_ref_update(struct display_state *display_state, char code, + const char *summary, const char *error, + const char *remote, const char *local, + int summary_width) { int width; if (verbosity < 0) return; + strbuf_reset(&display_state->buf); + if (!display_state->shown_url) { - strbuf_addf(display_buffer, _("From %.*s\n"), + strbuf_addf(&display_state->buf, _("From %.*s\n"), display_state->url_len, display_state->url); display_state->shown_url = 1; } width = (summary_width + strlen(summary) - gettext_width(summary)); - strbuf_addf(display_buffer, " %c %-*s ", code, width, summary); + strbuf_addf(&display_state->buf, " %c %-*s ", code, width, summary); if (!display_state->compact_format) - print_remote_to_local(display_state, display_buffer, remote, prettify_refname(local)); + print_remote_to_local(display_state, remote, prettify_refname(local)); else - print_compact(display_state, display_buffer, remote, prettify_refname(local)); + print_compact(display_state, remote, prettify_refname(local)); if (error) - strbuf_addf(display_buffer, " (%s)", error); - strbuf_addch(display_buffer, '\n'); + strbuf_addf(&display_state->buf, " (%s)", error); + strbuf_addch(&display_state->buf, '\n'); + + fputs(display_state->buf.buf, stderr); } static int update_local_ref(struct ref *ref, struct ref_transaction *transaction, struct display_state *display_state, const char *remote, const struct ref *remote_ref, - struct strbuf *display, int summary_width) + int summary_width) { struct commit *current = NULL, *updated; int fast_forward = 0; @@ -936,8 +944,8 @@ static int update_local_ref(struct ref *ref, if (oideq(&ref->old_oid, &ref->new_oid)) { if (verbosity > 0) - format_display(display_state, display, '=', _("[up to date]"), NULL, - remote, ref->name, summary_width); + display_ref_update(display_state, '=', _("[up to date]"), NULL, + remote, ref->name, summary_width); return 0; } @@ -948,9 +956,9 @@ static int update_local_ref(struct ref *ref, * If this is the head, and it's not okay to update * the head, and the old value of the head isn't empty... */ - format_display(display_state, display, '!', _("[rejected]"), - _("can't fetch into checked-out branch"), - remote, ref->name, summary_width); + display_ref_update(display_state, '!', _("[rejected]"), + _("can't fetch into checked-out branch"), + remote, ref->name, summary_width); return 1; } @@ -959,14 +967,14 @@ static int update_local_ref(struct ref *ref, if (force || ref->force) { int r; r = s_update_ref("updating tag", ref, transaction, 0); - format_display(display_state, display, r ? '!' : 't', _("[tag update]"), - r ? _("unable to update local ref") : NULL, - remote, ref->name, summary_width); + display_ref_update(display_state, r ? '!' : 't', _("[tag update]"), + r ? _("unable to update local ref") : NULL, + remote, ref->name, summary_width); return r; } else { - format_display(display_state, display, '!', _("[rejected]"), - _("would clobber existing tag"), - remote, ref->name, summary_width); + display_ref_update(display_state, '!', _("[rejected]"), + _("would clobber existing tag"), + remote, ref->name, summary_width); return 1; } } @@ -997,9 +1005,9 @@ static int update_local_ref(struct ref *ref, } r = s_update_ref(msg, ref, transaction, 0); - format_display(display_state, display, r ? '!' : '*', what, - r ? _("unable to update local ref") : NULL, - remote, ref->name, summary_width); + display_ref_update(display_state, r ? '!' : '*', what, + r ? _("unable to update local ref") : NULL, + remote, ref->name, summary_width); return r; } @@ -1019,9 +1027,9 @@ static int update_local_ref(struct ref *ref, strbuf_addstr(&quickref, ".."); strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); r = s_update_ref("fast-forward", ref, transaction, 1); - format_display(display_state, display, r ? '!' : ' ', quickref.buf, - r ? _("unable to update local ref") : NULL, - remote, ref->name, summary_width); + display_ref_update(display_state, r ? '!' : ' ', quickref.buf, + r ? _("unable to update local ref") : NULL, + remote, ref->name, summary_width); strbuf_release(&quickref); return r; } else if (force || ref->force) { @@ -1031,14 +1039,14 @@ static int update_local_ref(struct ref *ref, strbuf_addstr(&quickref, "..."); strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); r = s_update_ref("forced-update", ref, transaction, 1); - format_display(display_state, display, r ? '!' : '+', quickref.buf, - r ? _("unable to update local ref") : _("forced update"), - remote, ref->name, summary_width); + display_ref_update(display_state, r ? '!' : '+', quickref.buf, + r ? _("unable to update local ref") : _("forced update"), + remote, ref->name, summary_width); strbuf_release(&quickref); return r; } else { - format_display(display_state, display, '!', _("[rejected]"), _("non-fast-forward"), - remote, ref->name, summary_width); + display_ref_update(display_state, '!', _("[rejected]"), _("non-fast-forward"), + remote, ref->name, summary_width); return 1; } } @@ -1266,10 +1274,9 @@ static int store_updated_refs(struct display_state *display_state, note.buf, display_state->url, display_state->url_len); - strbuf_reset(¬e); if (ref) { rc |= update_local_ref(ref, transaction, display_state, what, - rm, ¬e, summary_width); + rm, summary_width); free(ref); } else if (write_fetch_head || dry_run) { /* @@ -1277,13 +1284,11 @@ static int store_updated_refs(struct display_state *display_state, * would be written to FETCH_HEAD, if --dry-run * is set). */ - format_display(display_state, ¬e, '*', - *kind ? kind : "branch", NULL, - *what ? what : "HEAD", - "FETCH_HEAD", summary_width); + display_ref_update(display_state, '*', + *kind ? kind : "branch", NULL, + *what ? what : "HEAD", + "FETCH_HEAD", summary_width); } - if (note.len) - fputs(note.buf, stderr); } } @@ -1419,12 +1424,9 @@ static int prune_refs(struct display_state *display_state, int summary_width = transport_summary_width(stale_refs); for (ref = stale_refs; ref; ref = ref->next) { - struct strbuf sb = STRBUF_INIT; - format_display(display_state, &sb, '-', _("[deleted]"), NULL, - _("(none)"), ref->name, - summary_width); - fputs(sb.buf, stderr); - strbuf_release(&sb); + display_ref_update(display_state, '-', _("[deleted]"), NULL, + _("(none)"), ref->name, + summary_width); warn_dangling_symref(stderr, dangling_msg, ref->name); } }