From patchwork Mon Dec 20 15:57:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12688159 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0494C433FE for ; Mon, 20 Dec 2021 15:57:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237753AbhLTP53 (ORCPT ); Mon, 20 Dec 2021 10:57:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237696AbhLTP52 (ORCPT ); Mon, 20 Dec 2021 10:57:28 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEEACC06173E for ; Mon, 20 Dec 2021 07:57:27 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id a203-20020a1c7fd4000000b003457874263aso7672121wmd.2 for ; Mon, 20 Dec 2021 07:57:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=IsSw908ccp3lxCR+ZdyOEfSsjPWPiG+5vFYTdIKHeTI=; b=I13ppJdWQkOFXs2ZAv6vCS5+RD6I3Po62pgWas67mMWGXsAjmgMRJTyhqCzf1+9xOg eSaYsChJcV9WDgYPbYY91dodhbz8IVa+bs/KYF4FDJ+8u5R5wqgYOAkWae8Q+B/7HdxR QqA+zM5bBKRQKXEKDeb0P8x3YgXaRU2GHOvZ91JxIYCeNIG8Fr5/gc23d7obSZptV9bp OocdM1GmLoVdWab0xTzVInTyDo0cVQWoOXJGvA/E0Rf9+Lvx73qGgn02cYkoT6rtbKrG NgTUuxUYgDCY5nuf6OjLR34mHjrSCpPutL71bS7kPMR3axccsySJCEomJoheSQyQAuEm zC5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=IsSw908ccp3lxCR+ZdyOEfSsjPWPiG+5vFYTdIKHeTI=; b=5KDL0WqdzQ5q7rwiZVTllAF7B1A7UkTTDJlX7hPtEBjQdr5RKucNsRRhhOW9rYMfxV SD2ICCwuN/6U2g/fjgvo7AvH1BnUvTMVK8geEiB0k/Mt+Kc/NhiFWF7JV+in73zI0IuZ wwQ3/V5HJik+6oH08CLyqfi+IfrwBWiUKyMQzmTNt+yV6hXU0BbMwmeCeRPvrIM4bJ5g OqUx336m4PwN84kb0Ybf0TzPI0aEcA9KsUxH6J9bq8l3zjiT5TGY8pIK7Ea9LBNbLONO n4WYgCZYmIMlxiT0kiUiJWTmYgU8W6OPmgUTkldWvGmVGwTXhFR6+bncWX7DqUpAOCO+ wyZQ== X-Gm-Message-State: AOAM531J+64JQ8KyBVCjMWzSuCd9fZ4xEc951MwGOQjcduf/sHyfKKYj Hz7MU2ljm4XIUyOOUrxZf70rvUDSdJs= X-Google-Smtp-Source: ABdhPJx9jHmY7T6cIOThTOqI3x29cMm1tv/OndWrMoc4OzUSrpnLeY2GBzSbuRVD2A78ExwdeAz+gQ== X-Received: by 2002:a05:600c:1e12:: with SMTP id ay18mr6736741wmb.14.1640015846435; Mon, 20 Dec 2021 07:57:26 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e1sm14090777wrc.74.2021.12.20.07.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 07:57:26 -0800 (PST) Message-Id: <28813703ff612cd346a49549ce11ba79a47eb223.1640015844.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Dec 2021 15:57:21 +0000 Subject: [PATCH 1/4] setup: use a repository when upgrading format Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, sunshine@sunshineco.com, allred.sean@gmail.com, gitster@pobox.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The upgrade_repository_format() helper previously was not aware of the possibility of multiple repositories. Add a 'struct repository *' parameter so it is possible to call it from a specific repository. The implementation already referred to the_repository in one place, so that is an easy replacement. The use of git_config_set() is replaced with a call to repo_config_set(). Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 2 +- list-objects-filter-options.c | 2 +- repository.h | 2 +- setup.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index d0f5c4702be..34447f87cd8 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -358,7 +358,7 @@ static int set_config(enum sparse_checkout_mode mode) { const char *config_path; - if (upgrade_repository_format(1) < 0) + if (upgrade_repository_format(the_repository, 1) < 0) die(_("unable to upgrade repository format to enable worktreeConfig")); if (git_config_set_gently("extensions.worktreeConfig", "true")) { error(_("failed to set extensions.worktreeConfig setting")); diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c index fd8d59f653a..6e21d12045e 100644 --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@ -372,7 +372,7 @@ void partial_clone_register( */ return; } else { - if (upgrade_repository_format(1) < 0) + if (upgrade_repository_format(the_repository, 1) < 0) die(_("unable to upgrade repository format to support partial clone")); /* Add promisor config for the remote */ diff --git a/repository.h b/repository.h index 98f95834706..d3fc1f7689d 100644 --- a/repository.h +++ b/repository.h @@ -215,6 +215,6 @@ void prepare_repo_settings(struct repository *r); * Return 1 if upgrade repository format to target_version succeeded, * 0 if no upgrade is necessary, and -1 when upgrade is not possible. */ -int upgrade_repository_format(int target_version); +int upgrade_repository_format(struct repository *, int target_version); #endif /* REPOSITORY_H */ diff --git a/setup.c b/setup.c index 347d7181ae9..90516664ce5 100644 --- a/setup.c +++ b/setup.c @@ -595,14 +595,14 @@ static int check_repository_format_gently(const char *gitdir, struct repository_ return 0; } -int upgrade_repository_format(int target_version) +int upgrade_repository_format(struct repository *r, int target_version) { struct strbuf sb = STRBUF_INIT; struct strbuf err = STRBUF_INIT; struct strbuf repo_version = STRBUF_INIT; struct repository_format repo_fmt = REPOSITORY_FORMAT_INIT; - strbuf_git_common_path(&sb, the_repository, "config"); + strbuf_git_common_path(&sb, r, "config"); read_repository_format(&repo_fmt, sb.buf); strbuf_release(&sb); @@ -621,7 +621,7 @@ int upgrade_repository_format(int target_version) repo_fmt.unknown_extensions.items[0].string); strbuf_addf(&repo_version, "%d", target_version); - git_config_set("core.repositoryformatversion", repo_version.buf); + repo_config_set(r, "core.repositoryformatversion", repo_version.buf); strbuf_release(&repo_version); return 1; } From patchwork Mon Dec 20 15:57:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12688161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0C47C4332F for ; Mon, 20 Dec 2021 15:57:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237781AbhLTP5a (ORCPT ); Mon, 20 Dec 2021 10:57:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237725AbhLTP53 (ORCPT ); Mon, 20 Dec 2021 10:57:29 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8D9EC061574 for ; Mon, 20 Dec 2021 07:57:28 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id i22so20977913wrb.13 for ; Mon, 20 Dec 2021 07:57:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ZHHVedAp8W2JuzN7+w7ympjfdkaHVwsh7qOjVXFvtD0=; b=T30lNlgVROZoxycxBttUdCaLL8VzDoolzm49j2qLw7PEJfPZqEQpat5uKcKlGJs0Ua JxJKJx9ni/cP3jBuvDnqf12usui4V6vGpDRRMEZhs+D3B5VcIg8XZjbXyYDJ6ljEkAwo K+QMzH9t75FPjzbY2/CbBlQlVduY9huHlzNcA+yhSsjRc36FMias5kl4wTos9UpsK5F2 TofrZqlozZwnI9u65qLF9d99b7bWcu41JNN8vzk7FbcZ0+mfREQNpUwnrCW8X6lqQuyY FZUy/POz3NOjuLp6/G0cfD3ZOmLCXv3Y9aABx9EIlNkIYOjoBnGMDGQWFwecdfdEGizP B2bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ZHHVedAp8W2JuzN7+w7ympjfdkaHVwsh7qOjVXFvtD0=; b=wyV6drCvIEgfdrea4qxjy1jVvOXubLDLJ4PJ1UEpzIC7CRDYt2kvWCA2yo1DwoiKCq z5BvxQlK8ZadYfBx/OLyrkAWLcq9ISi8HEUSqtb8jQtxuJuYP6FfNQXnqbr1KgNnomH2 wJTrxk+9iKEDeh/HTvgfc7yp8XIqHxbGBAWXlhyatr0BACDIP97p/ODcc/JUAYthwcXz Jb8NN0DcoAlZNgaYjMMzvd2NQwBaCNvxh0SyUI3hQxu1Hpx21SPZRUkvVF00v2QPEStr UX2i+dDtdpt0mkwQbffgT1lao/Dkoyp31b76dw131StHF1jjlLFy+w9T0T+N5UcbB0xR xGzw== X-Gm-Message-State: AOAM530YC4FJxhIcn+L6vu2ZUYzn71MSIBjt1tc90TKfHRUguUg9Gf29 GBUxw5CLC2I080chP/E64uOOau3+Cz0= X-Google-Smtp-Source: ABdhPJw5PQm9fFy9hExsfK1hr6zBEKOjj2wOuGKQCh4+U70iPKOYnthwDY/6d+uYn/KhV6Hr95uh1A== X-Received: by 2002:a5d:60c8:: with SMTP id x8mr8263686wrt.695.1640015847036; Mon, 20 Dec 2021 07:57:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c2sm6527340wri.50.2021.12.20.07.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 07:57:26 -0800 (PST) Message-Id: <3b549770eb9133fc78739ecc4eaba274e138076f.1640015844.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Dec 2021 15:57:22 +0000 Subject: [PATCH 2/4] config: make some helpers repo-aware Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, sunshine@sunshineco.com, allred.sean@gmail.com, gitster@pobox.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee As we prepare to add new config helpers to write into a config.worktree, let's make some existing methods be available for writing to a config file relative to a repository. Signed-off-by: Derrick Stolee --- config.c | 29 ++++++++++++++++++++++++++--- config.h | 7 +++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/config.c b/config.c index c5873f3a706..9c9eef16018 100644 --- a/config.c +++ b/config.c @@ -2882,7 +2882,12 @@ int git_config_set_gently(const char *key, const char *value) void git_config_set(const char *key, const char *value) { - git_config_set_multivar(key, value, NULL, 0); + repo_config_set(the_repository, key, value); +} + +void repo_config_set(struct repository *r, const char *key, const char *value) +{ + repo_config_set_multivar(r, key, value, NULL, 0); trace2_cmd_set_config(key, value); } @@ -3177,14 +3182,32 @@ void git_config_set_multivar_in_file(const char *config_filename, int git_config_set_multivar_gently(const char *key, const char *value, const char *value_pattern, unsigned flags) { - return git_config_set_multivar_in_file_gently(NULL, key, value, value_pattern, + return repo_config_set_multivar_gently(the_repository, key, value, + value_pattern, flags); +} + +int repo_config_set_multivar_gently(struct repository *r, const char *key, + const char *value, + const char *value_pattern, unsigned flags) +{ + return git_config_set_multivar_in_file_gently(repo_git_path(r, "config"), + key, value, value_pattern, flags); } void git_config_set_multivar(const char *key, const char *value, const char *value_pattern, unsigned flags) { - git_config_set_multivar_in_file(NULL, key, value, value_pattern, + repo_config_set_multivar(the_repository, key, value, + value_pattern, flags); +} + +void repo_config_set_multivar(struct repository *r, const char *key, + const char *value, const char *value_pattern, + unsigned flags) +{ + git_config_set_multivar_in_file(repo_git_path(r, "config"), + key, value, value_pattern, flags); } diff --git a/config.h b/config.h index f119de01309..5531fc018e3 100644 --- a/config.h +++ b/config.h @@ -258,6 +258,11 @@ int git_config_set_gently(const char *, const char *); */ void git_config_set(const char *, const char *); +/** + * write config values to `.git/config`, takes a key/value pair as parameter. + */ +void repo_config_set(struct repository *, const char *, const char *); + int git_config_parse_key(const char *, char **, size_t *); /* @@ -281,6 +286,8 @@ int git_config_parse_key(const char *, char **, size_t *); int git_config_set_multivar_gently(const char *, const char *, const char *, unsigned); void git_config_set_multivar(const char *, const char *, const char *, unsigned); +int repo_config_set_multivar_gently(struct repository *, const char *, const char *, const char *, unsigned); +void repo_config_set_multivar(struct repository *, const char *, const char *, const char *, unsigned); int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, unsigned); /** From patchwork Mon Dec 20 15:57:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12688163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7687C433F5 for ; Mon, 20 Dec 2021 15:57:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237810AbhLTP5b (ORCPT ); Mon, 20 Dec 2021 10:57:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237696AbhLTP53 (ORCPT ); Mon, 20 Dec 2021 10:57:29 -0500 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 387E5C06173E for ; Mon, 20 Dec 2021 07:57:29 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id b188-20020a1c80c5000000b00345afe7e3c0so364623wmd.3 for ; Mon, 20 Dec 2021 07:57:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/YKiBTM++2zocP5Q85EYLwm92iPXHqkV2co9AUgPvfY=; b=EcB0dKvPlX1l5uqY13Kp8YVkjAht+lzjOTzKFW3hMTVAayO8G5R/qyvoKDJ1ULeq5x DfxxhXVJA6rIXLaER+uMxv0BVYKxWvehOmCyDdZ018X90NO5W2Cv6S28capEi+iOmNxb 48UQ/Kj3jesTexlebWjZn638A+KYQnuLGH9dTjL19KPITXDlEd/iFw09BlHB0X0pv+s2 rtsf+04BX2ut6Q/SYx0D0s7LrRagRc1hgOiO5ACx/JVLPFySz9p2nUKyOcCqNJrQjwGT hh4mBEmE4Woe7M0ZWm8zBYZ7TLSe67UAjFglGocSIR9MmNb4CMCoq4fuBMt2okDtaQ+e YEtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/YKiBTM++2zocP5Q85EYLwm92iPXHqkV2co9AUgPvfY=; b=ArA71a0DZH65meSVrLc7PjusRreCI93EXg0lo5VtB1xscvceMnN/9j+zS/WBXHNb/v zsZNwcXlUAxKtJ5ooSbzOAP45Q0ETCZIjfa3BX7HHhFaCUjbAleqGFIRuB8YQvHJ1j1A Hjvb3HqM9NMu161S5LEaOByKzg0LkLLkl3kUXNRpo5O21pax1kVlth2GdErBTOdhR9Og a6r3ag7luUktLhYBvXkXbAhJhZglXZXmW8tkXREz1rjSM+ld8u4zJJ/TJuOVQxFtXSJf uV9NMigNcsETHWKCFaa4xFgH1xKuPN8F/F3YuslwSyEIbVYB1neldam0VAam5AdKV+jN BnJA== X-Gm-Message-State: AOAM531NOpilCHlFdnlyB+0MWtq+2PpuFq1xAdzyuMFg7bmB0j1CmXJ+ a84avFle//YzY3r+6jn/xBaTPpT0WjM= X-Google-Smtp-Source: ABdhPJz+KJS/WeaDBl+0+WCxu/Ss2LdvrlCTwuPA6Zc4I0NX/kB5pxayfmaCA+LOO+EryBDE+5SOnw== X-Received: by 2002:a05:600c:3c9b:: with SMTP id bg27mr14443986wmb.163.1640015847681; Mon, 20 Dec 2021 07:57:27 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p11sm5009639wru.99.2021.12.20.07.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 07:57:27 -0800 (PST) Message-Id: <67993f6cff254d341ba4ad7fe7709b57eb3e74d4.1640015844.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Dec 2021 15:57:23 +0000 Subject: [PATCH 3/4] config: add repo_config_set_worktree_gently() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, sunshine@sunshineco.com, allred.sean@gmail.com, gitster@pobox.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee When adding config values to the worktree config, we might enable the extensions.worktreeConfig setting and create the config.worktree file for the first time. When the base repository is bare, this creates a change of behavior for determining if the worktree is bare or not. A worktree off of a bare repository is assumed to be non-bare when extensions.worktreeConfig is disabled. When extensions.worktreeConfig is enabled but config.worktree is empty, the worktree is considered bare because the base repo's core.bare=true setting is used. To avoid issues like this, create a helper that initializes all the right settings in the correct order. A caller will be added in the next change. Signed-off-by: Derrick Stolee --- config.c | 27 +++++++++++++++++++++++++++ config.h | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/config.c b/config.c index 9c9eef16018..67f3d5015ef 100644 --- a/config.c +++ b/config.c @@ -2880,6 +2880,33 @@ int git_config_set_gently(const char *key, const char *value) return git_config_set_multivar_gently(key, value, NULL, 0); } +int repo_config_set_worktree_gently(struct repository *r, + const char *key, const char *value) +{ + int res; + const char *config_filename = repo_git_path(r, "config.worktree"); + + /* + * Ensure that core.bare reflects the current worktree, since the + * logic for is_bare_repository() changes if extensions.worktreeConfig + * is disabled. + */ + if ((res = git_config_set_multivar_in_file_gently(config_filename, "core.bare", + r->worktree ? "false" : "true", + NULL, 0))) { + error(_("unable to set core.bare setting in worktree config")); + return res; + } + if (upgrade_repository_format(r, 1) < 0) + return error(_("unable to upgrade repository format to enable worktreeConfig")); + if ((res = git_config_set_gently("extensions.worktreeConfig", "true"))) { + error(_("failed to set extensions.worktreeConfig setting")); + return res; + } + + return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, 0); +} + void git_config_set(const char *key, const char *value) { repo_config_set(the_repository, key, value); diff --git a/config.h b/config.h index 5531fc018e3..d8db420849e 100644 --- a/config.h +++ b/config.h @@ -253,6 +253,12 @@ void git_config_set_in_file(const char *, const char *, const char *); int git_config_set_gently(const char *, const char *); +/** + * Write a config value into the config.worktree file for the current + * worktree. This will initialize extensions.worktreeConfig if necessary. + */ +int repo_config_set_worktree_gently(struct repository *, const char *, const char *); + /** * write config values to `.git/config`, takes a key/value pair as parameter. */ From patchwork Mon Dec 20 15:57:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12688165 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0104C433FE for ; Mon, 20 Dec 2021 15:57:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237835AbhLTP5b (ORCPT ); Mon, 20 Dec 2021 10:57:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237792AbhLTP5a (ORCPT ); Mon, 20 Dec 2021 10:57:30 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5646C061574 for ; Mon, 20 Dec 2021 07:57:29 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id t18so20977582wrg.11 for ; Mon, 20 Dec 2021 07:57:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=ygHQYgXnIJEpJwZ5HKT23OLaaY3ZiHMixagGnCWrzyo=; b=X4+laB3hgz/xEsbTAN7hCMlw8cj9gQ9ugRbfRq/jxOOQ/hxf8KcuyyAtcPPNcosr6S p9pfFPZwOYYjzslRldyfmnUU/Zcsj/omkmqpT7sdydz3t92t7fraAIJzpr8xYpbXpNCR RW+u50/4mgp72xWryZXX4GdnwlFOQ0TOW0GTuI9/XC6frA5OnfhCNC5synAukIQI2mF7 mrFCxXSDbUYGHsv36H+H4i+wBKlXTqWzDxY3UG0tKZbEgD4RmyUn1JoVTsZk28tkBqKO B9b9XAlip9LcrgDZbY16EZgIGVa0mle/1ll+DdNxOt92PIqHIGV71a0I5jmbjpGe0pR4 3Vng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=ygHQYgXnIJEpJwZ5HKT23OLaaY3ZiHMixagGnCWrzyo=; b=NjNNX25OnLL9Jw9MpJMpXT6wfFeMNI9Han1gDTufFU5BQzmUioEtbzpRAeHGia5KOx O2T7tuLM0kMYr3oWgYV6JqLw5jAZHM7XWZVH93q9hwHFVdT+QXp6GQ+JskEYIKUQz4cI 7rntfHDTYg7p5EGv0QoG7+gCPs1+QYvWFtS4QnEpdpWNQH0mmjJvuTOeLx1XtbgaYTfM BFNaU09B0CiRgYa/l67Frdl5J5tZ0tJ77UUY7hwVU8Uc+Q0GIwqN0rLYGt7fp8WBzzx2 kEgL/AJkrCt/iioXyyoJe0Nsv4Sg1lBI1o+VC52j0+pYZJrSPMotHEMRDQDF0ldaGWTT bHmQ== X-Gm-Message-State: AOAM533r6fnH1CHpd9KTN1yKTIjVz2UOTduRutseJQ36G737/90Qbe3K W/WmF5drEyx7Z77yhiW9UhhgQIE61VE= X-Google-Smtp-Source: ABdhPJwPWA4nV3rx0bZhLBBpCP6W6me56s/20q4W2oDSpdvg6LrV+p+ECUXw/kjGkzmS3Y0Ub0wm4w== X-Received: by 2002:a5d:5988:: with SMTP id n8mr13618974wri.309.1640015848358; Mon, 20 Dec 2021 07:57:28 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n15sm10959382wru.66.2021.12.20.07.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 07:57:28 -0800 (PST) Message-Id: <6202f767f4ae8012ce8cdf78d3234eba478d6681.1640015845.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 20 Dec 2021 15:57:24 +0000 Subject: [PATCH 4/4] sparse-checkout: use repo_config_set_worktree_gently() Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: stolee@gmail.com, sunshine@sunshineco.com, allred.sean@gmail.com, gitster@pobox.com, Derrick Stolee , Derrick Stolee Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Derrick Stolee From: Derrick Stolee The previous change added repo_config_set_worktree_gently() to assist writing config values into the worktree.config file, especially when that may not have been initialized. When the base repo is bare, running 'git sparse-checkout init' in a worktree will create the config.worktree file for the worktree, but that will start causing the worktree to parse the bare repo's core.bare=true value and start treating the worktree as bare. This causes more problems as other commands are run in that worktree. The fix is to have this assignment into config.worktree be handled by the repo_config_set_worktree_gently() helper. Reported-by: Sean Allred Helped-by: Eric Sunshine Signed-off-by: Derrick Stolee --- builtin/sparse-checkout.c | 25 ++++++++----------------- sparse-index.c | 10 +++------- t/t1091-sparse-checkout-builtin.sh | 14 +++++++++++++- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 34447f87cd8..ec2c9a146cc 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -356,26 +356,17 @@ enum sparse_checkout_mode { static int set_config(enum sparse_checkout_mode mode) { - const char *config_path; - - if (upgrade_repository_format(the_repository, 1) < 0) - die(_("unable to upgrade repository format to enable worktreeConfig")); - if (git_config_set_gently("extensions.worktreeConfig", "true")) { - error(_("failed to set extensions.worktreeConfig setting")); + if (repo_config_set_worktree_gently(the_repository, + "core.sparseCheckout", + mode ? "true" : "false") || + repo_config_set_worktree_gently(the_repository, + "core.sparseCheckoutCone", + mode == MODE_CONE_PATTERNS ? + "true" : "false")) return 1; - } - - config_path = git_path("config.worktree"); - git_config_set_in_file_gently(config_path, - "core.sparseCheckout", - mode ? "true" : NULL); - - git_config_set_in_file_gently(config_path, - "core.sparseCheckoutCone", - mode == MODE_CONE_PATTERNS ? "true" : NULL); if (mode == MODE_NO_PATTERNS) - set_sparse_index_config(the_repository, 0); + return set_sparse_index_config(the_repository, 0); return 0; } diff --git a/sparse-index.c b/sparse-index.c index a1d505d50e9..e93609999e0 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -99,13 +99,9 @@ static int convert_to_sparse_rec(struct index_state *istate, int set_sparse_index_config(struct repository *repo, int enable) { - int res; - char *config_path = repo_git_path(repo, "config.worktree"); - res = git_config_set_in_file_gently(config_path, - "index.sparse", - enable ? "true" : NULL); - free(config_path); - + int res = repo_config_set_worktree_gently(repo, + "index.sparse", + enable ? "true" : "false"); prepare_repo_settings(repo); repo->settings.sparse_index = enable; return res; diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 272ba1b566b..3ff125c5fd6 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -71,6 +71,18 @@ test_expect_success 'git sparse-checkout init' ' check_files repo a ' +test_expect_success 'init in a worktree of a bare repo' ' + test_when_finished rm -rf bare worktree && + git clone --bare repo bare && + git -C bare worktree add ../worktree && + ( + cd worktree && + git sparse-checkout init && + test_cmp_config false core.bare && + git sparse-checkout set /* + ) +' + test_expect_success 'git sparse-checkout list after init' ' git -C repo sparse-checkout list >actual && cat >expect <<-\EOF && @@ -219,7 +231,7 @@ test_expect_success 'sparse-index enabled and disabled' ' test-tool -C repo read-cache --table >cache && ! grep " tree " cache && git -C repo config --list >config && - ! grep index.sparse config + test_cmp_config -C repo false index.sparse ) '