From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_CSS,URIBL_CSS_A shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id DA5181F8C4 for ; Mon, 28 Mar 2022 17:23:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244586AbiC1RZC (ORCPT ); Mon, 28 Mar 2022 13:25:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232718AbiC1RZA (ORCPT ); Mon, 28 Mar 2022 13:25:00 -0400 Received: from pb-smtp20.pobox.com (pb-smtp20.pobox.com [173.228.157.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F01BC11A37 for ; Mon, 28 Mar 2022 10:23:18 -0700 (PDT) Received: from pb-smtp20.pobox.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 7E23118A2A2; Mon, 28 Mar 2022 13:23:16 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=Ay+aJ/ROKTw5TGhrih6u5EY+GrhLg4RE05I/EB VTpIQ=; b=RP4oPuWkDPbdMWD8zBaM18xCgNkgzZD7/B7MZ67M7tjcY5zDqCSBHJ XEhPEoN8inFq/P9zM54Ltp2LyfPbo2vAWJe+DFUtYzUtxvYyocx1ehDyZPNt4L9Z EqZTikvOQf1wIPyhoEL3UyyUonoUIUbua4XWcchbvUTZ6tEYkoPUo= Received: from pb-smtp20.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp20.pobox.com (Postfix) with ESMTP id 6464C18A2A1; Mon, 28 Mar 2022 13:23:16 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [35.227.145.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp20.pobox.com (Postfix) with ESMTPSA id B1D5D18A2A0; Mon, 28 Mar 2022 13:23:13 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: Glen Choo Cc: Tao Klerks via GitGitGadget , git@vger.kernel.org, =?utf-8?Q?=C3=86var_Arnfj=C3=B6r=C3=B0_Bjarmason?= , Tao Klerks Subject: Re: [PATCH v3] tracking branches: add advice to ambiguous refspec error References: Date: Mon, 28 Mar 2022 10:23:12 -0700 In-Reply-To: (Glen Choo's message of "Mon, 28 Mar 2022 10:12:07 -0700") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: BF8CE250-AEBB-11EC-AE0B-C85A9F429DF0-77302942!pb-smtp20.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Glen Choo writes: > Hm, what do you think of an alternate approach of storing of the > matching remotes in a string_list, something like: > > struct find_tracked_branch_cb { > struct tracking *tracking; > struct string_list matching_remotes; > }; > > static int find_tracked_branch(struct remote *remote, void *priv) > { > struct tracking *tracking = priv; > struct find_tracked_branch_cb *ftb = priv; > struct tracking *tracking = ftb->tracking; > > if (!remote_find_tracking(remote, &tracking->spec)) { > if (++tracking->matches == 1) { > string_list_append(tracking->srcs, tracking->spec.src); > tracking->remote = remote->name; > } else { > free(tracking->spec.src); > string_list_clear(tracking->srcs, 0); > } > string_list_append(&ftb->matching_remotes, remote->name); > tracking->spec.src = NULL; > } > > then construct the advice message in setup_tracking()? To my untrained > eye, "case 2" requires a bit of extra work to understand. If I were writing this code from scratch, I would have probably collected the names first in this callback, and assembled them at the end into a single string when we need a single string to show. Having said that, as long as you do that lazily not to penalize those who have sane setting without the need for advice/error to trigger, I do not particularly care how the list of matching remote names are kept. Having string_list_append() unconditionally like the above patch has, even for folks with just a single match without need for the advice/error message is suboptimal, I would think.