From patchwork Sun Sep 19 08:47: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: 12504247 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.7 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,URIBL_BLOCKED,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 68C4EC433F5 for ; Sun, 19 Sep 2021 08:47:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 468CB611C8 for ; Sun, 19 Sep 2021 08:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237084AbhISIst (ORCPT ); Sun, 19 Sep 2021 04:48:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237067AbhISIss (ORCPT ); Sun, 19 Sep 2021 04:48:48 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED99C061574 for ; Sun, 19 Sep 2021 01:47:23 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id a194-20020a1c98cb000000b0030b41ac389fso5152853wme.2 for ; Sun, 19 Sep 2021 01:47:23 -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=tBRv2Wd7MFvbmedcRMPTTnl++Ea0U8Yv5UhhZajFYVo=; b=EvIaU39854ad7QuvHksLIrBnqMf4x28SUeIoagftrz6qS8H9l7CQbirENo9HYG5GlZ jYa7vflSE1X4IcIfgVL/XJrIHg8yyKlUfsSsocvTNHIVRwPFlh8Zk0DSnJlvnip2wEuW 4+nA/LTHAg8xFvB5DG0SNnu+HfvRkGJXrzTUP0Kr0uF0WZ1OkrWrmeNfR2C1bpI0dUfu iD2w/jh/vZqKWVM2cOfnpVGGF0xt05LadBaSFiHLebB/40xZGGnVbO/hTU5sfsFROz8f 6Q8NTh3zliIOaVhW5rqaO0s0eCODuG4jW7zJ0W7AwEfmJmKnMom8l3PP+napixJlYiZq c3pg== 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=tBRv2Wd7MFvbmedcRMPTTnl++Ea0U8Yv5UhhZajFYVo=; b=1PFaf25KqX4V4FTySX63HV5CsVAYs1+w9tzMZrBg8P4ZVNUbADSrPzwM8TsjkJ+iRi isUQwPqNGfAAckEkt0FbSpAwAaWFo83C/0IM9SEp5l2riRBZidGxqThtvr/z/tCyclGq dF/fH0uql6pmn2areTWBDjj5JB9KWX+wM5O7VP3gRcUXByyECku+YNJEZ0t+SwRqVhfk XHBy7LlRI1WGP4opztsaN+KO7VPMY5SKWDP07arN12rj87iyvldNmUm070zg7oFUT+SA c3Ybky3CDQF29obnCCNLtPPo8rAh814uIdFaZGuzFlIcsmZPUMq+F3vaTJBdHR39iwHX Oxbg== X-Gm-Message-State: AOAM533EedRYoAosByp5i9NHC2nptO8picUmUgYyYZBjY0B2Yjpk4W4q qWhfJ2PXfEkRZcZ4TFTiyLzehWFFsyeQmQ== X-Google-Smtp-Source: ABdhPJx40JXdyx/NRyS3y1R3Rg/SnnewFVB6thkePd3Ha4sgEVzjOLUR5DQFxko7FKmmBb1pTaRoHA== X-Received: by 2002:a7b:c414:: with SMTP id k20mr18694481wmi.146.1632041242195; Sun, 19 Sep 2021 01:47:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i67sm7884497wmi.41.2021.09.19.01.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 01:47:21 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 1/5] wrapper.c: add x{un,}setenv(), and use xsetenv() in environment.c Date: Sun, 19 Sep 2021 10:47:15 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1092.g44c994ea1be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add fatal wrappers for setenv() and unsetenv(). In d7ac12b25d3 (Add set_git_dir() function, 2007-08-01) we started checking its return value, and since 48988c4d0c3 (set_git_dir: die when setenv() fails, 2018-03-30) we've had set_git_dir_1() die if we couldn't set it. Let's provide a wrapper for both, this will be useful in many other places, a subsequent patch will make another use of xsetenv(). The checking of the return value here is over-eager according to setenv(3) and POSIX. It's documented as returning just -1 or 0, so perhaps we should be checking -1 explicitly. Let's just instead die on any non-zero, if our C library is so broken as to return something else than -1 on error (and perhaps not set errno?) the worst we'll do is die with a nonsensical errno value, but we'll want to die in either case. We could make these return "void" (as far as I can tell there's no other x*() wrappers that needed to make that decision before), i.e. our "return 0" is only to indicate that we didn't error, which we would have died on. Let's return "int" instead to be consistent with the C library function signatures, including for any future code that expects a pointer to a setenv()-like function. I think it would be OK skip the NULL check of the "name" here for the calls to die_errno(). Almost all of our setenv() callers are taking a constant string hardcoded in the source as the first argument, and for the rest we can probably assume they've done the NULL check themselves. Even if they didn't, modern C libraries are forgiving about it (e.g. glibc formatting it as "(null)"), on those that aren't, well, we were about to die anyway. But let's include the check anyway for good measure. 1. https://pubs.opengroup.org/onlinepubs/009604499/functions/setenv.html Signed-off-by: Ævar Arnfjörð Bjarmason --- environment.c | 3 +-- git-compat-util.h | 2 ++ wrapper.c | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/environment.c b/environment.c index d6b22ede7ea..7d8a949285c 100644 --- a/environment.c +++ b/environment.c @@ -330,8 +330,7 @@ char *get_graft_file(struct repository *r) static void set_git_dir_1(const char *path) { - if (setenv(GIT_DIR_ENVIRONMENT, path, 1)) - die(_("could not set GIT_DIR to '%s'"), path); + xsetenv(GIT_DIR_ENVIRONMENT, path, 1); setup_git_env(path); } diff --git a/git-compat-util.h b/git-compat-util.h index b46605300ab..0b0c0305165 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -875,6 +875,8 @@ void *xmemdupz(const void *data, size_t len); char *xstrndup(const char *str, size_t len); void *xrealloc(void *ptr, size_t size); void *xcalloc(size_t nmemb, size_t size); +int xsetenv(const char *name, const char *value, int overwrite); +int xunsetenv(const char *name); void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); const char *mmap_os_err(void); void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset); diff --git a/wrapper.c b/wrapper.c index 7c6586af321..95f989260cd 100644 --- a/wrapper.c +++ b/wrapper.c @@ -145,6 +145,21 @@ void *xcalloc(size_t nmemb, size_t size) return ret; } +int xsetenv(const char *name, const char *value, int overwrite) +{ + if (setenv(name, value, overwrite)) + die_errno("setenv(%s, '%s', %d) failed", name ? name : "(null)", + value, overwrite); + return 0; +} + +int xunsetenv(const char *name) +{ + if (!unsetenv(name)) + die_errno("unsetenv(%s) failed", name ? name : "(null)"); + return 0; +} + /* * Limit size of IO chunks, because huge chunks only cause pain. OS X * 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in From patchwork Sun Sep 19 08:47: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: 12504245 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.7 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 7BC96C433EF for ; Sun, 19 Sep 2021 08:47:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54D05611C3 for ; Sun, 19 Sep 2021 08:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237120AbhISIsw (ORCPT ); Sun, 19 Sep 2021 04:48:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237067AbhISIsu (ORCPT ); Sun, 19 Sep 2021 04:48:50 -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 DA847C061574 for ; Sun, 19 Sep 2021 01:47:24 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id u18so21209020wrg.5 for ; Sun, 19 Sep 2021 01:47: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=dIAOOKqV80LUBbkULEqtI0O3L2Wh0rj6xzKUtZXAEIg=; b=aIcFTSNRxLCJcpYJPFJZARWzMeYKDf0vyva4kjhFHNzIj1tABKm3B6DT4l8J2E3skK sTWo8nfoj20y6HTTGxutCN0S1n9KZvpbZu5z2j0IR0y4RF1OhLeNQcF34nFe6swg/2im gb3hPrePEKHi73fj69tLfwNiEtoJDR81jabbta7weGXoLun9AGo2LraZb8BcanStCRpJ 29acEY7CkQ5+EskZ3wvupfkBaIjOoMPd3YskFYZmbNlR9QNshOub8GBDq4hyhCWH14gj WM+de1VOy4ONjvacLSjt4EB/YEVyjvAWGFvZzYZo2Fk20/ZC+rsgFRbLzz1hUEHjFoJi xSRA== 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=dIAOOKqV80LUBbkULEqtI0O3L2Wh0rj6xzKUtZXAEIg=; b=f3XWuV7RmoOJk8EQG7gIs+L4PDwLvz8Fv6K7jIrZQTa2WjAVbe/ZVsnP6WNS08BkjO PGM2yYLDdU/QS5DQARGCuE1+w8aGCGqKCIVfkDl7i1YwRWAVhfERY7VxNCa42133adH+ pbIoUPUo/Mw9/pN4NlcbaBfSJgdPkm5gKoSiEmX0hinYZCfFxVl2kViJW3uzxYA3Hfpw fQt170sK+GJV71RUy05dREHZwjSuV8FT4rxE8re1ykoEQEp5gkxXqO6072VKPriSM15N 1tTHTWcgzULBXBEGVOSdu/c3BzVJjWfU/I3k/ZLCQpStmCZEbj1kkKuu5Taph1aiAb18 yjQg== X-Gm-Message-State: AOAM532jUOCqUYWwsaSFEOf/DrCP7cVuyrYIxSoqnQ2eWII3jCwde54F prsCvDyjbl+TLMRk0SWEeDt09LWIBTOLNg== X-Google-Smtp-Source: ABdhPJxgQ5brG4CgeojWvbEPNTYYobYIfF9P9aLLPi1uXgarKP/E7pU4cwOHYgfgGolJ+H+fl93p7g== X-Received: by 2002:adf:e390:: with SMTP id e16mr21753579wrm.217.1632041243113; Sun, 19 Sep 2021 01:47:23 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i67sm7884497wmi.41.2021.09.19.01.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 01:47:22 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 2/5] environment.c: remove test-specific "ignore_untracked..." variable Date: Sun, 19 Sep 2021 10:47:16 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1092.g44c994ea1be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Instead of the global ignore_untracked_cache_config variable added in dae6c322fa1 (test-dump-untracked-cache: don't modify the untracked cache, 2016-01-27) we can make use of the new facility to set config via environment variables added in d8d77153eaf (config: allow specifying config entries via envvar pairs, 2021-01-12). It's arguably a bit hacky to use setenv() and getenv() to pass messages between the same program, but since the test helpers are not the main intended audience of repo-settings.c I think it's better than hardcoding the test-only special-case in prepare_repo_settings(). This uses the xsetenv() wrapper added in the preceding commit, if we don't set these in the environment we'll fail in t7063-status-untracked-cache.sh, but let's fail earlier anyway if that were to happen. This breaks any parent process that's potentially using the GIT_CONFIG_* and GIT_CONFIG_PARAMETERS mechanism to pass one-shot config setting down to a git subprocess, but in this case we don't care about the general case of such potential parents. This process neither spawns other "git" processes, nor is it interested in other configuration. We might want to pick up other test modes here, but those will be passed via GIT_TEST_* environment variables. Signed-off-by: Ævar Arnfjörð Bjarmason --- cache.h | 7 ------- environment.c | 7 ------- repo-settings.c | 7 +------ t/helper/test-dump-untracked-cache.c | 6 ++++-- 4 files changed, 5 insertions(+), 22 deletions(-) diff --git a/cache.h b/cache.h index d23de693680..8e60fdd2a12 100644 --- a/cache.h +++ b/cache.h @@ -1719,13 +1719,6 @@ int update_server_info(int); const char *get_log_output_encoding(void); const char *get_commit_output_encoding(void); -/* - * This is a hack for test programs like test-dump-untracked-cache to - * ensure that they do not modify the untracked cache when reading it. - * Do not use it otherwise! - */ -extern int ignore_untracked_cache_config; - int committer_ident_sufficiently_given(void); int author_ident_sufficiently_given(void); diff --git a/environment.c b/environment.c index 7d8a949285c..d73dd0c42f7 100644 --- a/environment.c +++ b/environment.c @@ -96,13 +96,6 @@ int auto_comment_line_char; /* Parallel index stat data preload? */ int core_preload_index = 1; -/* - * This is a hack for test programs like test-dump-untracked-cache to - * ensure that they do not modify the untracked cache when reading it. - * Do not use it otherwise! - */ -int ignore_untracked_cache_config; - /* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg; diff --git a/repo-settings.c b/repo-settings.c index 0cfe8b787db..b0df8b93b86 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -70,12 +70,7 @@ void prepare_repo_settings(struct repository *r) if (!repo_config_get_bool(r, "feature.experimental", &value) && value) UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_SKIPPING); - /* Hack for test programs like test-dump-untracked-cache */ - if (ignore_untracked_cache_config) - r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP; - else - UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP); - + UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP); UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_DEFAULT); /* diff --git a/t/helper/test-dump-untracked-cache.c b/t/helper/test-dump-untracked-cache.c index cf0f2c7228e..99010614f6d 100644 --- a/t/helper/test-dump-untracked-cache.c +++ b/t/helper/test-dump-untracked-cache.c @@ -45,8 +45,10 @@ int cmd__dump_untracked_cache(int ac, const char **av) struct untracked_cache *uc; struct strbuf base = STRBUF_INIT; - /* Hack to avoid modifying the untracked cache when we read it */ - ignore_untracked_cache_config = 1; + /* Set core.untrackedCache=keep before setup_git_directory() */ + xsetenv("GIT_CONFIG_COUNT", "1", 1); + xsetenv("GIT_CONFIG_KEY_0", "core.untrackedCache", 1); + xsetenv("GIT_CONFIG_VALUE_0", "keep", 1); setup_git_directory(); if (read_cache() < 0) From patchwork Sun Sep 19 08:47: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: 12504249 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.7 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 998F4C4332F for ; Sun, 19 Sep 2021 08:47:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DABE61212 for ; Sun, 19 Sep 2021 08:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237198AbhISIsy (ORCPT ); Sun, 19 Sep 2021 04:48:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237085AbhISIsu (ORCPT ); Sun, 19 Sep 2021 04:48:50 -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 B9F6DC061574 for ; Sun, 19 Sep 2021 01:47:25 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id z184-20020a1c7ec1000000b003065f0bc631so13293233wmc.0 for ; Sun, 19 Sep 2021 01:47: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=mM3Z+oAJuUsvBxBGmGKvCeF23cGlFiPbMicsHB83nM8=; b=nT5KgkuTmmh2CzyLaxUCEhgTVCkHQEEZ4XdNCwsgC49FfZlxRPxjdQjbmaj9nCZyA+ TrlzKJAZCuuLcVpAEg8oUJsVizutAHfGxqLt1FLYyAxVamKXZu6LJMN4k9wrd4RW47ft mm4Avht4DnWMsXbfzumymE4fAnonPX/JNoNlXTYxHN7h0d/B+NIheYcl5es+r8ed1+0G KtmtNhX+bo+VVd7yZrKpCC7KdNlu9w51noUvyYP/tBeC6Hul5KfbZ7x5UwvLphNBzM+G SLEo5+GWob/8FLdLN/wCQEtp2QkmEgKsMW28heEG/OrWNlr8hbKf5o4HL3qRzmOVn5LM Mmsw== 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=mM3Z+oAJuUsvBxBGmGKvCeF23cGlFiPbMicsHB83nM8=; b=lh6GD02arQ8U576e/QH8l6X8GTdCfWgtEx0jN3DaLYL8xzpzECwpHbLhFTYB+Btf1N SZca5zM7r/L18q3Tu3xktm3E7CvioEzZ14Ry74nYYZHKu7yVweUpBtJ4RZO0qzsoWB/5 RB96s8jHTfswXEROUniNmZqgsLuwLH10LLwoV0wkc7AW5mdby/nrwAuuGO3ZvTDNvmCZ qrfK2v8AyeMjpulO3IRBi2Uj1+//OfstCpGveL9zupp3o62phnqaW8OKLArtpYYoy+d9 7vCaJ5pNS6OM81V1iJAyPdVnYQB5SJiFyLBTSf1d+jaJR2mkclIUBeitefNAAL+0t4W4 AUwg== X-Gm-Message-State: AOAM531ZDgu3tz2r/OBsJ81gkwL0Url/T88koSOo4pVXR2IIyoK8tOsx m8f98FJ3mw4dQ4QWoip71EIa1dUBMkXEEQ== X-Google-Smtp-Source: ABdhPJwzNgCUGu566XMuYfZQJgejbjt6rw1+MnH5pCwgvf3P31J4gTnocOjqC3Db+CVd6RLR0hE5HQ== X-Received: by 2002:a05:600c:211a:: with SMTP id u26mr23815813wml.190.1632041244116; Sun, 19 Sep 2021 01:47:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i67sm7884497wmi.41.2021.09.19.01.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 01:47:23 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 3/5] read-cache & fetch-negotiator: check "enum" values in switch() Date: Sun, 19 Sep 2021 10:47:17 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1092.g44c994ea1be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change tweak_untracked_cache() in "read-cache.c" to use a switch() to have the compiler assert that we checked all possible values in the "enum untracked_cache_setting" type, and likewise remove the "default" case in fetch_negotiator_init() in favor of checking for "FETCH_NEGOTIATION_UNSET" and "FETCH_NEGOTIATION_NONE". As will be discussed in a subsequent we'll only ever have either of these set to FETCH_NEGOTIATION_NONE, FETCH_NEGOTIATION_UNSET and UNTRACKED_CACHE_UNSET within the prepare_repo_settings() function itself. In preparation for fixing that code let's add a BUG() here to mark this as unreachable code. See ad0fb659993 (repo-settings: parse core.untrackedCache, 2019-08-13) for when the "unset" and "keep" handling for core.untrackedCache was consolidated, and aaf633c2ad1 (repo-settings: create feature.experimental setting, 2019-08-13) for the addition of the "default" pattern in "fetch-negotiator.c". Signed-off-by: Ævar Arnfjörð Bjarmason --- fetch-negotiator.c | 4 +++- read-cache.c | 15 ++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fetch-negotiator.c b/fetch-negotiator.c index 57ed5784e14..237f92b8696 100644 --- a/fetch-negotiator.c +++ b/fetch-negotiator.c @@ -19,8 +19,10 @@ void fetch_negotiator_init(struct repository *r, return; case FETCH_NEGOTIATION_DEFAULT: - default: default_negotiator_init(negotiator); return; + case FETCH_NEGOTIATION_NONE: + case FETCH_NEGOTIATION_UNSET: + BUG("FETCH_NEGOTIATION_UNSET only in prepare_repo_settings()"); } } diff --git a/read-cache.c b/read-cache.c index 9048ef9e905..6918dc3d8b2 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1944,13 +1944,18 @@ static void tweak_untracked_cache(struct index_state *istate) prepare_repo_settings(r); - if (r->settings.core_untracked_cache == UNTRACKED_CACHE_REMOVE) { + switch (r->settings.core_untracked_cache) { + case UNTRACKED_CACHE_REMOVE: remove_untracked_cache(istate); - return; - } - - if (r->settings.core_untracked_cache == UNTRACKED_CACHE_WRITE) + break; + case UNTRACKED_CACHE_WRITE: add_untracked_cache(istate); + break; + case UNTRACKED_CACHE_KEEP: + break; + case UNTRACKED_CACHE_UNSET: + BUG("UNTRACKED_CACHE_UNSET only in prepare_repo_settings()"); + } } static void tweak_split_index(struct index_state *istate) From patchwork Sun Sep 19 08:47: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: 12504253 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.7 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 786FCC433EF for ; Sun, 19 Sep 2021 08:47:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62CC761268 for ; Sun, 19 Sep 2021 08:47:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237158AbhISIs5 (ORCPT ); Sun, 19 Sep 2021 04:48:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237133AbhISIsw (ORCPT ); Sun, 19 Sep 2021 04:48:52 -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 84325C061764 for ; Sun, 19 Sep 2021 01:47:27 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id q11so22937791wrr.9 for ; Sun, 19 Sep 2021 01:47: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=EWfDZ+rtrnG21Skj48lW5WkTkD3Y1oEspdbO9ufkms0=; b=jGLyXhkyT5bnkcY1PxRHyqmSUT408/9Cb83h3pZDIBgpr8JQ+CYQ9l8D7Mn3sR/CUT tBIViyWWRXatWN+IZZORhNPfhqPxwTCSsCQRm8bPwhoFEy7vhl0AkQBn3QpOMle9H1AA Jp7oorVkT+/2q/za0b22cta6M9m8wZL1Ajxk3D2g4ie3wHNHYkPxactMEgyL37Jv9iE5 Keh4/5cGAZgXX0Gk0JmqNyaBVLkgQcSK5xCIjb2jSCyIS8iy/tr2atdp6A6zBRk+1Ga8 BAQM1ZWdEXlvk9KIpjq+Be1ALekuMmum/mGpdlJYGchW+o/6/gfaGvso8C7szXuqmt69 ppKw== 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=EWfDZ+rtrnG21Skj48lW5WkTkD3Y1oEspdbO9ufkms0=; b=uwiihva7N0GJ4XrLNpRjf/86QqUf1lFlFG8DqGZZKCkhpPiE56q6Rt8ztgC04C701/ 016WOZSXFbqPqDXd/8bih1PmxHACma2v8cdrR/PO1rik0gaKAFuDVtnjF9FHL7RqDKlc scQ3eJsr3RDLDvivzlO7lrN+q8lqlWZOgzDSj6a2QdtxZblwZNOH9e979l2jhKjfF9LV Au96pKleqv7/34iwrNgvmD3AE/VubjICdTlfCcGvvthYQ85OpoLypz/R4M1IZhxo5pn8 d3onh9B7IwiAoELrf4fLZjDK71blvCVlbUIL9a25jG1h9KwDNoS78yNBmQcS2QsQnyDl vnCg== X-Gm-Message-State: AOAM531ShdrgERHR6/Uq1uJeNwm1rR2bDKIW0I0MOVRAFl7p1aj9WCJ+ UXHdwpZo97pZJgupdLgQnFOQkglLgZvQng== X-Google-Smtp-Source: ABdhPJw9XJr6SDBWC40ZxAS4yS+VSfWyuGGzYAxDc5E78fuRbPmdrEfa18Rv+/EwdAm5Zp4XDvgmDw== X-Received: by 2002:a5d:58ec:: with SMTP id f12mr22229024wrd.24.1632041244869; Sun, 19 Sep 2021 01:47:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i67sm7884497wmi.41.2021.09.19.01.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 01:47:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 4/5] repo-settings.c: simplify the setup Date: Sun, 19 Sep 2021 10:47:18 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1092.g44c994ea1be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Simplify the setup code in repo-settings.c in various ways, making the code shorter, easier to read, and requiring fewer hacks to do the same thing as it did before: Since 7211b9e7534 (repo-settings: consolidate some config settings, 2019-08-13) we have memset() the whole "settings" structure to -1 in prepare_repo_settings(), and subsequently relied on the -1 value. Most of the fields did not need to be initialized to -1, and because we were doing that we had the enum labels "UNTRACKED_CACHE_UNSET" and "FETCH_NEGOTIATION_UNSET" purely to reflect the resulting state created this memset() in prepare_repo_settings(). No other code used or relied on them, more on that below. For the rest most of the subsequent "are we -1, then read xyz" can simply be removed by re-arranging what we read first. E.g. when setting the "index.version" setting we should have first read "feature.experimental", so that it (and "feature.manyfiles") can provide a default for our "index.version". Instead the code setting it, added when "feature.manyFiles"[1] was created, was using the UPDATE_DEFAULT_BOOL() macro added in an earlier commit[2]. That macro is now gone, since it was only needed for this pattern of reading things in the wrong order. This also fixes an (admittedly obscure) logic error where we'd conflate an explicit "-1" value in the config with our own earlier memset() -1. We can also remove the UPDATE_DEFAULT_BOOL() wrapper added in [3]. Using it is redundant to simply using the return value from repo_config_get_bool(), which is non-zero if the provided key exists in the config. Details on edge cases relating to the memset() to -1, continued from "more on that below" above: * UNTRACKED_CACHE_KEEP: In [4] the "unset" and "keep" handling for core.untrackedCache was consolidated. But it while we understand the "keep" value, we don't handle it differently than the case of any other unknown value. So let's retain UNTRACKED_CACHE_KEEP and remove the UNTRACKED_CACHE_UNSET setting (which was always implicitly UNTRACKED_CACHE_KEEP before). We don't need to inform any code after prepare_repo_settings() that the setting was "unset", as far as anyone else is concerned it's core.untrackedCache=keep. if "core.untrackedcache" isn't present in the config. * FETCH_NEGOTIATION_UNSET & FETCH_NEGOTIATION_NONE: Since these two two enum fields added in [5] don't rely on the memzero() setting them to "-1" anymore we don't have to provide them with explicit values. 1. c6cc4c5afd2 (repo-settings: create feature.manyFiles setting, 2019-08-13) 2. 31b1de6a09b (commit-graph: turn on commit-graph by default, 2019-08-13) 3. 31b1de6a09b (commit-graph: turn on commit-graph by default, 2019-08-13) 4. ad0fb659993 (repo-settings: parse core.untrackedCache, 2019-08-13) 5. aaf633c2ad1 (repo-settings: create feature.experimental setting, 2019-08-13) Signed-off-by: Ævar Arnfjörð Bjarmason --- fetch-negotiator.c | 3 -- read-cache.c | 8 +++- repo-settings.c | 102 +++++++++++++++++++++++++-------------------- repository.h | 15 +++---- 4 files changed, 68 insertions(+), 60 deletions(-) diff --git a/fetch-negotiator.c b/fetch-negotiator.c index 237f92b8696..273390229fe 100644 --- a/fetch-negotiator.c +++ b/fetch-negotiator.c @@ -21,8 +21,5 @@ void fetch_negotiator_init(struct repository *r, case FETCH_NEGOTIATION_DEFAULT: default_negotiator_init(negotiator); return; - case FETCH_NEGOTIATION_NONE: - case FETCH_NEGOTIATION_UNSET: - BUG("FETCH_NEGOTIATION_UNSET only in prepare_repo_settings()"); } } diff --git a/read-cache.c b/read-cache.c index 6918dc3d8b2..147660c3090 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1952,9 +1952,13 @@ static void tweak_untracked_cache(struct index_state *istate) add_untracked_cache(istate); break; case UNTRACKED_CACHE_KEEP: + /* + * Either an explicit "core.untrackedCache=keep", the + * default if "core.untrackedCache" isn't configured, + * or a fallback on an unknown "core.untrackedCache" + * value. + */ break; - case UNTRACKED_CACHE_UNSET: - BUG("UNTRACKED_CACHE_UNSET only in prepare_repo_settings()"); } } diff --git a/repo-settings.c b/repo-settings.c index b0df8b93b86..46b9d56aeac 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -3,40 +3,76 @@ #include "repository.h" #include "midx.h" -#define UPDATE_DEFAULT_BOOL(s,v) do { if (s == -1) { s = v; } } while(0) +static void repo_cfg_bool(struct repository *r, const char *key, int *dest, + int def) +{ + if (repo_config_get_bool(r, key, dest)) + *dest = def; +} void prepare_repo_settings(struct repository *r) { + int experimental; int value; char *strval; + int manyfiles; - if (r->settings.initialized) + if (r->settings.initialized++) return; /* Defaults */ - memset(&r->settings, -1, sizeof(r->settings)); + r->settings.index_version = -1; + r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP; + r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT; + + /* Booleans config or default, cascades to other settings */ + repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0); + repo_cfg_bool(r, "feature.experimental", &experimental, 0); - if (!repo_config_get_bool(r, "core.commitgraph", &value)) - r->settings.core_commit_graph = value; - if (!repo_config_get_bool(r, "commitgraph.readchangedpaths", &value)) - r->settings.commit_graph_read_changed_paths = value; - if (!repo_config_get_bool(r, "gc.writecommitgraph", &value)) - r->settings.gc_write_commit_graph = value; - UPDATE_DEFAULT_BOOL(r->settings.core_commit_graph, 1); - UPDATE_DEFAULT_BOOL(r->settings.commit_graph_read_changed_paths, 1); - UPDATE_DEFAULT_BOOL(r->settings.gc_write_commit_graph, 1); + /* Defaults modified by feature.* */ + if (experimental) { + r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING; + } + if (manyfiles) { + r->settings.index_version = 4; + r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE; + } + + /* Boolean config or default, does not cascade (simple) */ + repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1); + repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1); + repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1); + repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0); + repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1); + repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1); + + /* + * The GIT_TEST_MULTI_PACK_INDEX variable is special in that + * either it *or* the config sets + * r->settings.core_multi_pack_index if true. We don't take + * the environment variable if it exists (even if false) over + * any config, as in most other cases. + */ + if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) + r->settings.core_multi_pack_index = 1; + /* + * Non-boolean config + */ if (!repo_config_get_int(r, "index.version", &value)) r->settings.index_version = value; - if (!repo_config_get_maybe_bool(r, "core.untrackedcache", &value)) { - if (value == 0) - r->settings.core_untracked_cache = UNTRACKED_CACHE_REMOVE; - else - r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE; - } else if (!repo_config_get_string(r, "core.untrackedcache", &strval)) { - if (!strcasecmp(strval, "keep")) - r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP; + if (!repo_config_get_string(r, "core.untrackedcache", &strval)) { + int v = git_parse_maybe_bool(strval); + + /* + * If it's set to "keep", or some other non-boolean + * value then "v < 0". Then we do nothing and keep it + * at the default of UNTRACKED_CACHE_KEEP. + */ + if (v >= 0) + r->settings.core_untracked_cache = v ? + UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE; free(strval); } @@ -45,34 +81,8 @@ void prepare_repo_settings(struct repository *r) r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING; else if (!strcasecmp(strval, "noop")) r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP; - else - r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT; } - if (!repo_config_get_bool(r, "pack.usesparse", &value)) - r->settings.pack_use_sparse = value; - UPDATE_DEFAULT_BOOL(r->settings.pack_use_sparse, 1); - - value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0); - if (value || !repo_config_get_bool(r, "core.multipackindex", &value)) - r->settings.core_multi_pack_index = value; - UPDATE_DEFAULT_BOOL(r->settings.core_multi_pack_index, 1); - - if (!repo_config_get_bool(r, "feature.manyfiles", &value) && value) { - UPDATE_DEFAULT_BOOL(r->settings.index_version, 4); - UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE); - } - - if (!repo_config_get_bool(r, "fetch.writecommitgraph", &value)) - r->settings.fetch_write_commit_graph = value; - UPDATE_DEFAULT_BOOL(r->settings.fetch_write_commit_graph, 0); - - if (!repo_config_get_bool(r, "feature.experimental", &value) && value) - UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_SKIPPING); - - UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP); - UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_DEFAULT); - /* * This setting guards all index reads to require a full index * over a sparse index. After suitable guards are placed in the diff --git a/repository.h b/repository.h index 3740c93bc0f..bf36744e0a7 100644 --- a/repository.h +++ b/repository.h @@ -13,18 +13,15 @@ struct submodule_cache; struct promisor_remote_config; enum untracked_cache_setting { - UNTRACKED_CACHE_UNSET = -1, - UNTRACKED_CACHE_REMOVE = 0, - UNTRACKED_CACHE_KEEP = 1, - UNTRACKED_CACHE_WRITE = 2 + UNTRACKED_CACHE_KEEP, + UNTRACKED_CACHE_REMOVE, + UNTRACKED_CACHE_WRITE, }; enum fetch_negotiation_setting { - FETCH_NEGOTIATION_UNSET = -1, - FETCH_NEGOTIATION_NONE = 0, - FETCH_NEGOTIATION_DEFAULT = 1, - FETCH_NEGOTIATION_SKIPPING = 2, - FETCH_NEGOTIATION_NOOP = 3, + FETCH_NEGOTIATION_DEFAULT, + FETCH_NEGOTIATION_SKIPPING, + FETCH_NEGOTIATION_NOOP, }; struct repo_settings { From patchwork Sun Sep 19 08:47: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: 12504251 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.7 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 9171EC433FE for ; Sun, 19 Sep 2021 08:47:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6ACD561205 for ; Sun, 19 Sep 2021 08:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237105AbhISIsx (ORCPT ); Sun, 19 Sep 2021 04:48:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237122AbhISIsw (ORCPT ); Sun, 19 Sep 2021 04:48:52 -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 7B261C06175F for ; Sun, 19 Sep 2021 01:47:27 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id w17so14779746wrv.10 for ; Sun, 19 Sep 2021 01:47: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=xaMRck/fVTgjoYKcOJXmBfZ48IvAEWbU9E+uPrk5qS0=; b=YefICJlPg83eoOA2z9RNRwd3zK/WbKrSU2CDB01rbfGV1PGNaOiGE1hg4AmEDz7kVZ fBTNwZw8Ym36zXNO1ugewaEPhA+6nQptiugDH+9MR2hzBULegGH9GvTO3CmgQVxsCqCd VQGBZZkw3Nev0sjSCmzfN5KRAwhecjtlZIADjQpPoMk/NjSTK9MRT/4we0XrWjvUVZgr cXh2EEvLpGr4zd/85w+NAcLT/GnTb+lH14AVSQJg0J+5Y3RpuLpEiOuEcoJ/ucFteXaG DlJM/cTdXKpAvyqswGT0y+PeYpzMVHR8JaovedKcDsf8yMExdDLTvbDogzs3QOgrwFVy bRYA== 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=xaMRck/fVTgjoYKcOJXmBfZ48IvAEWbU9E+uPrk5qS0=; b=bQE+rtf//p7/xCI5Jpqm8/4iPimGbtjaVtgeDGNkkt5s8MgIIrFX8Xku7v77kJHB5P zcglmCt6hs1wicrIKTWeQ0rWG92NZJVX/DJOdXPpa+cFfvNxTCl7+ZbsibE/zegKB3NT wiW4iJgbh+AP80pu4005DTYLE+YAWU7kpbaQFDenfjAj5W2/zUqea6WJcjXcgdL/fSmY YdoFuzSoPSe4IvOt5puERSivaU5/Kcwm4XZLdBUUh/D01OH8dpMks4skJh+YLejYxPAH 9cHJi6HNnJEfZQKBC2m1ogAyljjGgb7Gk4l0u3eKHId1SbnG91IVOmQ2p2Q3fMYs0M1i PfVQ== X-Gm-Message-State: AOAM533x4gdJQA1bWivARLSCxvOI70SAv0BMIPtKbYUJ686e2TxXTWto v/GhTlso3NralGLu3S1pWs7Et8t9a6/waQ== X-Google-Smtp-Source: ABdhPJw3mzwtnT0TyhaAeLed8HA2ytVopeQ2eCW4pTh2uwiL3Mx+x382/7zrHldoOoPQx0YcqRX8cA== X-Received: by 2002:a05:6000:18a4:: with SMTP id b4mr15463512wri.96.1632041245803; Sun, 19 Sep 2021 01:47:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i67sm7884497wmi.41.2021.09.19.01.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Sep 2021 01:47:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v3 5/5] repository.h: don't use a mix of int and bitfields Date: Sun, 19 Sep 2021 10:47:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1092.g44c994ea1be In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change the bitfield added in 58300f47432 (sparse-index: add index.sparse config option, 2021-03-30) and 3964fc2aae7 (sparse-index: add guard to ensure full index, 2021-03-30) to just use an "int" boolean instead. It might be smart to optimize the space here in the future, but by consistently using an "int" we can take its address and pass it to repo_cfg_bool(), and therefore don't need to handle "sparse_index" as a special-case when reading the "index.sparse" setting. There's no corresponding config for "command_requires_full_index", but let's change it too for consistency and to prevent future bugs creeping in due to one of these being "unsigned". Using "int" consistently also prevents subtle bugs or undesired control flow creeping in here. Before the preceding commit the initialization of "command_requires_full_index" in prepare_repo_settings() did nothing, i.e. this: r->settings.command_requires_full_index = 1 Was redundant to the earlier memset() to -1. Likewise for "sparse_index" added in 58300f47432 (sparse-index: add index.sparse config option, 2021-03-30) the code and comment added there was misleading, we weren't initializing it to off, but re-initializing it from "1" to "0", and then finally checking the config, and perhaps setting it to "1" again. I.e. we could have applied this patch before the preceding commit: + assert(r->settings.command_requires_full_index == 1); r->settings.command_requires_full_index = 1; /* * Initialize this as off. */ + assert(r->settings.sparse_index == 1); r->settings.sparse_index = 0; if (!repo_config_get_bool(r, "index.sparse", &value) && value) r->settings.sparse_index = 1; Signed-off-by: Ævar Arnfjörð Bjarmason --- repo-settings.c | 8 +------- repository.h | 5 ++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/repo-settings.c b/repo-settings.c index 46b9d56aeac..b93e91a212e 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -45,6 +45,7 @@ void prepare_repo_settings(struct repository *r) repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0); repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1); repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1); + repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0); /* * The GIT_TEST_MULTI_PACK_INDEX variable is special in that @@ -90,11 +91,4 @@ void prepare_repo_settings(struct repository *r) * removed. */ r->settings.command_requires_full_index = 1; - - /* - * Initialize this as off. - */ - r->settings.sparse_index = 0; - if (!repo_config_get_bool(r, "index.sparse", &value) && value) - r->settings.sparse_index = 1; } diff --git a/repository.h b/repository.h index bf36744e0a7..02599ae2c98 100644 --- a/repository.h +++ b/repository.h @@ -31,6 +31,8 @@ struct repo_settings { int commit_graph_read_changed_paths; int gc_write_commit_graph; int fetch_write_commit_graph; + int command_requires_full_index; + int sparse_index; int index_version; enum untracked_cache_setting core_untracked_cache; @@ -39,9 +41,6 @@ struct repo_settings { enum fetch_negotiation_setting fetch_negotiation_algorithm; int core_multi_pack_index; - - unsigned command_requires_full_index:1, - sparse_index:1; }; struct repository {