From patchwork Fri Oct 1 10:27:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12530261 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB4A2C433FE for ; Fri, 1 Oct 2021 10:27:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB8CE61361 for ; Fri, 1 Oct 2021 10:27:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353573AbhJAK3b (ORCPT ); Fri, 1 Oct 2021 06:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353569AbhJAK33 (ORCPT ); Fri, 1 Oct 2021 06:29:29 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 919A4C061775 for ; Fri, 1 Oct 2021 03:27:45 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id t8so14746630wri.1 for ; Fri, 01 Oct 2021 03:27:45 -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=icwplYCFQXDQZ25Mnj2TxVvaPQyqdARYvXsA+5WLHW8=; b=p5Co9x8/gyReXYO/2OqvpxEh4HJLiUtoEuI9kcki9qu5sk0r1B5ooBB+lRwQsYfmhI uBHpMhNPxqmGeFyXkSq3wyFpBJoFd4wmuquXFV8kN8X9lDUSqF9xuS3WF40T1y3UNfdX FnQKzphEg94ejw93sFZndCy3PTxdEzTyoqUGgax14JTZ5LFO1ueIpsbXC8a8nU16EPGn C3BuDBqF9SE+IWNIJmhIqRWwwx/fI7DoDaj0AzNiFBJ9NHrxpfzFT30c4b/hxn1oleeW 1LdEuv3T9PbsU7V5ii2KKOwHx6IgoMsDfaYYlVyOy1r1qQH0owjVY7iQo15BpCLdpKMs AZcw== 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=icwplYCFQXDQZ25Mnj2TxVvaPQyqdARYvXsA+5WLHW8=; b=a+JAZ67Kyy8pQ1XWzlsqaB1tPt0ym+/X7DzWuCqiz7LnzfpK5sSSnAVSPe/TyHPgkp ZwX0oNWWLvpNShejv9V+rsmKBaiPBIwBXLh2IVCn+qt3lN2YbJ3WlECNRU0tE5KAlNSp AQ7SPaC/iUAX0e97iO7n9a1TYH6YOKP3xAQD21O3jGxv4pEe3v/Q2BfflqQx9yNG0hc5 ZOh0AcBTRJg4z3cCCOm99L2/AB1NJ677E6heXL5KoD6QHb8iZYoA0UQScK2h5T0RNZI/ YnImKmfvV74Gu82w60DEGQtN7VYI0YdwbHoF3tw3iT95DKzb86MUeEIzZkkR5q4YKPir d1xw== X-Gm-Message-State: AOAM530PiVFLeprp7b2jcxMtyxyj2jkpiVsaBZI/fJ0aiggF7misO4V5 evgsUVtKgFW72J66ee+bodU6t+OkXgyjrw== X-Google-Smtp-Source: ABdhPJwb0tAcNHmMrKhyeV4rQnbJRUPtTGnb6CMKXuuApG4a7iySVJy0blcjOYYzT62GPoO7aGarnw== X-Received: by 2002:adf:fec6:: with SMTP id q6mr11181910wrs.122.1633084063915; Fri, 01 Oct 2021 03:27:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h7sm5398952wrx.14.2021.10.01.03.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 03:27:43 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , Phillip Wood , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 1/6] daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macro Date: Fri, 1 Oct 2021 12:27:31 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.gbbd823cc90f In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the hostinfo_init() function added in 01cec54e135 (daemon: deglobalize hostname information, 2015-03-07) and instead initialize the "struct hostinfo" with a macro. This is the more idiomatic pattern in the codebase, and doesn't leave us wondering when we see the *_init() function if this struct needs more complex initialization than a macro can provide. Signed-off-by: Ævar Arnfjörð Bjarmason --- daemon.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/daemon.c b/daemon.c index 5c4cbad62d0..d80d009d1a1 100644 --- a/daemon.c +++ b/daemon.c @@ -63,6 +63,12 @@ struct hostinfo { unsigned int hostname_lookup_done:1; unsigned int saw_extended_args:1; }; +#define HOSTINFO_INIT { \ + .hostname = STRBUF_INIT, \ + .canon_hostname = STRBUF_INIT, \ + .ip_address = STRBUF_INIT, \ + .tcp_port = STRBUF_INIT, \ +} static void lookup_hostname(struct hostinfo *hi); @@ -727,15 +733,6 @@ static void lookup_hostname(struct hostinfo *hi) } } -static void hostinfo_init(struct hostinfo *hi) -{ - memset(hi, 0, sizeof(*hi)); - strbuf_init(&hi->hostname, 0); - strbuf_init(&hi->canon_hostname, 0); - strbuf_init(&hi->ip_address, 0); - strbuf_init(&hi->tcp_port, 0); -} - static void hostinfo_clear(struct hostinfo *hi) { strbuf_release(&hi->hostname); @@ -760,11 +757,9 @@ static int execute(void) char *line = packet_buffer; int pktlen, len, i; char *addr = getenv("REMOTE_ADDR"), *port = getenv("REMOTE_PORT"); - struct hostinfo hi; + struct hostinfo hi = HOSTINFO_INIT; struct strvec env = STRVEC_INIT; - hostinfo_init(&hi); - if (addr) loginfo("Connection from %s:%s", addr, port); From patchwork Fri Oct 1 10:27:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12530263 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2413FC433F5 for ; Fri, 1 Oct 2021 10:27:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE87561A7B for ; Fri, 1 Oct 2021 10:27:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353574AbhJAK3e (ORCPT ); Fri, 1 Oct 2021 06:29:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353572AbhJAK3a (ORCPT ); Fri, 1 Oct 2021 06:29:30 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EA25C061775 for ; Fri, 1 Oct 2021 03:27:46 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id l18-20020a05600c4f1200b002f8cf606262so10837210wmq.1 for ; Fri, 01 Oct 2021 03:27:46 -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=ty3rV+mfSy+t26gPkfA+ksR916LTb9lpS4q69E+jbIQ=; b=AHsIKrLW+G80QzLJklbQ91BmNvvWXyxf1kEsgYMas74HHfFirgH8KyBSmPlEoZlamk 9wA0iWKDFCm8gsHCI1nhEFv22d8QAkUf01mLlQ31Pfc1EjzuZVcmNcffUf6lNKnLL+Kn peSxYXiE1+NmL1tka81VMqbkFdkpZPkeCmttXd5QmHBiYUzLyL7SZ0/pHtDsyJn+o+Vs a7LKpUdUtkKkKpHBGfZ9MuuyKSJEDeD+HcBQZU516qjbU1RMNkpJtpcxfZiNjO8hVqg+ Jn6awchcTGvO/UFV1QnVhpJO7BUP5n8PoWYVnXmFK37jIz9zF7NRXhoAHp4UO92SxJW6 Atyw== 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=ty3rV+mfSy+t26gPkfA+ksR916LTb9lpS4q69E+jbIQ=; b=dFJNFYAkmYUlC/TWtp9Jieoguehv7gevZvxEE5YXSnQWvx9eOsieFUEQiBGJcqvTds yxut/9kklB6Jp81tn02sMMSBOZMiPelebIarEE5u88uy4bqxkRARSscsCkj6P5Uvl4LE zKyEl3HE1gMhD0hzsrTj+x7WpieXaOf6ihNbWCzR2F1kcUfSHABgq31llzZfJoV8nQbE KgcWq/r9K3MnssUdHRObM9sw1Z8lYe392B10C21uQ4hw7QZ0s07ODzIVVUicGkC8R4wQ mz0HxaBpKMttM92YoKNSCXU5uJOoA57pOPGJndBJarFYo/ZgteiQJqII0uqQ8bDURfsu Qjgw== X-Gm-Message-State: AOAM530+kWuqzMPWgQ8sEAgwgOzyiBT9TFyT4Fbk+wyjajoCvPH/DPoX fuR8q5Col1lAS6fBg6oQ893yTy3Fg7MtIg== X-Google-Smtp-Source: ABdhPJxeXZ1gqI8hCgcyYVNCxpjcuLDA/JEVvq3FHYzi5Bh1e+58OIBPu9CYt9Z1NQxH1n5hTIorZQ== X-Received: by 2002:a1c:8056:: with SMTP id b83mr3632039wmd.87.1633084064830; Fri, 01 Oct 2021 03:27:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h7sm5398952wrx.14.2021.10.01.03.27.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 03:27:44 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , Phillip Wood , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 2/6] builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macro Date: Fri, 1 Oct 2021 12:27:32 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.gbbd823cc90f In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the commit_info_init() function addded in ea02ffa3857 (mailmap: simplify map_user() interface, 2013-01-05) and instead initialize the "struct commit_info" with a macro. This is the more idiomatic pattern in the codebase, and doesn't leave us wondering when we see the *_init() function if this struct needs more complex initialization than a macro can provide. The get_commit_info() function is only called by the three callers being changed here immediately after initializing the struct with the macros, so by moving the initialization to the callers we don't need to do it in get_commit_info() anymore. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/blame.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/builtin/blame.c b/builtin/blame.c index 641523ff9af..1c31a996403 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -101,6 +101,16 @@ struct commit_info { struct strbuf summary; }; +#define COMMIT_INFO_INIT { \ + .author = STRBUF_INIT, \ + .author_mail = STRBUF_INIT, \ + .author_tz = STRBUF_INIT, \ + .committer = STRBUF_INIT, \ + .committer_mail = STRBUF_INIT, \ + .committer_tz = STRBUF_INIT, \ + .summary = STRBUF_INIT, \ +} + /* * Parse author/committer line in the commit object buffer */ @@ -160,18 +170,6 @@ static void get_ac_line(const char *inbuf, const char *what, strbuf_add(name, namebuf, namelen); } -static void commit_info_init(struct commit_info *ci) -{ - - strbuf_init(&ci->author, 0); - strbuf_init(&ci->author_mail, 0); - strbuf_init(&ci->author_tz, 0); - strbuf_init(&ci->committer, 0); - strbuf_init(&ci->committer_mail, 0); - strbuf_init(&ci->committer_tz, 0); - strbuf_init(&ci->summary, 0); -} - static void commit_info_destroy(struct commit_info *ci) { @@ -192,8 +190,6 @@ static void get_commit_info(struct commit *commit, const char *subject, *encoding; const char *message; - commit_info_init(ret); - encoding = get_log_output_encoding(); message = logmsg_reencode(commit, NULL, encoding); get_ac_line(message, "\nauthor ", @@ -246,7 +242,7 @@ static void write_filename_info(struct blame_origin *suspect) */ static int emit_one_suspect_detail(struct blame_origin *suspect, int repeat) { - struct commit_info ci; + struct commit_info ci = COMMIT_INFO_INIT; if (!repeat && (suspect->commit->object.flags & METAINFO_SHOWN)) return 0; @@ -440,7 +436,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int int cnt; const char *cp; struct blame_origin *suspect = ent->suspect; - struct commit_info ci; + struct commit_info ci = COMMIT_INFO_INIT; char hex[GIT_MAX_HEXSZ + 1]; int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP); const char *default_color = NULL, *color = NULL, *reset = NULL; @@ -630,7 +626,7 @@ static void find_alignment(struct blame_scoreboard *sb, int *option) if (longest_file < num) longest_file = num; if (!(suspect->commit->object.flags & METAINFO_SHOWN)) { - struct commit_info ci; + struct commit_info ci = COMMIT_INFO_INIT; suspect->commit->object.flags |= METAINFO_SHOWN; get_commit_info(suspect->commit, &ci, 1); if (*option & OUTPUT_SHOW_EMAIL) From patchwork Fri Oct 1 10:27:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12530265 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A281C433EF for ; Fri, 1 Oct 2021 10:27:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B26A61361 for ; Fri, 1 Oct 2021 10:27:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353575AbhJAK3f (ORCPT ); Fri, 1 Oct 2021 06:29:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353569AbhJAK3c (ORCPT ); Fri, 1 Oct 2021 06:29:32 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC75DC06177B for ; Fri, 1 Oct 2021 03:27:47 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id s21so14672985wra.7 for ; Fri, 01 Oct 2021 03:27:47 -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=g+5I+kI8JYDX1W4Jc6XuHBv/+6HIADIX2NJudsoR2mk=; b=DD79R7l4NWVoTbQafU0t8Tnn9OFRibr0/CVKa/rz9cT/ALOs90bFXA9uYdEG/JMMc6 XU02GumuKgyx3osJImYySL4N3lc9JNILN8dnskTEh6Ea4wY4vmoreqUlJ8rFR9jTVShf UhYVOgK/R7sVBXAXgjgdJxAC8Ts3Z1w0LE7VsTPdiUqx/UHRtkgefKeyJxXoextjqHrB u2RWBBOplRYfIWL2atN+55R3dhDct7ZXD6YlBKasOojFhDr0bLahBftCkNSLJ1UCgz01 V9Ga7cKapuw7sXcegcsr7q4bzs/yXupecegKdQ5BrcZDlaRB4D+Odr9pDC6IHMYp/6u6 6aOw== 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=g+5I+kI8JYDX1W4Jc6XuHBv/+6HIADIX2NJudsoR2mk=; b=yLcRIePMiuotpzCu9R3YWBlKddK9nG/IL5CfoNZx/eltD+qfPOHTqRCKqLYM3AKscx IhEsIQpBvHGtDy5tdGbUef0SeeeTK+n3wEASBns6PMdqeZ479SbY0zEh4wbSsZPpTdpP VJIaf7UhPQPoe8U8+jlzlgjtQ9WOHTFQjfHgACE5ASvfkLgkq6oMaKSTTWlJCYpYwayw k4KZlVegxQMHHAkHKl9kw7qGQn71uV+Yp5NMUnGhfirZmydWYnz00GxpcuKPpcuXgiiM LpstbASV4VK3pgkUv3c1OaQ3bTZDMOhW3jM7BtUThBpgL0xoyiGGgkPA5flah6BmmUlH ggcg== X-Gm-Message-State: AOAM53137Kv+HAEYX5tmLiv0z5NrgooFaadC1aVbY0NInBL9xbhq28qv ZRRgx3B/wBBV9CGA1ga6FrI2ePzRpAS1lw== X-Google-Smtp-Source: ABdhPJzei0Kr8YyQ9+HBv4SP27gPyZqlpYDc8hRQv31hu/t+s40LT/KgfOFVfeNV1EdGwoISguWH3g== X-Received: by 2002:adf:a4cf:: with SMTP id h15mr11426399wrb.56.1633084066183; Fri, 01 Oct 2021 03:27:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h7sm5398952wrx.14.2021.10.01.03.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 03:27:45 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , Phillip Wood , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 3/6] urlmatch.[ch]: add and use URLMATCH_CONFIG_INIT Date: Fri, 1 Oct 2021 12:27:33 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.gbbd823cc90f In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the initialization pattern of "struct urlmatch_config" to use an *_INIT macro and designated initializers. Right now there's no other "struct" member of "struct urlmatch_config" which would require its own *_INIT, but it's good practice not to assume that. Let's also change this to a designated initializer while we're at it. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/config.c | 2 +- credential.c | 2 +- http.c | 2 +- urlmatch.h | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 865fddd6ce8..542d8d02b2b 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -575,7 +575,7 @@ static int get_urlmatch(const char *var, const char *url) int ret; char *section_tail; struct string_list_item *item; - struct urlmatch_config config = { STRING_LIST_INIT_DUP }; + struct urlmatch_config config = URLMATCH_CONFIG_INIT; struct string_list values = STRING_LIST_INIT_DUP; config.collect_fn = urlmatch_collect_fn; diff --git a/credential.c b/credential.c index 000ac7a8d43..e7240f3f636 100644 --- a/credential.c +++ b/credential.c @@ -105,7 +105,7 @@ static int match_partial_url(const char *url, void *cb) static void credential_apply_config(struct credential *c) { char *normalized_url; - struct urlmatch_config config = { STRING_LIST_INIT_DUP }; + struct urlmatch_config config = URLMATCH_CONFIG_INIT; struct strbuf url = STRBUF_INIT; if (!c->host) diff --git a/http.c b/http.c index d7c20493d7f..da12471c242 100644 --- a/http.c +++ b/http.c @@ -990,7 +990,7 @@ void http_init(struct remote *remote, const char *url, int proactive_auth) char *low_speed_limit; char *low_speed_time; char *normalized_url; - struct urlmatch_config config = { STRING_LIST_INIT_DUP }; + struct urlmatch_config config = URLMATCH_CONFIG_INIT; config.section = "http"; config.key = NULL; diff --git a/urlmatch.h b/urlmatch.h index 6ff42f81b0c..34a3ba6d197 100644 --- a/urlmatch.h +++ b/urlmatch.h @@ -66,6 +66,10 @@ struct urlmatch_config { int (*fallback_match_fn)(const char *url, void *cb); }; +#define URLMATCH_CONFIG_INIT { \ + .vars = STRING_LIST_INIT_DUP, \ +} + int urlmatch_config_entry(const char *var, const char *value, void *cb); #endif /* URL_MATCH_H */ From patchwork Fri Oct 1 10:27:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12530267 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A2BCC433FE for ; Fri, 1 Oct 2021 10:27:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E675261361 for ; Fri, 1 Oct 2021 10:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353586AbhJAK3h (ORCPT ); Fri, 1 Oct 2021 06:29:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353576AbhJAK3c (ORCPT ); Fri, 1 Oct 2021 06:29:32 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2F3DC06177D for ; Fri, 1 Oct 2021 03:27:48 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id h15so13082855wrc.3 for ; Fri, 01 Oct 2021 03:27:48 -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=BEZcKIPRwtnnT9VkWXEQ+OlaqQisBTYl7+gzgjCO3Ok=; b=ENDJW/ph4W2CVLPxRQvQrUvMX+PEoYIBST9BLFheFq/dorJCRFTZa0aPt1/2vHI36n a7rrKhyKbla0AUT57ZPRdgffY/yAXGEnvRiDNvYT321EFCk96YopEF51Mua3iV3E/bpW qSz63H0KP1cEe/bdMII/mpmf52RvqGsLhiIU998vuiaZvjdHgEJWgC4M9bO+W455jo2N TCmugFSr5zz6Uh6kCuo51/jmK0F8yOXoyhA1lhCqHEvWmPsST+nV0ug/K/KqqD+oliPM gizvS0wY01vazfUXacWl1SM+tMBzNxPxmKLXJewm7ECTmOJHOFXztxnC5nT76tBjGQeZ J5Qg== 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=BEZcKIPRwtnnT9VkWXEQ+OlaqQisBTYl7+gzgjCO3Ok=; b=GwUkf4ym6atT+W81HlFJuxQSMPz+CGjWTC9aXlZp5jIVMiOCGXnsS8mSeSpM0IlpET yuh4Nl7eQtib7UpZmV3Lr+dBhoFIWWdZnp6JZnghoSVVbfSoea2nWaHu5GDbG1jkU85a MrjopOL0kpp13a8HpARf0Fgf4XVCut8AU1P2zOJ+jK+Igg5ruJnZIN6kAFHhSrzXOXB0 HmaityLEPQAIj30dwfsHZPWBELUviv5nX94D7+ZOFYhSheMuXmeLJwJn6+X4avjBFYQW lMfixxjntE26aULWeCEAUgii+MAK5FvfaoceTUbTwx98lbHUFlqP5gWObk9583HgwCY8 X9CA== X-Gm-Message-State: AOAM530GRahO3ygLRXpILGKFIGEAVs6HpSRRVj6ZMOfKRRVU7DyGzcEc N1QoY1gYGFFGP2WHk/kOO22INNs7iwS+jw== X-Google-Smtp-Source: ABdhPJxi55q+GqHyANdGFg58WnLdeZD5tpGzkEXSwI3L+80PtK69iE8GmUe4pXJyKT726cPViX4GQQ== X-Received: by 2002:a05:6000:2af:: with SMTP id l15mr11744315wry.17.1633084067007; Fri, 01 Oct 2021 03:27:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h7sm5398952wrx.14.2021.10.01.03.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 03:27:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , Phillip Wood , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 4/6] builtin/remote.c: add and use a REF_STATES_INIT Date: Fri, 1 Oct 2021 12:27:34 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.gbbd823cc90f In-Reply-To: References: MIME-Version: 1.0 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. This would be a behavior change if we had codepaths that relied say on implicitly having had "new_refs" initialized to STRING_LIST_INIT_NODUP with the memset(), but only set the "strdup_strings" on some other struct, but then called string_list_append() on "new_refs". There isn't any such codepath, all of the late assignments to "strdup_strings" assigned to those structs that we'd use for those codepaths. So just initializing them all up-front makes for easier to understand code, i.e. in the pre-image it looked as though we had that tricky edge case, but we didn't. 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) { From patchwork Fri Oct 1 10:27:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12530269 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59F8BC433EF for ; Fri, 1 Oct 2021 10:27:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B30C61A6E for ; Fri, 1 Oct 2021 10:27:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353591AbhJAK3j (ORCPT ); Fri, 1 Oct 2021 06:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353581AbhJAK3d (ORCPT ); Fri, 1 Oct 2021 06:29:33 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3C0DC0613E2 for ; Fri, 1 Oct 2021 03:27:49 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id m22so9244740wrb.0 for ; Fri, 01 Oct 2021 03:27:49 -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=w7DQvqEMgzqdRwUr2mz8i+ZC1Cw5/l2cfvUOfnoI7rA=; b=IZwy1nRb0cBjRJkKDSHF8ogL1CWqnHxj5u0fippQ28MvN+8fj29IJakIuChRsGKo+U RnJUOvqGSD0q85UY0hn3pdiKGYa764tzJ/xIdl32Hd41ezZh8sextI1NkU9BaZ0a+BUt W8A2N6MGNLU9U0DTRC6Nha55FGHqlTkbtjLDsHwOajI7QpaRMerqQv1g9Y0zKb4ZF8jx l4nSf0crRe+qmxgi/2mZUzLwqHhekR8dF4Bm/TTzWvyw9QRrpoYxo7TBjNZft7YrS3nE 0QmJp8xgFEfUBBc3x9b2jYEsO+dx/SYeyNH7jl9jO8W9+ZPpJt9i4K9oaZP2oqC0lrrj fQBw== 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=w7DQvqEMgzqdRwUr2mz8i+ZC1Cw5/l2cfvUOfnoI7rA=; b=MIHmF71cjq/8Y7zVTb0uNm8qwQe4H4kK1MdlvuoVJ7GgDMcVNw6MokNM//r+OW0Qtx 5eeFMkVY+xSUCfGURTzTVgRB1jwDsgVw6S1+FTzrsKKMpWLW5vvDTGNEdTUOtPFUTkFn XQdM4fCE7tnD2VQ5LN9QBaeILTh+Q1dy0S7vwpvS5Fq+NYBpi4DKonKTWrlE+Z6LuBxb CxTldDq+CGYyJmWNOURphB5iqpkXSED95czKga/RvFH8Ev0p2/8pxgEvWMaiq8lKIxm9 +iPtlmrcyW9MNFuPRg5nsHybJjAU3PmvESQmnmyv/fvDDqyrdkTvtOY/I5DnUXQ9hh+R 3V8Q== X-Gm-Message-State: AOAM530v05sj5yWvbb1RMFJMe10PHbeE+/kQdV1GLt76ORi89Qqty6G/ xOltyqRyFCUphDr05a7Fees9i5qQFMFiIQ== X-Google-Smtp-Source: ABdhPJxoy9IXcr0VbeNwzknmgfeYliziSkuyuBE2lERkG8zo7TxpWX66eo8fpCbZVmL9VmG2hWmBoQ== X-Received: by 2002:a5d:6d8e:: with SMTP id l14mr11203999wrs.26.1633084067933; Fri, 01 Oct 2021 03:27:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h7sm5398952wrx.14.2021.10.01.03.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 03:27:47 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , Phillip Wood , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 5/6] builtin/remote.c: add and use SHOW_INFO_INIT Date: Fri, 1 Oct 2021 12:27:35 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.gbbd823cc90f In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In the preceding commit we introduced REF_STATES_INIT, but did not change the "struct show_info" to have a corresponding initializer. Let's do that, and make it use "REF_STATES_INIT" and "STRING_LIST_INIT_DUP", doing that requires changing "list" and "states" away from being pointers. The resulting end-state is simpler since we omit the local "info_list" and "states" variables in show() as well as the memset(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/remote.c | 90 ++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index 160dd954f74..deb48772ac5 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -972,26 +972,31 @@ static int get_remote_ref_states(const char *name, } struct show_info { - struct string_list *list; - struct ref_states *states; + struct string_list list; + struct ref_states states; int width, width2; int any_rebase; }; +#define SHOW_INFO_INIT { \ + .list = STRING_LIST_INIT_DUP, \ + .states = REF_STATES_INIT, \ +} + static int add_remote_to_show_info(struct string_list_item *item, void *cb_data) { struct show_info *info = cb_data; int n = strlen(item->string); if (n > info->width) info->width = n; - string_list_insert(info->list, item->string); + string_list_insert(&info->list, item->string); return 0; } static int show_remote_info_item(struct string_list_item *item, void *cb_data) { struct show_info *info = cb_data; - struct ref_states *states = info->states; + struct ref_states *states = &info->states; const char *name = item->string; if (states->queried) { @@ -1018,7 +1023,7 @@ static int show_remote_info_item(struct string_list_item *item, void *cb_data) static int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data) { struct show_info *show_info = cb_data; - struct ref_states *states = show_info->states; + struct ref_states *states = &show_info->states; struct branch_info *branch_info = branch_item->util; struct string_list_item *item; int n; @@ -1031,7 +1036,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb if (branch_info->rebase >= REBASE_TRUE) show_info->any_rebase = 1; - item = string_list_insert(show_info->list, branch_item->string); + item = string_list_insert(&show_info->list, branch_item->string); item->util = branch_info; return 0; @@ -1086,7 +1091,7 @@ static int add_push_to_show_info(struct string_list_item *push_item, void *cb_da show_info->width = n; if ((n = strlen(push_info->dest)) > show_info->width2) show_info->width2 = n; - item = string_list_append(show_info->list, push_item->string); + item = string_list_append(&show_info->list, push_item->string); item->util = push_item->util; return 0; } @@ -1214,9 +1219,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 = REF_STATES_INIT; - struct string_list info_list = STRING_LIST_INIT_NODUP; - struct show_info info; + struct show_info info = SHOW_INFO_INIT; argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage, 0); @@ -1227,25 +1230,22 @@ static int show(int argc, const char **argv) if (!no_query) query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES); - memset(&info, 0, sizeof(info)); - info.states = &states; - info.list = &info_list; for (; argc; argc--, argv++) { int i; const char **url; int url_nr; - get_remote_ref_states(*argv, &states, query_flag); + get_remote_ref_states(*argv, &info.states, query_flag); printf_ln(_("* remote %s"), *argv); - printf_ln(_(" Fetch URL: %s"), states.remote->url_nr > 0 ? - states.remote->url[0] : _("(no URL)")); - if (states.remote->pushurl_nr) { - url = states.remote->pushurl; - url_nr = states.remote->pushurl_nr; + printf_ln(_(" Fetch URL: %s"), info.states.remote->url_nr > 0 ? + info.states.remote->url[0] : _("(no URL)")); + if (info.states.remote->pushurl_nr) { + url = info.states.remote->pushurl; + url_nr = info.states.remote->pushurl_nr; } else { - url = states.remote->url; - url_nr = states.remote->url_nr; + url = info.states.remote->url; + url_nr = info.states.remote->url_nr; } for (i = 0; i < url_nr; i++) /* @@ -1258,57 +1258,57 @@ static int show(int argc, const char **argv) printf_ln(_(" Push URL: %s"), _("(no URL)")); if (no_query) printf_ln(_(" HEAD branch: %s"), _("(not queried)")); - else if (!states.heads.nr) + else if (!info.states.heads.nr) printf_ln(_(" HEAD branch: %s"), _("(unknown)")); - else if (states.heads.nr == 1) - printf_ln(_(" HEAD branch: %s"), states.heads.items[0].string); + else if (info.states.heads.nr == 1) + printf_ln(_(" HEAD branch: %s"), info.states.heads.items[0].string); else { printf(_(" HEAD branch (remote HEAD is ambiguous," " may be one of the following):\n")); - for (i = 0; i < states.heads.nr; i++) - printf(" %s\n", states.heads.items[i].string); + for (i = 0; i < info.states.heads.nr; i++) + printf(" %s\n", info.states.heads.items[i].string); } /* remote branch info */ info.width = 0; - for_each_string_list(&states.new_refs, add_remote_to_show_info, &info); - for_each_string_list(&states.tracked, add_remote_to_show_info, &info); - for_each_string_list(&states.stale, add_remote_to_show_info, &info); - if (info.list->nr) + for_each_string_list(&info.states.new_refs, add_remote_to_show_info, &info); + for_each_string_list(&info.states.tracked, add_remote_to_show_info, &info); + for_each_string_list(&info.states.stale, add_remote_to_show_info, &info); + if (info.list.nr) printf_ln(Q_(" Remote branch:%s", " Remote branches:%s", - info.list->nr), + info.list.nr), no_query ? _(" (status not queried)") : ""); - for_each_string_list(info.list, show_remote_info_item, &info); - string_list_clear(info.list, 0); + for_each_string_list(&info.list, show_remote_info_item, &info); + string_list_clear(&info.list, 0); /* git pull info */ info.width = 0; info.any_rebase = 0; for_each_string_list(&branch_list, add_local_to_show_info, &info); - if (info.list->nr) + if (info.list.nr) printf_ln(Q_(" Local branch configured for 'git pull':", " Local branches configured for 'git pull':", - info.list->nr)); - for_each_string_list(info.list, show_local_info_item, &info); - string_list_clear(info.list, 0); + info.list.nr)); + for_each_string_list(&info.list, show_local_info_item, &info); + string_list_clear(&info.list, 0); /* git push info */ - if (states.remote->mirror) + if (info.states.remote->mirror) printf_ln(_(" Local refs will be mirrored by 'git push'")); info.width = info.width2 = 0; - for_each_string_list(&states.push, add_push_to_show_info, &info); - QSORT(info.list->items, info.list->nr, cmp_string_with_push); - if (info.list->nr) + for_each_string_list(&info.states.push, add_push_to_show_info, &info); + QSORT(info.list.items, info.list.nr, cmp_string_with_push); + if (info.list.nr) printf_ln(Q_(" Local ref configured for 'git push'%s:", " Local refs configured for 'git push'%s:", - info.list->nr), + info.list.nr), no_query ? _(" (status not queried)") : ""); - for_each_string_list(info.list, show_push_info_item, &info); - string_list_clear(info.list, 0); + for_each_string_list(&info.list, show_push_info_item, &info); + string_list_clear(&info.list, 0); - free_remote_ref_states(&states); + free_remote_ref_states(&info.states); } return result; From patchwork Fri Oct 1 10:27:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12530271 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A14D6C433FE for ; Fri, 1 Oct 2021 10:27:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C6C561A6F for ; Fri, 1 Oct 2021 10:27:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353606AbhJAK3k (ORCPT ); Fri, 1 Oct 2021 06:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353578AbhJAK3e (ORCPT ); Fri, 1 Oct 2021 06:29:34 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72725C061775 for ; Fri, 1 Oct 2021 03:27:50 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id h15so13082957wrc.3 for ; Fri, 01 Oct 2021 03:27:50 -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=7HzLWFNBImKnp7o/ZCpEEw2drZWcf5DDyaWePBOzSDw=; b=OUk62OeOcQ8wydWmZWzxNrUp9a1Lt62lvTqokrOcnFDY+51LJ8m2Eua7YtTkKAU0p8 jX6zQGJnAC60F2Oy8KE3Vbo0eRBNuE9IuojkTUtFBIMmKCAkLgi+C0c66spGguE4OaRX 0sFOMc2yVyn0OBM8GZmyAQeXWB85bG59YJ3BJ8bMzLRx4Z4QEDYG2HTVqscN1iNjY7gS fEv4elsVoAnRyIdbF9B1/ucs0Ct1Z0eE67AuSUtjv52n3mKKhBXQWwYDhqPrC5mK+mod Oxx3eFKiv6g6NwFSyxJll/Q62y7dvo/kNY1FVBAxVZqWxNu7blYyrTw8WyHSe4o4bvxD H5vA== 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=7HzLWFNBImKnp7o/ZCpEEw2drZWcf5DDyaWePBOzSDw=; b=4wd+Ao/F7DD3J8M6RqIw0m29HxS929wwp3F6uSGtzhC6piA0YPenCK5TrPczztADQn 0noRcgYxXDk+OTaBjpnI7UrgbcJ7278Q7RGFL/UWzZddk6jBpHmqhkGa1N7zIL0dfhXw X7EvG5cFLvJFUlNSuBKYQaPoFDkrY/FepVSsUujMukwJ/onpjBdc+g4BpthnCXxFglWZ h0oJHNdfKWM38d/bGtTFIhMcSib1ftQFOOEx9Ilhk4VmPI2Roz+jnWwpzTAgAdeXqBeu SDLjdWftnOAM/bUMh+/iJANTiAGntSmX+YGieYAi4z3yLMIhAgEZJRY+JDk/Abz41QXc FhOQ== X-Gm-Message-State: AOAM532aMjAGie/M5INboyd5lV/WTH5aAE6t5h6W/8MIU+PwB2iITk6/ BKF9p/jwMsr286lYEaAmVQ9pRGDlhYP3aQ== X-Google-Smtp-Source: ABdhPJxmsLhB0UPT/1/V4RWRR1OEL3XExztrURkpOGcdoY3T6ePLDsdQIUuEoPyKTSqbE80RWLWOjA== X-Received: by 2002:a05:6000:1b8d:: with SMTP id r13mr11797242wru.230.1633084068693; Fri, 01 Oct 2021 03:27:48 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h7sm5398952wrx.14.2021.10.01.03.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 03:27:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , Phillip Wood , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 6/6] unpack-trees.[ch]: define and use a UNPACK_TREES_OPTIONS_INIT Date: Fri, 1 Oct 2021 12:27:36 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1375.gbbd823cc90f In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Almost all users of "struct unpack_trees_options" allocate it on the stack already, let's provide an *_INIT macro for them to use. This will make later changes that would like to initialize other members of the struct easier[1][2], but for now we're keeping it compatible with a memset() to "0" with an "{ 0 }" initialization. This leaves a caller in "checkout_fast_forward()" in "merge.c" still doing the memset(). I've left it to avoid a conflict with the in-flight en/removing-untracked-fixes. As noted above conflict is just textual, not semantic, so we can clean it up some other time. I've manually validated[3] with some WIP changes on top of this that the remaining "checkout_fast_forward()" caller is the only one that.s left. 1. https://lore.kernel.org/git/87k0ixrv23.fsf@evledraar.gmail.com/ 2. https://lore.kernel.org/git/87fstlrumj.fsf@evledraar.gmail.com/ 3. https://lore.kernel.org/git/877dexrqvg.fsf@evledraar.gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 3 +-- builtin/am.c | 6 ++---- builtin/checkout.c | 6 ++---- builtin/clone.c | 3 +-- builtin/commit.c | 3 +-- builtin/merge.c | 3 +-- builtin/read-tree.c | 3 +-- builtin/reset.c | 3 +-- builtin/sparse-checkout.c | 3 +-- builtin/stash.c | 6 ++---- diff-lib.c | 3 +-- merge-ort.c | 3 +-- merge-recursive.c | 4 +++- reset.c | 2 +- sequencer.c | 3 +-- unpack-trees.h | 1 + 16 files changed, 21 insertions(+), 34 deletions(-) diff --git a/archive.c b/archive.c index a3bbb091256..210d7235c5a 100644 --- a/archive.c +++ b/archive.c @@ -269,7 +269,7 @@ int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry) { struct archiver_context context; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; struct tree_desc t; int err; struct strbuf path_in_archive = STRBUF_INIT; @@ -300,7 +300,6 @@ int write_archive_entries(struct archiver_args *args, * Setup index and instruct attr to read index only */ if (!args->worktree_attributes) { - memset(&opts, 0, sizeof(opts)); opts.index_only = 1; opts.head_idx = -1; opts.src_index = args->repo->index; diff --git a/builtin/am.c b/builtin/am.c index e4a0ff9cd7c..82641ce68ec 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1901,7 +1901,7 @@ static void am_resolve(struct am_state *state) static int fast_forward_to(struct tree *head, struct tree *remote, int reset) { struct lock_file lock_file = LOCK_INIT; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; struct tree_desc t[2]; if (parse_tree(head) || parse_tree(remote)) @@ -1911,7 +1911,6 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset) refresh_cache(REFRESH_QUIET); - memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.src_index = &the_index; opts.dst_index = &the_index; @@ -1940,7 +1939,7 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset) static int merge_tree(struct tree *tree) { struct lock_file lock_file = LOCK_INIT; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; struct tree_desc t[1]; if (parse_tree(tree)) @@ -1948,7 +1947,6 @@ static int merge_tree(struct tree *tree) hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); - memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.src_index = &the_index; opts.dst_index = &the_index; diff --git a/builtin/checkout.c b/builtin/checkout.c index 8c69dcdf72a..fea4533dbec 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -639,10 +639,9 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o, int worktree, int *writeout_error, struct branch_info *info) { - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; struct tree_desc tree_desc; - memset(&opts, 0, sizeof(opts)); opts.head_idx = -1; opts.update = worktree; opts.skip_unmerged = !worktree; @@ -719,9 +718,8 @@ static int merge_working_tree(const struct checkout_opts *opts, } else { struct tree_desc trees[2]; struct tree *tree; - struct unpack_trees_options topts; + struct unpack_trees_options topts = UNPACK_TREES_OPTIONS_INIT; - memset(&topts, 0, sizeof(topts)); topts.head_idx = -1; topts.src_index = &the_index; topts.dst_index = &the_index; diff --git a/builtin/clone.c b/builtin/clone.c index ff1d3d447a3..0df820c5970 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -655,7 +655,7 @@ static int checkout(int submodule_progress) struct object_id oid; char *head; struct lock_file lock_file = LOCK_INIT; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; struct tree *tree; struct tree_desc t; int err = 0; @@ -683,7 +683,6 @@ static int checkout(int submodule_progress) hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); - memset(&opts, 0, sizeof opts); opts.update = 1; opts.merge = 1; opts.clone = 1; diff --git a/builtin/commit.c b/builtin/commit.c index e7320f66f95..6cc7313bad8 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -303,7 +303,7 @@ static void add_remove_files(struct string_list *list) static void create_base_index(const struct commit *current_head) { struct tree *tree; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; struct tree_desc t; if (!current_head) { @@ -311,7 +311,6 @@ static void create_base_index(const struct commit *current_head) return; } - memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.index_only = 1; opts.merge = 1; diff --git a/builtin/merge.c b/builtin/merge.c index 3fbdacc7db4..73290a07fcc 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -670,9 +670,8 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head, int i, nr_trees = 0; struct tree *trees[MAX_UNPACK_TREES]; struct tree_desc t[MAX_UNPACK_TREES]; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; - memset(&opts, 0, sizeof(opts)); opts.head_idx = 2; opts.src_index = &the_index; opts.dst_index = &the_index; diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 485e7b04794..847182fdad6 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -116,7 +116,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) int i, stage = 0; struct object_id oid; struct tree_desc t[MAX_UNPACK_TREES]; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; int prefix_set = 0; struct lock_file lock_file = LOCK_INIT; const struct option read_tree_options[] = { @@ -158,7 +158,6 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) OPT_END() }; - memset(&opts, 0, sizeof(opts)); opts.head_idx = -1; opts.src_index = &the_index; opts.dst_index = &the_index; diff --git a/builtin/reset.c b/builtin/reset.c index 51c9e2f43ff..86c604b21e9 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -51,10 +51,9 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t int i, nr = 0; struct tree_desc desc[2]; struct tree *tree; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; int ret = -1; - memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.src_index = &the_index; opts.dst_index = &the_index; diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index d0f5c4702be..4c3c29fb580 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -195,7 +195,7 @@ static void clean_tracked_sparse_directories(struct repository *r) static int update_working_directory(struct pattern_list *pl) { enum update_sparsity_result result; - struct unpack_trees_options o; + struct unpack_trees_options o = UNPACK_TREES_OPTIONS_INIT; struct lock_file lock_file = LOCK_INIT; struct repository *r = the_repository; @@ -205,7 +205,6 @@ static int update_working_directory(struct pattern_list *pl) r->index->sparse_checkout_patterns = pl; - memset(&o, 0, sizeof(o)); o.verbose_update = isatty(2); o.update = 1; o.head_idx = -1; diff --git a/builtin/stash.c b/builtin/stash.c index 8f42360ca91..1137e5fcbe8 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -233,7 +233,7 @@ static int clear_stash(int argc, const char **argv, const char *prefix) static int reset_tree(struct object_id *i_tree, int update, int reset) { int nr_trees = 1; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; struct tree_desc t[MAX_UNPACK_TREES]; struct tree *tree; struct lock_file lock_file = LOCK_INIT; @@ -244,8 +244,6 @@ static int reset_tree(struct object_id *i_tree, int update, int reset) hold_locked_index(&lock_file, LOCK_DIE_ON_ERROR); - memset(&opts, 0, sizeof(opts)); - tree = parse_tree_indirect(i_tree); if (parse_tree(tree)) return -1; @@ -799,7 +797,7 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op const struct object_id *oid[] = { &info->w_commit, &info->u_tree }; struct tree *tree[ARRAY_SIZE(oid)]; struct tree_desc tree_desc[ARRAY_SIZE(oid)]; - struct unpack_trees_options unpack_tree_opt = { 0 }; + struct unpack_trees_options unpack_tree_opt = UNPACK_TREES_OPTIONS_INIT; int i; for (i = 0; i < ARRAY_SIZE(oid); i++) { diff --git a/diff-lib.c b/diff-lib.c index ca085a03efc..8a08d9af4eb 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -526,13 +526,12 @@ static int diff_cache(struct rev_info *revs, { struct tree *tree; struct tree_desc t; - struct unpack_trees_options opts; + struct unpack_trees_options opts = UNPACK_TREES_OPTIONS_INIT; tree = parse_tree_indirect(tree_oid); if (!tree) return error("bad tree object %s", tree_name ? tree_name : oid_to_hex(tree_oid)); - memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.index_only = cached; opts.diff_index_cached = (cached && diff --git a/merge-ort.c b/merge-ort.c index 35aa979c3a4..75d2b8e4b99 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4021,9 +4021,8 @@ static int checkout(struct merge_options *opt, /* Switch the index/working copy from old to new */ int ret; struct tree_desc trees[2]; - struct unpack_trees_options unpack_opts; + struct unpack_trees_options unpack_opts = UNPACK_TREES_OPTIONS_INIT; - memset(&unpack_opts, 0, sizeof(unpack_opts)); unpack_opts.head_idx = -1; unpack_opts.src_index = opt->repo->index; unpack_opts.dst_index = opt->repo->index; diff --git a/merge-recursive.c b/merge-recursive.c index e594d4c3fa1..40254ec0b3d 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -404,8 +404,10 @@ static int unpack_trees_start(struct merge_options *opt, int rc; struct tree_desc t[3]; struct index_state tmp_index = { NULL }; + struct unpack_trees_options blank = UNPACK_TREES_OPTIONS_INIT; - memset(&opt->priv->unpack_opts, 0, sizeof(opt->priv->unpack_opts)); + assert(sizeof(blank) == sizeof(opt->priv->unpack_opts)); + memcpy(&opt->priv->unpack_opts, &blank, sizeof(opt->priv->unpack_opts)); if (opt->priv->call_depth) opt->priv->unpack_opts.index_only = 1; else diff --git a/reset.c b/reset.c index 79310ae071b..d13984ab781 100644 --- a/reset.c +++ b/reset.c @@ -21,7 +21,7 @@ int reset_head(struct repository *r, struct object_id *oid, const char *action, struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; - struct unpack_trees_options unpack_tree_opts = { 0 }; + struct unpack_trees_options unpack_tree_opts = UNPACK_TREES_OPTIONS_INIT; struct tree *tree; const char *reflog_action; struct strbuf msg = STRBUF_INIT; diff --git a/sequencer.c b/sequencer.c index 614d56f5e21..abd85b6c562 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3652,7 +3652,7 @@ static int do_reset(struct repository *r, struct lock_file lock = LOCK_INIT; struct tree_desc desc; struct tree *tree; - struct unpack_trees_options unpack_tree_opts; + struct unpack_trees_options unpack_tree_opts = UNPACK_TREES_OPTIONS_INIT; int ret = 0; if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) @@ -3691,7 +3691,6 @@ static int do_reset(struct repository *r, } } - memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); setup_unpack_trees_porcelain(&unpack_tree_opts, "reset"); unpack_tree_opts.head_idx = 1; unpack_tree_opts.src_index = r->index; diff --git a/unpack-trees.h b/unpack-trees.h index 2d88b19dca7..caa7ada59ab 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -90,6 +90,7 @@ struct unpack_trees_options { struct pattern_list *pl; /* for internal use */ struct checkout_metadata meta; }; +#define UNPACK_TREES_OPTIONS_INIT { 0 } int unpack_trees(unsigned n, struct tree_desc *t, struct unpack_trees_options *options);