From patchwork Mon Sep 27 00:53:15 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: 12518969 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 EFFD6C433FE for ; Mon, 27 Sep 2021 00:53:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D634B60F92 for ; Mon, 27 Sep 2021 00:53:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232341AbhI0AzC (ORCPT ); Sun, 26 Sep 2021 20:55:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232336AbhI0AzB (ORCPT ); Sun, 26 Sep 2021 20:55:01 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB0F4C061570 for ; Sun, 26 Sep 2021 17:53:24 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id g16so47272928wrb.3 for ; Sun, 26 Sep 2021 17:53:24 -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=IomzZ86x24zWVNUlJzN/X79HbuN8rS9DJ8UqAZrLRyA=; b=kwnRyvSBMrbew6FFUDbAUqBKsreKRl/XnUWdvEJ2SJUjz/2W+x280uVnoJPNQ9xc3w dtTd86tZsIU1x53XR53e+1+SosGIP6lO7pJXp0fbWB8AN7BJcjjPkbGaSFHgMUOiox6z daGUJdrfNJjTgR3qqwUJQco29zUw1QebXGqoSdx1bhIKBIr4tyP42uygO5I5r6876LZw xLmL+V8v4fTtzgJpqx9Q7H61k7AsbSkneAdQ7UcpJ0cSa7SMlOX4H8rurOwgZ4VYroU8 G9HAlqUAmYAK+n/qYBI+W3jL3bM2kZSLuo55pvOIHPgnLliEGBXfNc/aQKxxdVdGedWU KIKg== 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=IomzZ86x24zWVNUlJzN/X79HbuN8rS9DJ8UqAZrLRyA=; b=LhuJPosD8UDRl2IfQCzscsNEEmZN1GedTqP7gZDUeW1LMACBvNSmUJ12X6lVnds0V+ 1dZqp75SzAlYTt8Nkf+8qdIL0LAreh9xmgyAnHLYWeWAcyTpZAGBuhHPUKZWftx6LGh+ SQ1OCjpGZm3evscyXxTOxbTT9YPQioVbxm3H19ER2SVbCrEV+GRViMxIYicxgJVrbB2q OVHKvAQDB4xz2Yn2Mvp41TScNyQcUWmNCSNJGgcirWAZ1OABaYBR5+gYfmIaDZuXoMrq C4KyPFW7I6ugiUODkWXaero17igJy7czQCOBHFLfB78C3a4QwHOQXYNn1mkD1oDVBgVf 3XwQ== X-Gm-Message-State: AOAM532pkOmJTsx7GaEFqL20q7DYeY4DN6fn+YaHfaHezRgqKNdKW8sl dDXOzWPYVE4gABEtpbtVnHMjnJ9tSiQSww== X-Google-Smtp-Source: ABdhPJy4ZV5t09CAzUwq1bikTh5Hkdsmf2FVSfT6rUiA6SUJ9uJZVsHNYOXMbIlFfF1TJHON83TGHA== X-Received: by 2002:a5d:424c:: with SMTP id s12mr2409101wrr.294.1632704003245; Sun, 26 Sep 2021 17:53:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i2sm14749745wrq.78.2021.09.26.17.53.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 17:53:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/6] daemon.c: refactor hostinfo_init() to HOSTINFO_INIT macro Date: Mon, 27 Sep 2021 02:53:15 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1316.gb2e9b3ba3ae 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 Mon Sep 27 00:53:16 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: 12518971 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 07F01C433F5 for ; Mon, 27 Sep 2021 00:53:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E24756113A for ; Mon, 27 Sep 2021 00:53:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232349AbhI0AzE (ORCPT ); Sun, 26 Sep 2021 20:55:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232342AbhI0AzC (ORCPT ); Sun, 26 Sep 2021 20:55:02 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 790F8C061570 for ; Sun, 26 Sep 2021 17:53:25 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id t8so47370923wri.1 for ; Sun, 26 Sep 2021 17:53:25 -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=YEOg4jG1XTxObl/c3+f3Fvsn3dLUVPfQUMMjsDovzMI=; b=AdRhH0uQNtN0+cvm8T9tfB5WlG6DoCNQcG9xpjQFugJELk/N/rRNjNJW+Zb6k7/dh3 UVHDFUzEGDKgiKjqpduO4Za5DSHQzRKQ1CTHh3Qs7+3bq0NpdNoHI3keFTY3zw4yeOIy SJ5nHimILnf8yRTpmG69iSNQrABrilafQaRlJuJtVVWlcQh+hvnmPncDw+iHu973Qlay BZ4Sijs8mABRbL+7IJGq/KjzxlO2rGmUlCWzThrKgD1Z7c78dfFKW9d5s9nMC16cMlma a86kYYH940444keJOh6Auj0XoKB/JAydOar1KC3RORyuceJdWHJd94BheXWbYEqBxG+s zCOg== 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=YEOg4jG1XTxObl/c3+f3Fvsn3dLUVPfQUMMjsDovzMI=; b=8Eum6jtPkEP5Gla38GAb1tZfb6uMAg/IMZFc2P3jz+hfnSN+6rWV66R+bAxxfTc+X0 4otRNv7sJ01Z0HfrAV5tTqRWViQsBd98T6ZifqUjUva10Fto1PL/e3LRApaptawaB8QV 0eLz3v7VVYRUAWb05qtVL5gZnOs7FEnNLleWmJ+uTfcmAZVgJKdDZ4aeriaU6s3ht96B /5sxipEFsEaQrhbckPENyxOLAL54r5yWwyBtsxACZEt4BRAr0DRV7iUB4hDVXpPO7nfS yBBUgrMvfIAxZKW3TNYr+aXmLl+ktsIPQBlhCoOEh3dwpASiduIWsUoYeH6rdCK1Gs3i /iOw== X-Gm-Message-State: AOAM533V0qpi+4cfhW5TuhAiD/PYWDnK6xWZbUWP357mcfSnDSyw817T TCbTbV5VKePe77T8kxjL4Cgwje70RZrqqA== X-Google-Smtp-Source: ABdhPJw+j323vn6bP8b/QOqQYV4TQGeqcGZumY2IGdN7Q6iq/oaA7ZKjOVVTfQMgL6fqLpCmM623jg== X-Received: by 2002:adf:f8cc:: with SMTP id f12mr23873535wrq.195.1632704003904; Sun, 26 Sep 2021 17:53:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i2sm14749745wrq.78.2021.09.26.17.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 17:53:23 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/6] builtin/blame.c: refactor commit_info_init() to COMMIT_INFO_INIT macro Date: Mon, 27 Sep 2021 02:53:16 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1316.gb2e9b3ba3ae 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 Mon Sep 27 00:53:17 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: 12518973 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 73F3CC433F5 for ; Mon, 27 Sep 2021 00:53:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59B426103B for ; Mon, 27 Sep 2021 00:53:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232357AbhI0AzF (ORCPT ); Sun, 26 Sep 2021 20:55:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232338AbhI0AzD (ORCPT ); Sun, 26 Sep 2021 20:55:03 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CABBC061570 for ; Sun, 26 Sep 2021 17:53:26 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id v17so3832606wrv.9 for ; Sun, 26 Sep 2021 17:53:26 -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=oQ8mVJpemGK74uSrk9WPGPUUo7HiFI8SCIOhxKAnrwY=; b=AKDHKVc+KcdLd4H9gL3v4jpt1NDZvMaf19sBwxEYqFvznvhiJuZruxoBgGPQ88g1C0 JZHSMWnP3S2omRT/in5d+ukTPbpNfHwPsyNzknZo8s1V3yDCPAscyWIr4jftjDCHr/MW STJFdf2qAwNsDdaUDHpBdBNOzH4dkSzpOgEIXlW9FDmJqF3Ep82L42kQXHW0x9MwcXWf nnwUDrnkKzznw/0EdVo4GH0+2+9yCBGqKBIn4CY1c4gbCEAM+dOyHLN4iZZ2wu8rttLr HYDFP4up3QNdX3Z3lLEdctvz8O2l6UAyLG3wn16Q/6KpeUy2MIZSp/2AXYTy3Qb1ZZVm 9cpA== 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=oQ8mVJpemGK74uSrk9WPGPUUo7HiFI8SCIOhxKAnrwY=; b=cZLeGFEJif0JFiPcbisAof5mD5WT5nVk6/F/7WBZwMyRrtIyjOTV9Zn0AW8kLjj+oP EhfodkXrDcuBY2aoLsFfzhV0Fz/rqfS0+ViOgvbdzEOXw0wnYdM6hXJJqcLx4ZYT9ZHp peP2omUkeWPq6KgW8CdCGHXNwMeEFe3seLQYmO3V1084TJz6Y0cq0/bRTcfsVX/LLBBj DIxUFlW5NuSG5+zmnMoE6hJ5RBsbasykZX4fXQYnMRWTP9xWBh5sGP3aJgw4/hwHLDH3 GFPxah/rOEhi930dHT9dBo1QP/SMzHSHnuTcU92aPhquC4rzZRuLzOLUfWUcqYQRxLs5 qRtg== X-Gm-Message-State: AOAM5321i7uF0wC0zEBnaCxaWQKc/SolwqHlFHHzVtt/Z3jwGCD9DH5e 1upi78szhLpVxRULds7bj8/8iv6CSkBFSg== X-Google-Smtp-Source: ABdhPJwU+0LW8638VKjGATGka7givmear+MSJcfnHQvY4dPj+HZaFDhaWKbHVm8UuZJkNvpoH9ytsg== X-Received: by 2002:a5d:6d8e:: with SMTP id l14mr24593087wrs.196.1632704004498; Sun, 26 Sep 2021 17:53:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i2sm14749745wrq.78.2021.09.26.17.53.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 17:53:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/6] shortlog: use designated initializer for "struct shortlog" Date: Mon, 27 Sep 2021 02:53:17 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1316.gb2e9b3ba3ae In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code added in 64093fc06a (blame,shortlog: don't make local option variables static, 2016-06-13) to use a designated initializer via a typical *_INIT macro pattern. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/shortlog.c | 2 +- shortlog.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 3e7ab1ca821..fa1f76cc51e 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -342,7 +342,7 @@ void shortlog_init(struct shortlog *log) int cmd_shortlog(int argc, const char **argv, const char *prefix) { - struct shortlog log = { STRING_LIST_INIT_NODUP }; + struct shortlog log = SHORTLOG_INIT; struct rev_info rev; int nongit = !startup_info->have_repository; diff --git a/shortlog.h b/shortlog.h index 3f7e9aabcae..47892d6d604 100644 --- a/shortlog.h +++ b/shortlog.h @@ -28,6 +28,10 @@ struct shortlog { FILE *file; }; +#define SHORTLOG_INIT { \ + .list = STRING_LIST_INIT_NODUP, \ +} + void shortlog_init(struct shortlog *log); void shortlog_add_commit(struct shortlog *log, struct commit *commit); From patchwork Mon Sep 27 00:53:18 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: 12518975 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 4CBDFC433EF for ; Mon, 27 Sep 2021 00:53:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37A4560D42 for ; Mon, 27 Sep 2021 00:53:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232324AbhI0AzI (ORCPT ); Sun, 26 Sep 2021 20:55:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232345AbhI0AzD (ORCPT ); Sun, 26 Sep 2021 20:55:03 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC47AC061575 for ; Sun, 26 Sep 2021 17:53:26 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id i23so47329538wrb.2 for ; Sun, 26 Sep 2021 17:53:26 -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=6fcd36RsG2KA+FbhLjrBdVrQFExZV/4afFZDstOHA0k=; b=UVv70ljnT8fxnvvlV34zfeB7i+wRIbxrDVmkfRgSHwo0Uxus47F58+5S2XeYSKwgvF iijtHP8z57OD51Epz3CN1DnsSLwYXmYgMa5mNCS8UBvOP+NOIE5pwaC2/VzXJIjG9Gn1 yGlRp3mvROHnJ0+lS6z2UZ+cCkYiE5pJSiW48edwGkn+p/4gHucEZRuTPUj7Aw1cY37L M4QL0ugmeuwdTe7WX7ezdOnsw2u2QSAMjAB0xRnA2/HKytmctG0Hc+oRDZ93l6Ewu+TB X+++uHnP9BfC9BNibB4w3G8B5G26l+qEvL19AlFJQlaTKbjJmDTlf4nDcNxw3N3gaJJv R0RQ== 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=6fcd36RsG2KA+FbhLjrBdVrQFExZV/4afFZDstOHA0k=; b=U/heIcorTw0kXxGV8DCPrmw9jLBq7US4oTNI2HlrifjkWEflaeZY9CklNSLzbMgRjd BDF8bIOAZcoBwPd9zmJuAO+UGBi68erHPgQuPAX6GCyHlowXyUTKk1uKxcwbjMUlxNTR TwWrUNbhyNTHRdSoeWSEtJSSkWPwEavyFnyvZ6EleKLy+mvSw/bQirE0uXvWteeQPs2p vusKGFDyW4FFIqWzG1iJWLD+kJDH8AnJALAhgv69T++N2i3WgdChbdwvAVtvPJneXlNU lqurWrxel01hv8EniVX/DHyh+QQZgYRKAh0SlyBWhTC+yrAQLeYKno3qbW9LNmDpvojb obNg== X-Gm-Message-State: AOAM531JAZuxDHIMjnxSlUs23wZbtHNTKZBKktsn+0qh07DaytZnNANs gR7Ge1KpfSpCKwPHPjT9xts+wmImkWP4jg== X-Google-Smtp-Source: ABdhPJwbaLoiDH+qpHmT+XhhACy3cQ5Cux2w6vLFaYhWv/FTOgLxa1PrE1sPznKjUujQrCI4CoJQvQ== X-Received: by 2002:a05:6000:160c:: with SMTP id u12mr24862245wrb.128.1632704005204; Sun, 26 Sep 2021 17:53:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i2sm14749745wrq.78.2021.09.26.17.53.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 17:53:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 4/6] urlmatch.[ch]: add and use URLMATCH_CONFIG_INIT Date: Mon, 27 Sep 2021 02:53:18 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1316.gb2e9b3ba3ae 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. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/config.c | 3 +-- credential.c | 4 +--- http.c | 4 +--- urlmatch.h | 4 ++++ 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 865fddd6ce8..1ea4f68b7de 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -575,11 +575,10 @@ 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; - config.cascade_fn = NULL; config.cb = &values; if (!url_normalize(url, &config.url)) diff --git a/credential.c b/credential.c index 000ac7a8d43..c85db8a75cd 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) @@ -117,9 +117,7 @@ static void credential_apply_config(struct credential *c) return; config.section = "credential"; - config.key = NULL; config.collect_fn = credential_config_callback; - config.cascade_fn = NULL; config.select_fn = select_all; config.fallback_match_fn = match_partial_url; config.cb = c; diff --git a/http.c b/http.c index d7c20493d7f..3d6ad5c7be8 100644 --- a/http.c +++ b/http.c @@ -990,13 +990,11 @@ 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; config.collect_fn = http_options; config.cascade_fn = git_default_config; - config.cb = NULL; http_is_verbose = 0; normalized_url = url_normalize(url, &config.url); 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 Mon Sep 27 00:53:19 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: 12518977 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 8E1DEC433FE for ; Mon, 27 Sep 2021 00:53:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7256D6113D for ; Mon, 27 Sep 2021 00:53:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232384AbhI0AzJ (ORCPT ); Sun, 26 Sep 2021 20:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232351AbhI0AzE (ORCPT ); Sun, 26 Sep 2021 20:55:04 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77043C061570 for ; Sun, 26 Sep 2021 17:53:27 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id d21so47128633wra.12 for ; Sun, 26 Sep 2021 17:53:27 -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=n1Pq33ch4Ok8+aJqu/Yu0JnscS2P7E1ReMLdcX+ykC4gSAGPrx0rgFu8aIPfWYhk+9 fN0/akq3+gpgdS6vBiTqhsIbY26wmF5L2du859IEU9fVCLbPP14n6a7WbeoHKyEhT/li FbP9zWIqeRwVG6kDanGWPb088lmkZKhkNmTgTpw6LBhX+dyQDJibxdntDkzw9/XnAgJ4 1G+yohcaDB2OR4Yg3jqhr8D6+HG8flmuTkOj4IndDHW6QrhMjmOVPWwjgVjiMSprQ8Gk u9DSLbMZq8nPHmd3voZtQaY3ThRnqFwDrX81yBRFDvF4sMBVQuljYDy3UfFHqtJzVEJC gnrw== 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=rSVR4gTqkvUZGL9ZetcbPL/+1THTpO2IuGMUMj5gAJI5Q+aM05xYgkpXMML/BykM70 ny2oLVJEmLkOX8pFYITawjimG+/seCBWTESeV6p+lOWaZt2elPI0lqo571hQAQsGGmHA 0nMkLsH3+BLiHw1Y/rQfgyS4baaiceyoaHMxggWvKWi3wAvh6u2q0wRhri7mqwjEnZ3h 530+hojvnlWrvvJ/Wg5uvwYmkhQE+KlOeVBkAuumgo+19r7olKOUkslKjM9R4dHhE2hz XksXosBa4WZeU8b6ViAv2jRegolVieOy+1OcYXdRrPE1v0rg0GWJfkLmPSsh+y7gCfBN OZFg== X-Gm-Message-State: AOAM532kc14AXQnBLRqM3rEvXmeOWqc9hoTo7Tr+skmYETq33ei6WdGY So0POjsWICTgovj9sQVvlw5SGktkuT1j+g== X-Google-Smtp-Source: ABdhPJwZdznAJB4OExjWWbuOCfu7XVzGHXuhDMuL1DwLfSkzFpZ2gy4CW7rJL7ti8+sAtTbVyGeOGg== X-Received: by 2002:a5d:6292:: with SMTP id k18mr24737639wru.110.1632704005906; Sun, 26 Sep 2021 17:53:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i2sm14749745wrq.78.2021.09.26.17.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 17:53:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 5/6] builtin/remote.c: add and use a REF_STATES_INIT Date: Mon, 27 Sep 2021 02:53:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1316.gb2e9b3ba3ae 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. 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 Mon Sep 27 00:53:20 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: 12518979 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 89E08C433EF for ; Mon, 27 Sep 2021 00:53:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7381F60F92 for ; Mon, 27 Sep 2021 00:53:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232375AbhI0AzM (ORCPT ); Sun, 26 Sep 2021 20:55:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232374AbhI0AzF (ORCPT ); Sun, 26 Sep 2021 20:55:05 -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 AB7AFC061570 for ; Sun, 26 Sep 2021 17:53:28 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x20so2551935wrg.10 for ; Sun, 26 Sep 2021 17:53:28 -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=aPVW358KMffOcU5NvWPMkqkUO9OA/F0e/FQahSbWyxg=; b=Ul3hRhbdt3nLPh9FRwHEOuwcWecMnh7P2qX+gXK2jmTkyqRr4qrK/9ibjrY12JKvLq 6vSoNRNSMtpFD17Ob/BbxbEd5bquxi3FrAKcGZhLz7LZ9H7v/NlomGbo2fDbiQ2oPwIh 4It6YMLlNx8hqsOrvDJWYI9qBbk+dTb+PQS2dWvyXDBeNWtHQE/zVYNQ4ZdqikScncqx olR1IlTdfn7T/bKlmxGgVDPNDBTQwUEgTTdI+z3Y9K3e1gSPvCJGMGWO5o9bB9tAB0f/ hxK45AoalDPhg487yCu81NSpNcj8BWogAcdTnEOQohHcVkTxmJya10DWqdR7uNYmrIOI qy0w== 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=aPVW358KMffOcU5NvWPMkqkUO9OA/F0e/FQahSbWyxg=; b=J/mhkLlcLeznzB1zosDx/K6Nh8o8r0VpA58sPnUmZpxiGi4OLXy6qCn6g/tAmir6cr c6ZxmOrCzSLMhADm2epXaBPjvZ2Cn00NeFSpLwayOsi8DHc21calsCUzsJWYe+w0Gg/s s/WNHAp7iy1lyaeyEWYuaJf9eBdg2qRoJrLP4wVMv75fUCMH630G13Cj1rLk545h0TCs cE2ngm6MVG6UsBA7t5IKXkbqZAotlhApd4gpoAqezMVRgZ0446mTwiMGvFvz8w1UR6rk OC+rvhoQmaWEKmWE6lLUjYH4oJtH+sNslWDctaJGPZO1lXM/noUk91kG7tzUe4eWxzBM vCCQ== X-Gm-Message-State: AOAM5302YvLw6//BuxgvMubIsLgo+cHU34/Uw2yFhsMXMi+TVyoXOA3x hgptOIzETRBgEO4MIydTY0jLyyMODYh7tQ== X-Google-Smtp-Source: ABdhPJy6AUg1aBwUyec+0pfi7hZoyU9boc+jaEsTLK2/cWkAN2stIncSyfcQDt5Z/kvYx2bwxfIvMA== X-Received: by 2002:adf:ee48:: with SMTP id w8mr24836081wro.263.1632704006569; Sun, 26 Sep 2021 17:53:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i2sm14749745wrq.78.2021.09.26.17.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Sep 2021 17:53:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?q?Martin_=C3=85gren?= , =?utf-8?b?w4Z2YXIg?= =?utf-8?b?QXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 6/6] builtin/remote.c: add and use SHOW_INFO_INIT Date: Mon, 27 Sep 2021 02:53:20 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1316.gb2e9b3ba3ae 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;