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: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 869911F8C8 for ; Mon, 27 Sep 2021 12:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234506AbhI0NAc (ORCPT ); Mon, 27 Sep 2021 09:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234454AbhI0NAa (ORCPT ); Mon, 27 Sep 2021 09:00:30 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9905DC061765 for ; Mon, 27 Sep 2021 05:58:52 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id r83-20020a1c4456000000b0030cfc00ca5fso478304wma.2 for ; Mon, 27 Sep 2021 05:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dg6GYy6HbBWn0USRl6X59Z+OS9auLjx9r0A8/hv+zp4=; b=ZOT752I2pwSs8fVO43CdLMbfs0W6ahhKrz8N55riFa8WRbPiwT8ey6bD3JXBwL6DQa W7+S3Htosqt3CPBVJkfTfRSfHpALvSTxTAt6M7HzF76maA7mm4JrEka6etQm3wjUuGrg OuWJ5xrMJkoep77Cttfog1HKdVTTDiJDBSNos/WvQEJN66dtLRpIgCy10ZhgLc64MSsb L6829XPfBjSuWHxvJhV5G2v/mxs49/ggpyr4xVvv+pi7m02RvsOAfwtLpomBftW4OgYc kT+/9k4vF8menpAsAyPLkrb3Wf9YP8LORRPJdAbsg8ssRARqpzmPLQzGeMl/cxLDd5Cj EURA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dg6GYy6HbBWn0USRl6X59Z+OS9auLjx9r0A8/hv+zp4=; b=CouCB1ceYCXIIjml6GjHbbYu009eWc+q51rI1RTb9HeNsNbTJt2obaMAaZNwtqcHuH xeedSWRod03WJUS2cBHeKC7R76YsKRfn8A47eoF0RiExolE1t2h88l9AHBSSFRwo8F9B 5hCQ6hDXwfngteYrR3d2EicxXqSgBzgz92GyqnpBo/lcluknr7VC++/OBQU6f6IXeyiL zJn47Np0oDTjvk6Jk45GmYNj+JBNga3n4p4QrJFxnnqmNGgiQYU5nia/ttdGWVvYZUpU WUi7sNZSQj1MS4l4MwijHhh2KOVUtB8FkyvSruqiPS1i5tuVuGCi0DkrNuC6ULQ9lfQS kXtw== X-Gm-Message-State: AOAM533qSUfxVbTb600dkKDWhqohIMu+lgaenEKr5o40ESeUAijOV5f3 t2L2Gkj+fczu5EDFL5eirTA6cGu7c9K4Tg== X-Google-Smtp-Source: ABdhPJxl6AtNpzJgU7KAqqBsvHoQFVW7npPKLC24eIGIekfL4mzQC4s71w06jYG9QoG5RtvD+i/Okg== X-Received: by 2002:a05:600c:2f90:: with SMTP id t16mr9077893wmn.46.1632747531004; Mon, 27 Sep 2021 05:58:51 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id j21sm17562179wmj.40.2021.09.27.05.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 05:58:50 -0700 (PDT) From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?UTF-8?q?Martin=20=C3=85gren?= , Phillip Wood , =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Subject: [PATCH v2 4/5] builtin/remote.c: add and use a REF_STATES_INIT Date: Mon, 27 Sep 2021 14:58:44 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1316.gb2e9b3ba3ae In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use a new REF_STATES_INIT designated initializer instead of assigning to the "strdup_strings" member of the previously memzero()'d version of this struct. The pattern of assigning to "strdup_strings" dates back to 211c89682ee (Make git-remote a builtin, 2008-02-29) (when it was "strdup_paths"), i.e. long before we used anything like our current established *_INIT patterns consistently. Then in e61e0cc6b70 (builtin-remote: teach show to display remote HEAD, 2009-02-25) and e5dcbfd9ab7 (builtin-remote: new show output style for push refspecs, 2009-02-25) we added some more of these. As it turns out we only initialized this struct three times, all the other uses were of pointers to those initialized structs. So let's initialize it in those three places, skip the memset(), and pass those structs down appropriately. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/remote.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 7f88e6ce9de..160dd954f74 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -344,6 +344,14 @@ struct ref_states { int queried; }; +#define REF_STATES_INIT { \ + .new_refs = STRING_LIST_INIT_DUP, \ + .stale = STRING_LIST_INIT_DUP, \ + .tracked = STRING_LIST_INIT_DUP, \ + .heads = STRING_LIST_INIT_DUP, \ + .push = STRING_LIST_INIT_DUP, \ +} + static int get_ref_states(const struct ref *remote_refs, struct ref_states *states) { struct ref *fetch_map = NULL, **tail = &fetch_map; @@ -355,9 +363,6 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat die(_("Could not get fetch map for refspec %s"), states->remote->fetch.raw[i]); - states->new_refs.strdup_strings = 1; - states->tracked.strdup_strings = 1; - states->stale.strdup_strings = 1; for (ref = fetch_map; ref; ref = ref->next) { if (!ref->peer_ref || !ref_exists(ref->peer_ref->name)) string_list_append(&states->new_refs, abbrev_branch(ref->name)); @@ -406,7 +411,6 @@ static int get_push_ref_states(const struct ref *remote_refs, match_push_refs(local_refs, &push_map, &remote->push, MATCH_REFS_NONE); - states->push.strdup_strings = 1; for (ref = push_map; ref; ref = ref->next) { struct string_list_item *item; struct push_info *info; @@ -449,7 +453,6 @@ static int get_push_ref_states_noquery(struct ref_states *states) if (remote->mirror) return 0; - states->push.strdup_strings = 1; if (!remote->push.nr) { item = string_list_append(&states->push, _("(matching)")); info = item->util = xcalloc(1, sizeof(struct push_info)); @@ -483,7 +486,6 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat refspec.force = 0; refspec.pattern = 1; refspec.src = refspec.dst = "refs/heads/*"; - states->heads.strdup_strings = 1; get_fetch_map(remote_refs, &refspec, &fetch_map_tail, 0); matches = guess_remote_head(find_ref_by_name(remote_refs, "HEAD"), fetch_map, 1); @@ -1212,7 +1214,7 @@ static int show(int argc, const char **argv) OPT_BOOL('n', NULL, &no_query, N_("do not query remotes")), OPT_END() }; - struct ref_states states; + struct ref_states states = REF_STATES_INIT; struct string_list info_list = STRING_LIST_INIT_NODUP; struct show_info info; @@ -1225,7 +1227,6 @@ static int show(int argc, const char **argv) if (!no_query) query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES); - memset(&states, 0, sizeof(states)); memset(&info, 0, sizeof(info)); info.states = &states; info.list = &info_list; @@ -1334,8 +1335,7 @@ static int set_head(int argc, const char **argv) if (!opt_a && !opt_d && argc == 2) { head_name = xstrdup(argv[1]); } else if (opt_a && !opt_d && argc == 1) { - struct ref_states states; - memset(&states, 0, sizeof(states)); + struct ref_states states = REF_STATES_INIT; get_remote_ref_states(argv[0], &states, GET_HEAD_NAMES); if (!states.heads.nr) result |= error(_("Cannot determine remote HEAD")); @@ -1374,14 +1374,13 @@ static int set_head(int argc, const char **argv) static int prune_remote(const char *remote, int dry_run) { int result = 0; - struct ref_states states; + struct ref_states states = REF_STATES_INIT; struct string_list refs_to_prune = STRING_LIST_INIT_NODUP; struct string_list_item *item; const char *dangling_msg = dry_run ? _(" %s will become dangling!") : _(" %s has become dangling!"); - memset(&states, 0, sizeof(states)); get_remote_ref_states(remote, &states, GET_REF_STATES); if (!states.stale.nr) { -- 2.33.0.1316.gb2e9b3ba3ae