From patchwork Thu Jul 1 10:51:25 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: 12353935 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D7CDC11F67 for ; Thu, 1 Jul 2021 10:51:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05DDF61476 for ; Thu, 1 Jul 2021 10:51:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236090AbhGAKyK (ORCPT ); Thu, 1 Jul 2021 06:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbhGAKyG (ORCPT ); Thu, 1 Jul 2021 06:54:06 -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 1EA18C061756 for ; Thu, 1 Jul 2021 03:51:36 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id j1so7588013wrn.9 for ; Thu, 01 Jul 2021 03:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aWftUBBJ66R1Hq1bO/mpPUIrO5CfdUF6nTp6uUnBzaE=; b=Ks0v6bidWvVlHc5MZiWbC7Qh2NzDFBILR/lhb4kYuvNmaDnYwtKiZW0AvLsOeNq503 Ld0ORpcTYwjq8dnOumZbxF2JrTtn9IoVXg4Z891nf0qb9CFAirV85IoOPR0JlviJR28W x8ih+0c/Hro4485No5A2JdH/GzE9qm13R5FD1kv19qGRhX8DcfC51HkiWDHyOamyFAzp B/hOSXJJR407+abddFRISmtVsOguXXX+ccm9pcBr3k9dObwuDN1fmTa8ydWOXC2ofY6O WYer3UcniguwSEEYUdJs2mLj+v4Glumb6KQ5WH3QYiVkvUIDuMMXy0ZEv/2uYKEbGqCG gJCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aWftUBBJ66R1Hq1bO/mpPUIrO5CfdUF6nTp6uUnBzaE=; b=gy0053gIVta66jpvSnECcB4Z//1As6fYzjyFbbz24psI0rDq7/yWYfKJHSyTq4T6cA x1Ymb+Mk/MwYf8RP4EbLO92VOgDtfrSxnJ2XAN/3VmfQRMbhW950ptkKXsskBVFh6lP0 iNmxitrvsttbhRn4yaSFr0Z+IbVIVQHg/S6fM2F+a6ugQ5N7DNVic+8tVzqXt0AOylHH /gAgKq6gzJi4a8mdpVlCbzURQnVW3C5m4KHCkOcmMU3tKwJd5lembH12HfACHE9lWFdP MY7EZ9hhONZB1xu93O7w7LeH/KTlCMlXz6f4BnYDvZN0C+wDBfHOywcShP5/GecDgskF XoCg== X-Gm-Message-State: AOAM530x3Jg9QJRVjjdRKKS1afhUcggUkAgxRzg38vReozk0FZFjMuSz bS8LywN4HGjRbXr9XZ514Td6E1HRQYQ+Mg== X-Google-Smtp-Source: ABdhPJwfl+toyVTP7StIJf1kaU9xIi43QDrb5wttQ3xjqRqyy3VlUjbX8wPGRyT49yQVsUDEfxaP8w== X-Received: by 2002:a5d:6a0d:: with SMTP id m13mr44241478wru.318.1625136694440; Thu, 01 Jul 2021 03:51:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p9sm8015699wmm.17.2021.07.01.03.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 03:51:33 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/5] *.h: move some *_INIT to designated initializers Date: Thu, 1 Jul 2021 12:51:25 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.632.g11c1df94a06 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Move *_INIT macros I'll use in a subsequent commits to designated initializers. This isn't required for those follow-up changes, but since I'm changing things in this are let's use the modern pattern over the old one while we're at it. Signed-off-by: Ævar Arnfjörð Bjarmason --- credential.h | 4 +++- json-writer.h | 5 ++++- run-command.h | 5 ++++- string-list.h | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/credential.h b/credential.h index c0e17e3554f..f430e77fea4 100644 --- a/credential.h +++ b/credential.h @@ -128,7 +128,9 @@ struct credential { char *path; }; -#define CREDENTIAL_INIT { STRING_LIST_INIT_DUP } +#define CREDENTIAL_INIT { \ + .helpers = STRING_LIST_INIT_DUP, \ +} /* Initialize a credential structure, setting all fields to empty. */ void credential_init(struct credential *); diff --git a/json-writer.h b/json-writer.h index 83906b09c17..209355e0f12 100644 --- a/json-writer.h +++ b/json-writer.h @@ -64,7 +64,10 @@ struct json_writer unsigned int pretty:1; }; -#define JSON_WRITER_INIT { STRBUF_INIT, STRBUF_INIT, 0, 0 } +#define JSON_WRITER_INIT { \ + .json = STRBUF_INIT, \ + .open_stack = STRBUF_INIT, \ +} void jw_init(struct json_writer *jw); void jw_release(struct json_writer *jw); diff --git a/run-command.h b/run-command.h index d08414a92e7..62a922d23fb 100644 --- a/run-command.h +++ b/run-command.h @@ -141,7 +141,10 @@ struct child_process { void *clean_on_exit_handler_cbdata; }; -#define CHILD_PROCESS_INIT { NULL, STRVEC_INIT, STRVEC_INIT } +#define CHILD_PROCESS_INIT { \ + .args = STRVEC_INIT, \ + .env_array = STRVEC_INIT, \ +} /** * The functions: child_process_init, start_command, finish_command, diff --git a/string-list.h b/string-list.h index 6c5d274126a..521b9c0748d 100644 --- a/string-list.h +++ b/string-list.h @@ -91,8 +91,8 @@ struct string_list { compare_strings_fn cmp; /* NULL uses strcmp() */ }; -#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0, NULL } -#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1, NULL } +#define STRING_LIST_INIT_NODUP { 0 } +#define STRING_LIST_INIT_DUP { .strdup_strings = 1 } /* General functions which work with both sorted and unsorted lists. */ From patchwork Thu Jul 1 10:51:26 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: 12353933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4AB0C11F69 for ; Thu, 1 Jul 2021 10:51:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 883C861476 for ; Thu, 1 Jul 2021 10:51:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236089AbhGAKyK (ORCPT ); Thu, 1 Jul 2021 06:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235966AbhGAKyH (ORCPT ); Thu, 1 Jul 2021 06:54:07 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D30F0C0617A8 for ; Thu, 1 Jul 2021 03:51:36 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id a13so7585304wrf.10 for ; Thu, 01 Jul 2021 03:51:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pWQ5jZWLEVfefRz+/qF73AjlxA+QRJVIgn/xB/cxI08=; b=UXHfD6EtkZcDUdOtnB0LXUJ/45HakeSYrWtw31TjQbgNBfSmR8AtHycilEWX/wS22x IrjK15Bp7x0A3RIKT7KaILQV7wWBVJcQ652mTYMTql8Vm/162Ss3a1XXQkkA3Yh5heka KaepG7OTlFLqk1oAQ41DDacSnhRgPT1BFKoQ5i14jSHSLikIbTvAKRyD1cUNFSHk7Ljw 63HfVAcSIXHy8sLVg6ys+HNB1qrxSOIfsFIW1eA1cwRiMyh9X7PjIVrIoRgSQHJ+o8rd 6/6GqQWzJb4N1UAIjKdDn5a3MWXX2nebvJB/MujfGvit/n1zW0vsB5QRXSJ9dKUI+/vw aK/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pWQ5jZWLEVfefRz+/qF73AjlxA+QRJVIgn/xB/cxI08=; b=gsnDKKEpo4R6SRyUJfYh9O34LjX/mKzWMmqSsnPUULjw9UKelCVCIxI57pNoueR8bU pKK9sE7uL9lCAdKeD5m4ZqrFyE8CaMk20zdEw+Cul4kwn74UgvLPSwi8Fgtx7+A0Y9fn ERfQ4IgJApYJnHZW3oklkNaCnMjOVU11BtkCeSdv91egtXo3M9k30QosgmzaE7yhlTXL 77cF6396E/wFoBC18ju2F8j7eZpgJFc3xSbrR2pjvq3NmbwsTIujlO0wXexo0Hf8T5xx zVzf5sVhnYyA8sJIwpXj1Mpak+1kHSEMxH34PNYXAvMBbPpWplPE+a4dtLj3opcPGmKa uang== X-Gm-Message-State: AOAM530qJ9lOK/ZH1SuYJfB5OXvGEq3bdPZRqLqau2JTSSQM55bl3vtr WjzZa7sl6GmIxojFP014MbK57XkdhEKzZQ== X-Google-Smtp-Source: ABdhPJz9HcwE9sx4pGZU0azRk54QByGcgJRbPeRG1jc78YpzctHPyq/6seZWgdAwyERKTP8u5nU/Hw== X-Received: by 2002:a5d:4b45:: with SMTP id w5mr18010537wrs.257.1625136695171; Thu, 01 Jul 2021 03:51:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p9sm8015699wmm.17.2021.07.01.03.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 03:51:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/5] *.c *_init(): define in terms of corresponding *_INIT macro Date: Thu, 1 Jul 2021 12:51:26 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.632.g11c1df94a06 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the common patter in the codebase of duplicating the initialization logic between an *_INIT macro and a corresponding *_init() function to use the macro as the canonical source of truth. Now we no longer need to keep the function up-to-date with the macro version. This implements a suggestion by Jeff King who found that under -O2 [1] modern compilers will init new version in place without the extra copy[1]. The performance of a single *_init() won't matter in most cases, but even if it does we're going to be producing efficient machine code to perform these operations. 1. https://lore.kernel.org/git/YNyrDxUO1PlGJvCn@coredump.intra.peff.net/ Signed-off-by: Ævar Arnfjörð Bjarmason --- credential.c | 4 ++-- json-writer.c | 6 ++---- run-command.c | 5 ++--- strbuf.c | 4 ++-- strmap.c | 3 ++- strvec.c | 5 ++--- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/credential.c b/credential.c index e5202fbef26..3c05c7c6691 100644 --- a/credential.c +++ b/credential.c @@ -10,8 +10,8 @@ void credential_init(struct credential *c) { - memset(c, 0, sizeof(*c)); - c->helpers.strdup_strings = 1; + struct credential blank = CREDENTIAL_INIT; + memcpy(c, &blank, sizeof(*c)); } void credential_clear(struct credential *c) diff --git a/json-writer.c b/json-writer.c index aadb9dbddc3..f1cfd8fa8c6 100644 --- a/json-writer.c +++ b/json-writer.c @@ -3,10 +3,8 @@ void jw_init(struct json_writer *jw) { - strbuf_init(&jw->json, 0); - strbuf_init(&jw->open_stack, 0); - jw->need_comma = 0; - jw->pretty = 0; + struct json_writer blank = JSON_WRITER_INIT; + memcpy(jw, &blank, sizeof(*jw));; } void jw_release(struct json_writer *jw) diff --git a/run-command.c b/run-command.c index be6bc128cd9..8750df16d89 100644 --- a/run-command.c +++ b/run-command.c @@ -11,9 +11,8 @@ void child_process_init(struct child_process *child) { - memset(child, 0, sizeof(*child)); - strvec_init(&child->args); - strvec_init(&child->env_array); + struct child_process blank = CHILD_PROCESS_INIT; + memcpy(child, &blank, sizeof(*child)); } void child_process_clear(struct child_process *child) diff --git a/strbuf.c b/strbuf.c index 4df30b45494..c8a5789694c 100644 --- a/strbuf.c +++ b/strbuf.c @@ -52,8 +52,8 @@ char strbuf_slopbuf[1]; void strbuf_init(struct strbuf *sb, size_t hint) { - sb->alloc = sb->len = 0; - sb->buf = strbuf_slopbuf; + struct strbuf blank = STRBUF_INIT; + memcpy(sb, &blank, sizeof(*sb)); if (hint) strbuf_grow(sb, hint); } diff --git a/strmap.c b/strmap.c index 4fb9f6100ec..ee486357082 100644 --- a/strmap.c +++ b/strmap.c @@ -25,7 +25,8 @@ static struct strmap_entry *find_strmap_entry(struct strmap *map, void strmap_init(struct strmap *map) { - strmap_init_with_options(map, NULL, 1); + struct strmap blank = STRMAP_INIT; + memcpy(map, &blank, sizeof(*map)); } void strmap_init_with_options(struct strmap *map, diff --git a/strvec.c b/strvec.c index 21dce0a7a4d..61a76ce6cb9 100644 --- a/strvec.c +++ b/strvec.c @@ -6,9 +6,8 @@ const char *empty_strvec[] = { NULL }; void strvec_init(struct strvec *array) { - array->v = empty_strvec; - array->nr = 0; - array->alloc = 0; + struct strvec blank = STRVEC_INIT; + memcpy(array, &blank, sizeof(*array)); } static void strvec_push_nodup(struct strvec *array, const char *value) From patchwork Thu Jul 1 10:51:27 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: 12353931 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25B39C11F64 for ; Thu, 1 Jul 2021 10:51:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B2206147D for ; Thu, 1 Jul 2021 10:51:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236078AbhGAKyJ (ORCPT ); Thu, 1 Jul 2021 06:54:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236015AbhGAKyI (ORCPT ); Thu, 1 Jul 2021 06:54:08 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94463C0617AD for ; Thu, 1 Jul 2021 03:51:37 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id r3so4202789wmq.1 for ; Thu, 01 Jul 2021 03:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J62VD9CK7RpAgptmkAbcgEVIp9kjtSSQNRCoxzVMxBI=; b=MZMzre5IXF8TsGOVCyGtGNjMsYxkn3ODoArxJtme2k6piKMJxp13WD9pdZAJ458eRJ hLA3AkdrAuFbMf3x4fmUjm+diSHnnFlxHAdqJOBLBtwo6NlQ3gFr6o+iFn2BRKEcQici 7DgKIA5qJUsX5eNMWeIcFiELxOS5MQfCkpI4wWGX2wjLjTQHXVEEBPiRjVUdtQp+u2Jx jRA0cpR0BmDIlbI+m/0cAK4hzkl/HOwPGwrV5R6j34WeeKLCsU0uE/vQxoheNjSwuDWH wIMuOxwtogjskoThJBLONXmjAg8ZsNx2nfeDgirOoVEjjhsRTENfpgJXwBbVaNqJOBN1 1kGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J62VD9CK7RpAgptmkAbcgEVIp9kjtSSQNRCoxzVMxBI=; b=ooJfcrUadjXXv1kJRCHQUkPlTWX1HVqhYgJq8nsMGkpwRkXDgadhGemCrhTobz1ize yhU653c8BPevisNvBTdbQfatW2NjyXnRKWupU/hSNjuKGZIZ97LhLI+nkkcl43GAEcbc CFO87KaCF+DEqKJKLJD7x8Yg6Q/zNGD+Ffp/pYw2ef0jzyTQjgZGIZrYJ24npf0lYeOW kpXop25VjD7HpOY2j17gMtIw/3+3Of+hyxjFUs6/MwGAycYRWdv/17s7XCOn7Ni/O0r8 5qf6bDLNe9rb/jsBsuSJof3UWZpdshzGCNTVgAnMJLGH0WCG1f6Sg8SL9m5BoSZlbkGL M1Ww== X-Gm-Message-State: AOAM53385KBOv58XKj3ppD18lj1xgKXM2aK/yfw6sJ71jS32vKBw5/4E 2BEDOckjs3fc8LvSNywYuFxLw9BPYZ2uMg== X-Google-Smtp-Source: ABdhPJwDh5/dAnNlAz2SZUhEzmuDZOL7ovfEY5XGQ0pa9Eju/CIJUIEWxKcJe9CHqd1xLugxQ1BkVQ== X-Received: by 2002:a05:600c:4f87:: with SMTP id n7mr44335656wmq.9.1625136695951; Thu, 01 Jul 2021 03:51:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p9sm8015699wmm.17.2021.07.01.03.51.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 03:51:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/5] dir.[ch]: replace dir_init() with DIR_INIT Date: Thu, 1 Jul 2021 12:51:27 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.632.g11c1df94a06 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Remove the dir_init() function and replace it with a DIR_INIT macro. In many cases in the codebase we need to initialize things with a function for good reasons, e.g. needing to call another function on initialization. The "dir_init()" function was not one such case, and could trivially be replaced with a more idiomatic macro initialization pattern. The only place where we made use of its use of memset() was in dir_clear() itself, which resets the contents of an an existing struct pointer. Let's use the new "memcpy() a 'blank' struct on the stack" idiom to do that reset. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/add.c | 3 +-- builtin/check-ignore.c | 3 +-- builtin/clean.c | 6 ++---- builtin/grep.c | 3 +-- builtin/ls-files.c | 3 +-- builtin/stash.c | 3 +-- dir.c | 9 ++------- dir.h | 4 ++-- merge.c | 3 +-- wt-status.c | 3 +-- 10 files changed, 13 insertions(+), 27 deletions(-) diff --git a/builtin/add.c b/builtin/add.c index b773b5a4993..09e684585d9 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -470,7 +470,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) { int exit_status = 0; struct pathspec pathspec; - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; int flags; int add_new_files; int require_pathspec; @@ -577,7 +577,6 @@ int cmd_add(int argc, const char **argv, const char *prefix) die_in_unpopulated_submodule(&the_index, prefix); die_path_inside_submodule(&the_index, &pathspec); - dir_init(&dir); if (add_new_files) { int baselen; diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 81234552b7f..21912569650 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -153,7 +153,7 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix) int cmd_check_ignore(int argc, const char **argv, const char *prefix) { int num_ignored; - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; git_config(git_default_config, NULL); @@ -182,7 +182,6 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix) if (!no_index && read_cache() < 0) die(_("index file corrupt")); - dir_init(&dir); setup_standard_excludes(&dir); if (stdin_paths) { diff --git a/builtin/clean.c b/builtin/clean.c index 4944cf440b4..98a2860409b 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -641,7 +641,7 @@ static int clean_cmd(void) static int filter_by_patterns_cmd(void) { - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; struct strbuf confirm = STRBUF_INIT; struct strbuf **ignore_list; struct string_list_item *item; @@ -665,7 +665,6 @@ static int filter_by_patterns_cmd(void) if (!confirm.len) break; - dir_init(&dir); pl = add_pattern_list(&dir, EXC_CMDL, "manual exclude"); ignore_list = strbuf_split_max(&confirm, ' ', 0); @@ -890,7 +889,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) int ignored_only = 0, config_set = 0, errors = 0, gone = 1; int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT; struct strbuf abs_path = STRBUF_INIT; - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; struct pathspec pathspec; struct strbuf buf = STRBUF_INIT; struct string_list exclude_list = STRING_LIST_INIT_NODUP; @@ -921,7 +920,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, builtin_clean_usage, 0); - dir_init(&dir); if (!interactive && !dry_run && !force) { if (config_set) die(_("clean.requireForce set to true and neither -i, -n, nor -f given; " diff --git a/builtin/grep.c b/builtin/grep.c index ab8822e68f4..7d2f8e5adb6 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -704,10 +704,9 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec, int exc_std, int use_index) { - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; int i, hit = 0; - dir_init(&dir); if (!use_index) dir.flags |= DIR_NO_GITLINKS; if (exc_std) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 45cc3b23dd6..29a26ad8ae4 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -608,7 +608,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) { int require_work_tree = 0, show_tag = 0, i; char *max_prefix; - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; struct pattern_list *pl; struct string_list exclude_list = STRING_LIST_INIT_NODUP; struct option builtin_ls_files_options[] = { @@ -678,7 +678,6 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(ls_files_usage, builtin_ls_files_options); - dir_init(&dir); prefix = cmd_prefix; if (prefix) prefix_len = strlen(prefix); diff --git a/builtin/stash.c b/builtin/stash.c index 9c72e4b1257..8f42360ca91 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -991,9 +991,8 @@ static int get_untracked_files(const struct pathspec *ps, int include_untracked, { int i; int found = 0; - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; - dir_init(&dir); if (include_untracked != INCLUDE_ALL_FILES) setup_standard_excludes(&dir); diff --git a/dir.c b/dir.c index ebe5ec046e0..313e9324597 100644 --- a/dir.c +++ b/dir.c @@ -53,12 +53,6 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, int check_only, int stop_at_first_file, const struct pathspec *pathspec); static int resolve_dtype(int dtype, struct index_state *istate, const char *path, int len); - -void dir_init(struct dir_struct *dir) -{ - memset(dir, 0, sizeof(*dir)); -} - struct dirent *readdir_skip_dot_and_dotdot(DIR *dirp) { struct dirent *e; @@ -3105,6 +3099,7 @@ void dir_clear(struct dir_struct *dir) struct exclude_list_group *group; struct pattern_list *pl; struct exclude_stack *stk; + struct dir_struct new = DIR_INIT; for (i = EXC_CMDL; i <= EXC_FILE; i++) { group = &dir->exclude_list_group[i]; @@ -3132,7 +3127,7 @@ void dir_clear(struct dir_struct *dir) } strbuf_release(&dir->basebuf); - dir_init(dir); + memcpy(dir, &new, sizeof(*dir)); } struct ondisk_untracked_cache { diff --git a/dir.h b/dir.h index e3db9b9ec65..8d0ddd8f18d 100644 --- a/dir.h +++ b/dir.h @@ -342,6 +342,8 @@ struct dir_struct { unsigned visited_directories; }; +#define DIR_INIT { 0 } + struct dirent *readdir_skip_dot_and_dotdot(DIR *dirp); /*Count the number of slashes for string s*/ @@ -367,8 +369,6 @@ int match_pathspec(struct index_state *istate, int report_path_error(const char *ps_matched, const struct pathspec *pathspec); int within_depth(const char *name, int namelen, int depth, int max_depth); -void dir_init(struct dir_struct *dir); - int fill_directory(struct dir_struct *dir, struct index_state *istate, const struct pathspec *pathspec); diff --git a/merge.c b/merge.c index 5fb88af1025..6e736881d90 100644 --- a/merge.c +++ b/merge.c @@ -53,7 +53,7 @@ int checkout_fast_forward(struct repository *r, struct unpack_trees_options opts; struct tree_desc t[MAX_UNPACK_TREES]; int i, nr_trees = 0; - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; struct lock_file lock_file = LOCK_INIT; refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL); @@ -80,7 +80,6 @@ int checkout_fast_forward(struct repository *r, } memset(&opts, 0, sizeof(opts)); - dir_init(&dir); if (overwrite_ignore) { dir.flags |= DIR_SHOW_IGNORED; setup_standard_excludes(&dir); diff --git a/wt-status.c b/wt-status.c index 42b67357169..b5a3e1cc252 100644 --- a/wt-status.c +++ b/wt-status.c @@ -699,14 +699,13 @@ static void wt_status_collect_changes_initial(struct wt_status *s) static void wt_status_collect_untracked(struct wt_status *s) { int i; - struct dir_struct dir; + struct dir_struct dir = DIR_INIT; uint64_t t_begin = getnanotime(); struct index_state *istate = s->repo->index; if (!s->show_untracked_files) return; - dir_init(&dir); if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES) dir.flags |= DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; From patchwork Thu Jul 1 10:51:28 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: 12353939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 16B21C11F6B for ; Thu, 1 Jul 2021 10:51:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00FBE6140A for ; Thu, 1 Jul 2021 10:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236110AbhGAKyM (ORCPT ); Thu, 1 Jul 2021 06:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236015AbhGAKyJ (ORCPT ); Thu, 1 Jul 2021 06:54:09 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79A01C061756 for ; Thu, 1 Jul 2021 03:51:38 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id a13so7585380wrf.10 for ; Thu, 01 Jul 2021 03:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dTLISbf6p2pNma+2eMCuKpqmOS9y3FqEfNvVCqHWFSk=; b=Oau1qkm3EcA2+jvQAankOQv4fpRCKPdIKF04s1/NDgJyB1FBQCawDoCdQ/jpGdN2hK LhDn4In0KAaV73W0cwVvX4XNSktFGipnEq7MNccyfg+8Uvj2YPj96WBUWCbW+09OE8w6 LrSFzaQY3qDWdxtVxC2RgMdXuHcYc3B7N8oxqxLT8PubDOafYeQfXwr73bE/0z728mYM gN36KJjzxo18Qv8sPsSgwjlSPB1SYuTnGCSeguIsYb5Bw07yzvrNblWP7yCxagIAIjo7 olO1RregF+RusVNBnaaGGxZ9SKpvpf1lSVWeNGZZnl/4qBA7PnmGClcXCoRp4bTfG+oH Yp8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dTLISbf6p2pNma+2eMCuKpqmOS9y3FqEfNvVCqHWFSk=; b=DpsNP6r53YRuNZUKDNNh4FqEeZLtBgSRKtULdTvKNtR9x8GDQNGkWfBFmslSJzOiPQ wR//+RPXdBDttiBT61feSVtXnSbEMK+14dIWt04Ujf5VIjZLi9vhmZRDaypbVpOpPQAg /qb6L6Ma6DfWulSkvYmNmSlzRV+dMjpbRd+D7ved721T9r7hR5PzOEw2MtRxEyHrFfPw AZQmIWMnKUIT+/3KuLmVJm53ENNoelGNLPcHRyiOMiBpKGADmVwXE4bqBdPv8MBY4Ivs TbsQJOBHaaqPrtTmV6+D3E1I0MaAcj77Wx41Jn8+qTLzoEOJrFthMnxDKhuaICTFu1eD qNsg== X-Gm-Message-State: AOAM530ql924DDq4RpwcBT8XKXrfKfJEUf7LTGIoTDRvrnwU6P4mTQzG TN9uPl+yio7B2nqmgfV8/5Q5AvHDvJN4/w== X-Google-Smtp-Source: ABdhPJww8vjybrrGOYvQ5RvLyY1osy2T7sGjipVDfq+37XxlXXxdbL++/8H3GzmeJDmryAOwcPmFbQ== X-Received: by 2002:adf:f946:: with SMTP id q6mr43984137wrr.283.1625136696661; Thu, 01 Jul 2021 03:51:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p9sm8015699wmm.17.2021.07.01.03.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 03:51:36 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 4/5] string-list.[ch]: add a string_list_init_{nodup,dup}() Date: Thu, 1 Jul 2021 12:51:28 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.632.g11c1df94a06 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In order to use the new "memcpy() a 'blank' struct on the stack" pattern for string_list_init(), and to make the macro initialization consistent with the function initialization introduce two new string_list_init_{nodup,dup}() functions. These are like the old string_list_init() when called with a false and true second argument, respectively. I think this not only makes things more consistent, but also easier to read. I often had to lookup what the ", 0)" or ", 1)" in these invocations meant, now it's right there in the function name, and corresponds to the macros. A subsequent commit will convert existing API users to this pattern, but as this is a very common API let's leave a compatibility function in place for later removal. This intermediate state also proves that the compatibility function works. Signed-off-by: Ævar Arnfjörð Bjarmason --- string-list.c | 18 ++++++++++++++++-- string-list.h | 11 +++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/string-list.c b/string-list.c index a917955fbd8..43576ad1265 100644 --- a/string-list.c +++ b/string-list.c @@ -1,10 +1,24 @@ #include "cache.h" #include "string-list.h" +void string_list_init_nodup(struct string_list *list) +{ + struct string_list blank = STRING_LIST_INIT_NODUP; + memcpy(list, &blank, sizeof(*list)); +} + +void string_list_init_dup(struct string_list *list) +{ + struct string_list blank = STRING_LIST_INIT_DUP; + memcpy(list, &blank, sizeof(*list)); +} + void string_list_init(struct string_list *list, int strdup_strings) { - memset(list, 0, sizeof(*list)); - list->strdup_strings = strdup_strings; + if (strdup_strings) + string_list_init_dup(list); + else + string_list_init_nodup(list); } /* if there is no exact match, point to the index where the entry could be diff --git a/string-list.h b/string-list.h index 521b9c0748d..0d6b4692396 100644 --- a/string-list.h +++ b/string-list.h @@ -97,8 +97,15 @@ struct string_list { /* General functions which work with both sorted and unsorted lists. */ /** - * Initialize the members of the string_list, set `strdup_strings` - * member according to the value of the second parameter. + * Initialize the members of a string_list pointer in the same way as + * the corresponding `STRING_LIST_INIT_NODUP` and + * `STRING_LIST_INIT_DUP` macros. + */ +void string_list_init_nodup(struct string_list *list); +void string_list_init_dup(struct string_list *list); + +/** + * TODO remove: For compatibility with any in-flight older API users */ void string_list_init(struct string_list *list, int strdup_strings); From patchwork Thu Jul 1 10:51:29 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: 12353937 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F925C11F6A for ; Thu, 1 Jul 2021 10:51:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 658616147D for ; Thu, 1 Jul 2021 10:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236098AbhGAKyK (ORCPT ); Thu, 1 Jul 2021 06:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236075AbhGAKyJ (ORCPT ); Thu, 1 Jul 2021 06:54:09 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2E42C0617A8 for ; Thu, 1 Jul 2021 03:51:38 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id r3so4202846wmq.1 for ; Thu, 01 Jul 2021 03:51:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ThP9Pez1hmbWoAaUrC+2tCNmSKRaBB9cDWMlDQkRvoI=; b=SNMIdYo6MdqHDDHPF/KKOEoL/IMLSaNvN33ZwQZPkLM/AFx53gocat4rYxJIBSOSh6 +VwOA7IfjhsHzkOnNHSPPjzDgiGpsJPm1T2oQvZwuIFV1oGDYkCSruT1WWfxrCxgtztH +4yxf+C0/eZCNc/wAAL47Oz67XpoaKYiofXXPZhCur2laYqPEBxcjhwZRHeR+bmQiGKs 0LNINHY+IKv1jZWeCjeFMnX5drvbjGhB4+J8aKUkYj1m0SIjhaVFoOlMNY8sBwoGeYNB o0CX35XIqu5GM9jeb5MVU4Njt5jJBcgNM+k0wsooutTpLPHmLhRmTNZyb40b6ncs9Zt1 KJTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ThP9Pez1hmbWoAaUrC+2tCNmSKRaBB9cDWMlDQkRvoI=; b=pU1LOYpWxRIIcqwepvNixnomRy63a9xr3VK7on/D8FfdBeuENrk4BtvixQsliHR4ec FEZIsmqLnwSJnLXBFfJNscVXFv6CNu27d4BJVZ1VJPj+my2S06nvHcBJWIKfPVZjN7g6 viiFONtXQC4s3lN0wKyDTMkGXAQWr8QKK7cKDZrHWzAiLusCZf1LNCg6ZnMkFNM3ujnN LsZQ6d8riGlDGYW00gHoP6LSaYTLuPq2gB87M9Ts8vlItIjKwqnkfeEvTjhusdfcS30Z +93kFJLnm5qelp5FicjqiSc0UeaT90t3UylJOFT7cDFvYw5mBl7N5B+hGdErnoCMxyfC 3Nfw== X-Gm-Message-State: AOAM5339ZFKVmTO+4L/8cZsQUyHfWp0bn1YS83lYer6fH87AhtLglLOX RoSZeJ4RvsUix2sYwtGwdv8MhhrxHGpkMA== X-Google-Smtp-Source: ABdhPJyXE2bDvjFOlDWolds63xymbbsJMP+h17FHj0fT7bRLbDiw5FkMRA/SB8zSxa9Oio4vkKcygA== X-Received: by 2002:a7b:cb1a:: with SMTP id u26mr9989542wmj.125.1625136697354; Thu, 01 Jul 2021 03:51:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id p9sm8015699wmm.17.2021.07.01.03.51.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jul 2021 03:51:36 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 5/5] string-list.h users: change to use *_{nodup,dup}() Date: Thu, 1 Jul 2021 12:51:29 +0200 Message-Id: X-Mailer: git-send-email 2.32.0.632.g11c1df94a06 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change all in-tree users of the string_list_init(LIST, BOOL) API to use string_list_init_{nodup,dup}(LIST) instead. As noted in the preceding commit let's leave the now-unused string_list_init() wrapper in-place for any in-flight users, it can be removed at some later date. Signed-off-by: Ævar Arnfjörð Bjarmason --- apply.c | 6 +++--- archive.c | 2 +- config.c | 2 +- entry.c | 4 ++-- merge-ort.c | 4 ++-- merge-recursive.c | 4 ++-- refs/packed-backend.c | 2 +- transport.c | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apply.c b/apply.c index 853d3ed385a..44bc31d6eb5 100644 --- a/apply.c +++ b/apply.c @@ -101,9 +101,9 @@ int init_apply_state(struct apply_state *state, state->ws_error_action = warn_on_ws_error; state->ws_ignore_action = ignore_ws_none; state->linenr = 1; - string_list_init(&state->fn_table, 0); - string_list_init(&state->limit_by_name, 0); - string_list_init(&state->symlink_changes, 0); + string_list_init_nodup(&state->fn_table); + string_list_init_nodup(&state->limit_by_name); + string_list_init_nodup(&state->symlink_changes); strbuf_init(&state->root, 0); git_apply_config(); diff --git a/archive.c b/archive.c index ff2bb54f622..3c266d1d7bf 100644 --- a/archive.c +++ b/archive.c @@ -645,7 +645,7 @@ int write_archive(int argc, const char **argv, const char *prefix, args.pretty_ctx = &ctx; args.repo = repo; args.prefix = prefix; - string_list_init(&args.extra_files, 1); + string_list_init_dup(&args.extra_files); argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote); if (!startup_info->have_repository) { /* diff --git a/config.c b/config.c index f9c400ad306..2edb282b43d 100644 --- a/config.c +++ b/config.c @@ -2072,7 +2072,7 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha e = xmalloc(sizeof(*e)); hashmap_entry_init(&e->ent, strhash(key)); e->key = xstrdup(key); - string_list_init(&e->value_list, 1); + string_list_init_dup(&e->value_list); hashmap_add(&cs->config_hash, &e->ent); } si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value)); diff --git a/entry.c b/entry.c index 711ee0693c7..125fabdbd52 100644 --- a/entry.c +++ b/entry.c @@ -143,8 +143,8 @@ void enable_delayed_checkout(struct checkout *state) if (!state->delayed_checkout) { state->delayed_checkout = xmalloc(sizeof(*state->delayed_checkout)); state->delayed_checkout->state = CE_CAN_DELAY; - string_list_init(&state->delayed_checkout->filters, 0); - string_list_init(&state->delayed_checkout->paths, 0); + string_list_init_nodup(&state->delayed_checkout->filters); + string_list_init_nodup(&state->delayed_checkout->paths); } } diff --git a/merge-ort.c b/merge-ort.c index b954f7184a5..d7ae8d0558f 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -1836,7 +1836,7 @@ static void compute_collisions(struct strmap *collisions, free(new_path); } else { CALLOC_ARRAY(collision_info, 1); - string_list_init(&collision_info->source_files, 0); + string_list_init_nodup(&collision_info->source_files); strmap_put(collisions, new_path, collision_info); } string_list_insert(&collision_info->source_files, @@ -3942,7 +3942,7 @@ static void merge_start(struct merge_options *opt, struct merge_result *result) */ strmap_init_with_options(&opt->priv->paths, NULL, 0); strmap_init_with_options(&opt->priv->conflicted, NULL, 0); - string_list_init(&opt->priv->paths_to_free, 0); + string_list_init_nodup(&opt->priv->paths_to_free); /* * keys & strbufs in output will sometimes need to outlive "paths", diff --git a/merge-recursive.c b/merge-recursive.c index d146bb116f7..be473f854be 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -121,7 +121,7 @@ static void dir_rename_entry_init(struct dir_rename_entry *entry, entry->dir = directory; entry->non_unique_new_dir = 0; strbuf_init(&entry->new_dir, 0); - string_list_init(&entry->possible_new_dirs, 0); + string_list_init_nodup(&entry->possible_new_dirs); } struct collision_entry { @@ -3703,7 +3703,7 @@ static int merge_start(struct merge_options *opt, struct tree *head) } CALLOC_ARRAY(opt->priv, 1); - string_list_init(&opt->priv->df_conflict_file_set, 1); + string_list_init_dup(&opt->priv->df_conflict_file_set); return 0; } diff --git a/refs/packed-backend.c b/refs/packed-backend.c index dfecdbc1db6..5f50def076c 100644 --- a/refs/packed-backend.c +++ b/refs/packed-backend.c @@ -1425,7 +1425,7 @@ static int packed_transaction_prepare(struct ref_store *ref_store, */ CALLOC_ARRAY(data, 1); - string_list_init(&data->updates, 0); + string_list_init_nodup(&data->updates); transaction->backend_data = data; diff --git a/transport.c b/transport.c index 50f5830eb6b..25f77ce6ab2 100644 --- a/transport.c +++ b/transport.c @@ -1052,7 +1052,7 @@ struct transport *transport_get(struct remote *remote, const char *url) struct transport *ret = xcalloc(1, sizeof(*ret)); ret->progress = isatty(2); - string_list_init(&ret->pack_lockfiles, 1); + string_list_init_dup(&ret->pack_lockfiles); if (!remote) BUG("No remote provided to transport_get()");