From patchwork Tue Sep 21 13:12:59 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: 12507817 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 A26D7C433FE for ; Tue, 21 Sep 2021 13:13:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87D196112F for ; Tue, 21 Sep 2021 13:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232868AbhIUNOj (ORCPT ); Tue, 21 Sep 2021 09:14:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbhIUNOi (ORCPT ); Tue, 21 Sep 2021 09:14:38 -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 795F5C061574 for ; Tue, 21 Sep 2021 06:13:10 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id u15so39050317wru.6 for ; Tue, 21 Sep 2021 06:13:10 -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=dNZFxbiJRW5pSnFhgJ3zpEadwx1XOGlpPDoK23RnUE8=; b=NBoKMEtJ9x4MU3FXcN3dPkHTkzNbuPnnuvLWmXF688oJ6YtCGJxtA8EsmdZ0iTzzLj 7DZlWl3WFUa1OoiM9xGd666pWBTARr0NHhBu4mmygXKiNU6qnfCqrGN7zIARXY13Atep fZj1V7EgSMzLaWajbwOyTyq+vy5tlW4Jovo1lDfBFW5enCagQyiWUvkOgkEmkRLrUEAz oC65Mn8vTvTLz2vSrCtWq1nKs6+2IFQm6HBf1s7SOwNbvKtqWTfJkWIZF25/w4Z1pblG PXaKXCmuDWnKqGxaKsU3vmurRGXW/e2QKafAZjESaFVfDHu4HomHvRynlXERlaAxemVJ VAMw== 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=dNZFxbiJRW5pSnFhgJ3zpEadwx1XOGlpPDoK23RnUE8=; b=aeiRYSyo1Ec+n2SoIKvNqk5mKR46J3b8MdiA90P4KjUNlWEH7TfpRLAb24kHkW4+Ow hscFcmoQBy5F3FMfvmKCNBQCMFkHB1GipxcMKwkl4XendWaA6ZHyMyt0nI3Qm9HeBqeh +xsAvWmuz536CUmAWBCCMZL2hN3wo3fyKWT49KemGmD4DGFT7W5M8y0NIN7HH5Cd0hfP OaRFwaYZTywlWCpdVrlIGmhlSBQM6ixv3z7obF1fLBw+Drd7sz2wtyToA75RPiFSuyrw kSzp+kfrWTY5XTm5iu892+NxkV71VgTN+EbiNPKc8SqqSR2sG1Vj62ZZ0Xl+d/frWAMP 7nEA== X-Gm-Message-State: AOAM530hcSt+NrNEjYrIgpcQINokuFY4iDszPUQ30hPgR5PA5CyvD3VZ B8e+2+hxgLJJpQ0Skso/1kOMkCIN2YYeNA== X-Google-Smtp-Source: ABdhPJxmC/gQLbc8o+o22OxpQdDAQ1IRjVvu6ivrRpS8RCu79WO4meHmpZSB4/rWcq0s35O/e2M4Cg== X-Received: by 2002:adf:dc85:: with SMTP id r5mr4811871wrj.37.1632229988490; Tue, 21 Sep 2021 06:13:08 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v18sm2733260wml.44.2021.09.21.06.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 06:13:07 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , Taylor Blau , =?utf-8?b?w4Z2?= =?utf-8?b?YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 1/5] wrapper.c: add x{un,}setenv(), and use xsetenv() in environment.c Date: Tue, 21 Sep 2021 15:12:59 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d 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. Let's make these return "void" instead of "int". As far as I can tell there's no other x*() wrappers that needed to make the decision of deviating from the signature in the C library, but since their return value is only used to indicate errors (so we'd die here), we can catch unreachable code such as if (xsetenv(...) < 0) [...]; 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 | 12 ++++++++++++ 3 files changed, 15 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 ddc65ff61d9..94d8250832d 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); +void xsetenv(const char *name, const char *value, int overwrite); +void 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..1460d4e27b0 100644 --- a/wrapper.c +++ b/wrapper.c @@ -145,6 +145,18 @@ void *xcalloc(size_t nmemb, size_t size) return ret; } +void xsetenv(const char *name, const char *value, int overwrite) +{ + if (setenv(name, value, overwrite)) + die_errno(_("could not setenv '%s'"), name ? name : "(null)"); +} + +void xunsetenv(const char *name) +{ + if (!unsetenv(name)) + die_errno(_("could not unsetenv '%s'"), name ? name : "(null)"); +} + /* * 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 Tue Sep 21 13:13:00 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: 12507819 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 13BF7C433EF for ; Tue, 21 Sep 2021 13:13:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E757C611BD for ; Tue, 21 Sep 2021 13:13:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232897AbhIUNOm (ORCPT ); Tue, 21 Sep 2021 09:14:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230411AbhIUNOk (ORCPT ); Tue, 21 Sep 2021 09:14:40 -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 183F7C061574 for ; Tue, 21 Sep 2021 06:13:12 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id u18so37292425wrg.5 for ; Tue, 21 Sep 2021 06:13:12 -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=gCEOWZXAqPd7DhK96pWEwHbEJdxJ4wt1/JzZzaKjz/I=; b=DJ1r29OQHWaceKqRWMkzXGTy9JBjO4CXaKE1eL9Fo3yWqfNo63x9bylIfm93+v5p0Y KXbssyh7fpOzmNIZg49X8TB8S0GtgfC1yAq++FwIhwKZ9MwII6tWwqDXplKF5qSMKRjX dv6JCNu6Cfp9CSonFFK2hPYynQK6jhaHPNIaSaS7LLguRlSZPuMLjHU2n8mM8oV+gawf KeK1LSeYidxk5ET5bd89pdTMypkxjmXU2PoLPdjdNwPGfiVuVCu0bT/sHl0kNRaWwl+l JNSfhU3WSEaLZwxEnNGZJFr3I8MYbhUPti0hXHawn8Y0q0Kt5eTtT1SpXwXhAY/Ah9mU uMkQ== 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=gCEOWZXAqPd7DhK96pWEwHbEJdxJ4wt1/JzZzaKjz/I=; b=GtdqoyHr4JIQYMkFXzGtGJ7kOcJoGSsh+Hlj7NeWJS0I4luVl8I9gngKs+wgG1kVaZ 7WuYwxwGk7kZPfxTVypOjAnEvTcTlDC/RQgiZGkDE6wmh4yHtiGeRkjuj4o+wfpNwcSj lSkbUJwSfaStFTT5x6y/ND22ZmO86bYoJtUQL1tmgGVKfNdbfP75/EfrUe+sIEaWIEbg 16eShFptmTpdMnJ6YSKtq3k0o3VUJgjjH2pA5HdXye/OmvDm01E8h+CInnpuOUU0IpgG CNGu5jQLBhN9L/ne1pgQih8GRbt/XgFGYiMfMTVVuNU80i3QCx9EnRZHfw3E/dqUxILC jlcQ== X-Gm-Message-State: AOAM533rulDwCHQKnwLhU8SRvs5vJ+yXYduBJqZYNMJtL9HvfuUxEmdH KUspRrnLFSMHsW3t+PCljAImsgz8aWT/Fg== X-Google-Smtp-Source: ABdhPJzvFsa8wgwTV4QmfLOdqsGh1frDmowRuHLHXVYqFM6+jn0K6BdwzpUzR/aJBLKom0GNeuUYAw== X-Received: by 2002:a5d:6d81:: with SMTP id l1mr35486502wrs.404.1632229989841; Tue, 21 Sep 2021 06:13:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v18sm2733260wml.44.2021.09.21.06.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 06:13:08 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , Taylor Blau , =?utf-8?b?w4Z2?= =?utf-8?b?YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 2/5] environment.c: remove test-specific "ignore_untracked..." variable Date: Tue, 21 Sep 2021 15:13:00 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d 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 0c245d4f105..8941cc62c59 100644 --- a/cache.h +++ b/cache.h @@ -1726,13 +1726,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 Tue Sep 21 13:13:01 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: 12507821 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 28085C433F5 for ; Tue, 21 Sep 2021 13:13:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09D21611C5 for ; Tue, 21 Sep 2021 13:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232999AbhIUNOn (ORCPT ); Tue, 21 Sep 2021 09:14:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232996AbhIUNOm (ORCPT ); Tue, 21 Sep 2021 09:14:42 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC80DC061574 for ; Tue, 21 Sep 2021 06:13:13 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id t7so5797021wrw.13 for ; Tue, 21 Sep 2021 06:13:13 -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=mAV57uDkKQnLyNDH9m6cm+VqhOjIxoN2SD/Poeh17iQ=; b=hZT6efJP+8AnGk/gBlcxlMA5yrywdJ81huB4XVtCRIvKEo2CGeUD4No0VbAL9zWLZj XdCcin60nku3AjcIytIf518EPoY+TS/Fc7/qsPZ/u7byQMyQcEmSAcHnwUb2KQtAoTQW wXupfcANe3HeKnDmUcPiN17p08IydY8fGgvyzEEIWITOAKW1ZHIS0aobzR54CSv3B2iQ mMZ88KmeLSpUvvmS3jjDdSLCUCDw+ktqtVctnD+VPtxNMLU5ps3uyfGq11Hl/9CGx1+k mwuVSb86mkUfdhBmhpeo+Yuu6a6vYJHlp0p4DTKNfIx3uz7x+zbxcH3dqZ7JDNyf9Zoi lttQ== 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=mAV57uDkKQnLyNDH9m6cm+VqhOjIxoN2SD/Poeh17iQ=; b=BIbUZbzNhhlsOyRyNa4woHQHpTG0PswnIpwFRO0Kv2zh4nH5yfw8Uot7pPaebM8PmN EN7a3BEqztn4zruscp9u6BSZwiXgR2NXC8QCWWxRbBJN4L3TZN0DCBfE9e/3cnAPu0P1 YPt+8s7hZOQBJV/BOKcrpOtp8bKZcoJPAVU5n84nUmlkR9OdBfGYY+Pxq7++ShhqddBA zvLYqnMh5buJ+v/3qXbpwccbbgbbFtxFogU7cSLCnULv2lpI5cwdL3IqkyiG+eYS3VhM 1WdQGu/AsUzzfWZUuVkg68LebqPI/gOsEHCfz9YOuYxqIEhlKmaGAbWiFkPITBMXKQZS nXXA== X-Gm-Message-State: AOAM530l7ivoLbJrTvb0KNymZ8sP+Tf5Pid18jiiGxjTwoCbWsNKcJxw iKGVLxNvI8UsBbplcg6i9MtKqctHGg/EQA== X-Google-Smtp-Source: ABdhPJyDs5T8d4l88HHHEmxqZxdwPod0vskLOUyNrVRKUNjCwx/3pVp2Jp4bWfTkprQQaJrx2rBwJQ== X-Received: by 2002:adf:f50b:: with SMTP id q11mr12377561wro.306.1632229991844; Tue, 21 Sep 2021 06:13:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v18sm2733260wml.44.2021.09.21.06.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 06:13:11 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , Taylor Blau , =?utf-8?b?w4Z2?= =?utf-8?b?YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 3/5] read-cache & fetch-negotiator: check "enum" values in switch() Date: Tue, 21 Sep 2021 15:13:01 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d 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..e61e40cb299 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_{NONE,UNSET} used outside of prepare_repo_settings()!"); } } diff --git a/read-cache.c b/read-cache.c index f5d4385c408..e4ae35ccdb2 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 used outside of prepare_repo_settings()!"); + } } static void tweak_split_index(struct index_state *istate) From patchwork Tue Sep 21 13:13:02 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: 12507823 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 1D0F3C433EF for ; Tue, 21 Sep 2021 13:13:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0583B611C5 for ; Tue, 21 Sep 2021 13:13:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233008AbhIUNOv (ORCPT ); Tue, 21 Sep 2021 09:14:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233006AbhIUNOn (ORCPT ); Tue, 21 Sep 2021 09:14:43 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1D8BC061574 for ; Tue, 21 Sep 2021 06:13:14 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id d21so38990781wra.12 for ; Tue, 21 Sep 2021 06:13:14 -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=ZKqWdCHbicix/Lj0PqM9Yd4vMeUYr9EcPJYw+LtreHM=; b=BFJLJa9rLbjXDBQrf4vft1RYwEUulfIVz86GTLdj0O1MOXUtCdvXyguUZkpR0pPNkG tSTflsKY5vW8saD3ge89YN0eoSfEDCYdnT00HPCg2kyazI63tYb2q2EiYHRkNLIb9WXp rlN5pPPN2pkm3zbZD49YXCUn78KGyRIQ5Wpam1j+nd74sL2ZVCeT4Uhrmhdfi2FuyfLH d1Z+k1EeKr9igFac5VIB7vGhIdbYDjpxRPX3UKH0WW3VA9QHBu+lWgWjwG48m4RZEKgo yXGY5+kmHTTnDC45DEiwX7hvg3CI4IEhAoLeXlf+lKHrkMpEWh7nn/ljw1NRYt7g3GEp O3LA== 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=ZKqWdCHbicix/Lj0PqM9Yd4vMeUYr9EcPJYw+LtreHM=; b=f52kcvxMhqp71nUH5wWcs8Hd8/B+kTeikwSrasr2jySLG1IWx0uKx8JKHLYjOH/mM3 yj+HONk7CBxUOm2Nadm7zthNsb4k+rktFpDzLJ3l9hG7xjWsDsfU1Pc8kEOvq6L46cdW 32LyLJY/2hu1gmb3/iFSC7xx7O9R5x9B1yXf+Ubrahj7Gu4LxdjkuBZCKxFQGEPZr9v2 h7iIrJclghR+GKafygRk4XjO9yeAPIB9H7lfEkaqgl9FQu3hKEwvJ56N1vBU4e4Wfp4z GKMJyhVTEUlqFdigyIZYRb3bP1NPUv0gPEDZiPXUIbxcdfrsAoQl5+KpwC6huGQmXA23 lZ5g== X-Gm-Message-State: AOAM533k/vkC67dkkK6WjHk14gXgtWJihIs5g1LIR5Ae+U5Ki9+SvvQ2 zxkFZMo6TcNnUWwZwHIcOlkXopbsERGwVA== X-Google-Smtp-Source: ABdhPJyGZbGqCPbrICAvMjQhpuDC6yS/ZPr+YMSMW+NBu4Tg0hErT4yHU8p9swfzhuPfqPb5442Ytg== X-Received: by 2002:adf:f80e:: with SMTP id s14mr35055429wrp.435.1632229993026; Tue, 21 Sep 2021 06:13:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v18sm2733260wml.44.2021.09.21.06.13.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 06:13:12 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , Taylor Blau , =?utf-8?b?w4Z2?= =?utf-8?b?YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 4/5] repo-settings.c: simplify the setup Date: Tue, 21 Sep 2021 15:13:02 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d 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 e61e40cb299..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_{NONE,UNSET} used outside of prepare_repo_settings()!"); } } diff --git a/read-cache.c b/read-cache.c index e4ae35ccdb2..b0a06db5c55 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 used outside of 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 Tue Sep 21 13:13:03 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: 12507825 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 269D0C433F5 for ; Tue, 21 Sep 2021 13:13:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FCC3611CE for ; Tue, 21 Sep 2021 13:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233026AbhIUNOx (ORCPT ); Tue, 21 Sep 2021 09:14:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233028AbhIUNOu (ORCPT ); Tue, 21 Sep 2021 09:14:50 -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 31319C061767 for ; Tue, 21 Sep 2021 06:13:16 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id t7so5797370wrw.13 for ; Tue, 21 Sep 2021 06:13:16 -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=wns+8NTxqlV/V7OSzUlJk3xAS+whp3qj8SV2LHdjsWg=; b=XNNeKGGE4ObKTYVQWMtTvZUow5nK/5jfDglH+3qrsc16QbjGpmGq/qH5vYxLB3Yyao YTKVZ1p+TotbYo6ZpZ57LtIBBqhGGdqNFL8+pPKAMNchlIIVX9TAXWW0ZLsVnh3UILlt 4+xuHjzHHTU5PnnrIR2fn3GR2bAUy0i9BjWnpqHWD+T53LXGYk+Xy59161EyQfbI0th8 ValNC+wH8utH/bXIafUKA4Ws8bEi79OV+MtIfY2C3MgttIMrJcAJUmFCzKo37/fPr04A h01ki9j7lhkWxlgYjKrLpF1x41mFlOtezyREhI9LBZLjYipUiPocB14NmCRiZZJGF2S2 7+mQ== 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=wns+8NTxqlV/V7OSzUlJk3xAS+whp3qj8SV2LHdjsWg=; b=sqxpUjgT0I7RRl6tXfwHaxeq3YxCcclEiMvrHd4kFZ4WIlZA6qwLUpB6A27lT4n7u3 pX83nOsDpnhXiNMnBjT+IRdB/bMc6GLFhMgMn1M0AO0THKWbIlnJAgQemZqlifFna0/e SXpGwNocdsZdl7ogo1mlrRYfTbZ+X5OG8JEsOWw9XuL5Aeyl2KvOTaeDByMNmM0oKZvm UZIxd3VYoL/UqVX28vQPKSbpFrV3zl3FT8k0R/4Umq+dglZebIDLEQ3W8JqznZXafb31 HBwuAPC/QqILqM+dvNS7Ri5oxy28M6e0xXg9mDmoNn5CfVBeATcohydGOELCQjFVs1IX pE3Q== X-Gm-Message-State: AOAM5319ZxNWsxRroa74F1e4HPTFgR+jx5pvlnQZMnTkSGLtyYMWR/nC ShoidxNSjaA1Muex10AfLoX7az99H3xqMg== X-Google-Smtp-Source: ABdhPJy+m+h8eJJ4s3mGi1iEw4nI+SBIxBfUy7UMz9ExlzDFAfyz332k/axJ/J/660vGT8Io8DPu7g== X-Received: by 2002:a1c:7e87:: with SMTP id z129mr4439475wmc.75.1632229994379; Tue, 21 Sep 2021 06:13:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v18sm2733260wml.44.2021.09.21.06.13.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 06:13:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , Jeff Hostetler , Patrick Steinhardt , Jeff King , Taylor Blau , =?utf-8?b?w4Z2?= =?utf-8?b?YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v4 5/5] repository.h: don't use a mix of int and bitfields Date: Tue, 21 Sep 2021 15:13:03 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1098.gf02a64c1a2d 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 {