From patchwork Tue Dec 21 19:14:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12690427 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 395CEC433F5 for ; Tue, 21 Dec 2021 19:14:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237371AbhLUTOM (ORCPT ); Tue, 21 Dec 2021 14:14:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237369AbhLUTOL (ORCPT ); Tue, 21 Dec 2021 14:14:11 -0500 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 8DAA1C061574 for ; Tue, 21 Dec 2021 11:14:11 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id c4so9264wrd.9 for ; Tue, 21 Dec 2021 11:14:11 -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=qRbO5kEI7ulB62J68+Rxy0FRIO5neWShsx9oW293kNenj04kdG88n/4935E9jb61h9 Nl5Z/QehVhrBXQX3cMgjVmhXPM7MfsQeKUUMx9B3h7PTvcYkbcJrq7pFHjC/yk9qniE1 pOI4qD4p3bhFIietQecIR9wEtQIpSlkU5n3W0KCZgKqtyMR5IPUWIBgJXu8X4eOXEtnB XDmZ4qCvd9jXciXaIfeuuF42FZh3O9aee6vm0TVuynRxHG1nJItSOauEsk4nF3Ut8b+k zxaUoz4km22KEiKQaQY154UWC6OnemJWw5TksT9ZlrjWaR47o7lZm3mi+EdtEfqMGenv mY6g== 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=H4i5zkJqHnMa5yODaiCR7mHkLAVxLuRF6s+w2aXeq223/5y5K3HsKEG6IBx6L+FJ1l PhOkFiVqdZPGlVd9Q5pXzcAKIOmFoYjQEt/PEdKHqsU7C/RrZ2AJkyiXq4h245fwaF9V 0Y6B2tk87SEOxx0Jxzl6O6LdnZH3+huAUCe9EJZDAIxP9POybzo2rgvr6aEqxFLpONpw paHibdnKzxQNGChldRnKR6wM4f6uruutPs0pxqH4YXugTcTKdl8ydl4FfFW6N5xrxrEz QHfZ4n8h73+J6UeZHxfZRPGAbNNpJ8gZY9Wmtaosa7zq3ScVhV/2UCa0aptYvQEsZ7h1 0fTg== X-Gm-Message-State: AOAM531iBGeTWMCq7oHz7SJkZEEQMazaeIXaM+niXsaVhVE5mebCs9Xk cwsUl1H1aXpibQHrUFaN7z8GxE97EOw= X-Google-Smtp-Source: ABdhPJwNNzir40Lk7eKHfpvdh3FFtOegFH2Rzcgi6f02xgD5/SrqE+rpIsmhDb3UwQp/1VFEwrD81Q== X-Received: by 2002:adf:f54e:: with SMTP id j14mr3704490wrp.442.1640114050002; Tue, 21 Dec 2021 11:14:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o13sm3313969wms.17.2021.12.21.11.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 11:14:09 -0800 (PST) Message-Id: <889e69dc45d0b02e8207a39e321c7a752bdb2532.1640114048.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 21 Dec 2021 19:14:04 +0000 Subject: [PATCH v2 1/5] 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 Tue Dec 21 19:14:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12690429 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 D43C6C433FE for ; Tue, 21 Dec 2021 19:14:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237392AbhLUTON (ORCPT ); Tue, 21 Dec 2021 14:14:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237369AbhLUTON (ORCPT ); Tue, 21 Dec 2021 14:14:13 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F4F3C061574 for ; Tue, 21 Dec 2021 11:14:12 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id i22so28850366wrb.13 for ; Tue, 21 Dec 2021 11:14:12 -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=h5/zMPYjDErTVP8zyB9GUekVtp+7s1Io++t7XULOxgt4YGG+Ztb5R5Btpc2SqijXMh xSITSu8xJSRex78KjyKreDGRGhGAZrh01qroY+lxSBINgvVve8o+zoh7N59MB3lT+YL/ q8X9JCYxvuFlkWcu1e01gcwfEZquDvV0MTQO9JzeRy4TwJbpcwXIzDPE+/YCYSSZ87cj 4ZuGIqPr8Y1zuNEiXCcSdzZaEL5pJUb0/wZklRM9zU4lPMx6YRcrr5eU3yenr93Q6EMN hY1LWlgDLTMWMF/wn2Y1QT644lIqoUSGZUGtdLa4uHqT0Zxv2a2WtMBlLZO4rfcpL/Br xMgQ== 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=h6Z4bMIrRpX0Jz59lC9GBPkht7bZPxQLqMu+5pkcrFzZOj/yY/QIeTlht5s41D0nIe xheMUcxOhjMSAKWLL5b0V95wHp4hbO/QXvIhs0BnsRrcdLuPefOFLRaw/qa6a7uD0v5Q swsyG7Gt26R6g4hBVucBNKyLfO+yNYHncneRZS4Qg9BqpgB5yxJXEzNhz0JWEyXn8/JO TLNMK4I1OhP7BJeWcXJF8MDSfrqte/yjxkEFLlwtr/p1WjXY1r264VqhZy+hJP+z6+tB 3XVpDCfqMK7VDsGFdy4wDKaDqeDMjh0Pil49ModMtYosBiz+OLbPeSkAwQu+FTWYRMJ0 BFDA== X-Gm-Message-State: AOAM530e0z9od6mXnp1j37SIu8mlb5VtYSs4ThDchlyQRzAsxrPuThjG vA4DbZpqpc+en9LD0p8c3I0Y+vVa6Uc= X-Google-Smtp-Source: ABdhPJwv9vtCw0TwRCJvZ56yZVH5LYyDi387sXR3MnSHaqD5Ns1tMmXk78fcBxwV3qkYLO4V7yaqwg== X-Received: by 2002:a5d:47a3:: with SMTP id 3mr3608550wrb.583.1640114050736; Tue, 21 Dec 2021 11:14:10 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id u13sm3755115wmq.14.2021.12.21.11.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 11:14:10 -0800 (PST) Message-Id: <3e01356815a84c9356f645735adde04906690f02.1640114048.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 21 Dec 2021 19:14:05 +0000 Subject: [PATCH v2 2/5] 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 Tue Dec 21 19:14:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12690431 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 CE9D5C433EF for ; Tue, 21 Dec 2021 19:14:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237407AbhLUTOP (ORCPT ); Tue, 21 Dec 2021 14:14:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237372AbhLUTON (ORCPT ); Tue, 21 Dec 2021 14:14:13 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBFCBC06173F for ; Tue, 21 Dec 2021 11:14:12 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id t18so28827007wrg.11 for ; Tue, 21 Dec 2021 11:14:12 -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=Q7b5qYaiMeO17wO2Ruu/6vA9yEHdyk/xTYzDqPQlbdE=; b=P/OqV7DdygN+SAyJjqM1tWDmsxHjRiYHNfLlT7zgeC+nnee8VPkXOnzJPK1L2fJpjm CO/E4GYFv15MvsG8T4lgjWscogm9o/3KZbP+azNUvrfJbJUMYxl3Wrwm7QBn9FDVzY9M YL9cvZkcLpPPv0v17hUM//XrBKGDwyAbDzICWWMHmLAhuNwzdJR3GcWmDyoZzttB8Aiw NW/rI2AzNNLEFyYkqC4RihpnLw9uA5HAzgI8ZUgSnXRImDvkdrRs6lZNzhiAMJH/cw/o stGvc5W+yNBoscyjJiRw+DG9yxN7Y7P+OcAbAWR6go7n8Se2PMqn9T7NiMCPhQtuTnne E7yA== 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=Q7b5qYaiMeO17wO2Ruu/6vA9yEHdyk/xTYzDqPQlbdE=; b=jzgLJITzlrM1tex2UQf14zNy3sr81fhgStYTXfoOI9JvaJdNHwy7TMunTdilcXNyis jHfjMPGTHgmpp+n+H9fge9fC45x0+0QUsahnFVzJQaB5dFPRgxmejdh8VIeaBE9SStVd tqkxg9vhfJe6DGdcRzSa/ZLOpX0V8hXP1KGhB6y/R3Bv7gUy0yYHeSQjxE/jQdclJUpO eSc+FMG2CYBZ9/uuCOmK8NwE6wHUYI+BLyP7HQyDrTQNqOYgCAOMb/hqY/PCd4F6QN0e lRCh/OqQfDnDCgu240cr4gIgVgF818v7sojJK/BtqQ8zWCMUBIYsfAX8dxnUOkVSAbnI lotg== X-Gm-Message-State: AOAM5324yYyf3xiQNqbmmli/OKwy2Z+ta2kifPMtVNfNQhCNX4cvV5DN +k5mlmSXySRUeeEXdJX02TSheieS+hU= X-Google-Smtp-Source: ABdhPJwwcWvZEpNx8P2KBdXR0Q9fV9ND+k83TAp9AtWbM75EwoaVZVt6gwCvigHj4NYTAXMAlVe64A== X-Received: by 2002:adf:dc0a:: with SMTP id t10mr3875114wri.8.1640114051331; Tue, 21 Dec 2021 11:14:11 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d10sm3176218wri.57.2021.12.21.11.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 11:14:11 -0800 (PST) Message-Id: In-Reply-To: References: Date: Tue, 21 Dec 2021 19:14:06 +0000 Subject: [PATCH v2 3/5] worktree: add upgrade_to_worktree_config() 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 Some features, such as the sparse-checkout builtin, require using the worktree config extension. It might seem simple to upgrade the repository format and add extensions.worktreeConfig, and that is what happens in the sparse-checkout builtin. Transitioning from one config file to multiple has some strange side-effects. In particular, if the base repository is bare and the worktree is not, Git knows to treat the worktree as non-bare as a special case when not using worktree config. Once worktree config is enabled, Git stops that special case since the core.bare setting could apply at the worktree config level. This opens the door for bare worktrees. To help resolve this transition, create upgrade_to_worktree_config() to navigate the intricacies of this operation. In particular, we need to look for core.bare=true within the base config file and move that setting into the core repository's config.worktree file. To gain access to the core repository's config and config.worktree file, we reference a repository struct's 'commondir' member. If the repository was a submodule instead of a worktree, then this still applies correctly. Helped-by: Eric Sunshine Signed-off-by: Derrick Stolee --- worktree.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ worktree.h | 12 ++++++++++++ 2 files changed, 59 insertions(+) diff --git a/worktree.c b/worktree.c index 2c155b10150..e8ddbe2bfcc 100644 --- a/worktree.c +++ b/worktree.c @@ -5,6 +5,7 @@ #include "worktree.h" #include "dir.h" #include "wt-status.h" +#include "config.h" void free_worktrees(struct worktree **worktrees) { @@ -830,3 +831,49 @@ int should_prune_worktree(const char *id, struct strbuf *reason, char **wtpath, *wtpath = path; return 0; } + +int upgrade_to_worktree_config(struct repository *r) +{ + int res; + int bare = 0; + struct config_set cs = { 0 }; + char *base_config_file = xstrfmt("%s/config", r->commondir); + char *base_worktree_file = xstrfmt("%s/config.worktree", r->commondir); + + git_configset_init(&cs); + git_configset_add_file(&cs, base_config_file); + + /* + * If the base repository is bare, then we need to move core.bare=true + * out of the base config file and into the base repository's + * config.worktree file. + */ + if (!git_configset_get_bool(&cs, "core.bare", &bare) && bare) { + if ((res = git_config_set_in_file_gently(base_worktree_file, + "core.bare", "true"))) { + error(_("unable to set core.bare=true in '%s'"), base_worktree_file); + goto cleanup; + } + + if ((res = git_config_set_in_file_gently(base_config_file, + "core.bare", NULL))) { + error(_("unable to unset core.bare=true in '%s'"), base_config_file); + goto cleanup; + } + } + if (upgrade_repository_format(r, 1) < 0) { + res = error(_("unable to upgrade repository format to enable worktreeConfig")); + goto cleanup; + } + if ((res = git_config_set_gently("extensions.worktreeConfig", "true"))) { + error(_("failed to set extensions.worktreeConfig setting")); + goto cleanup; + } + +cleanup: + git_configset_clear(&cs); + free(base_config_file); + free(base_worktree_file); + trace2_printf("returning %d", res); + return res; +} diff --git a/worktree.h b/worktree.h index 8b7c408132d..170b6b1e1f5 100644 --- a/worktree.h +++ b/worktree.h @@ -182,4 +182,16 @@ void strbuf_worktree_ref(const struct worktree *wt, struct strbuf *sb, const char *refname); +/** + * Upgrade the config of the current repository and its base (if different + * from this repository) to use worktree-config. This might adjust config + * in both repositories, including: + * + * 1. Upgrading the repository format version to 1. + * 2. Adding extensions.worktreeConfig to the base config file. + * 3. Moving core.bare=true from the base config file to the base + * repository's config.worktree file. + */ +int upgrade_to_worktree_config(struct repository *r); + #endif From patchwork Tue Dec 21 19:14:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12690433 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 4EC5CC4332F for ; Tue, 21 Dec 2021 19:14:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241719AbhLUTOP (ORCPT ); Tue, 21 Dec 2021 14:14:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237395AbhLUTOO (ORCPT ); Tue, 21 Dec 2021 14:14:14 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D922C061574 for ; Tue, 21 Dec 2021 11:14:13 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id q16so29099wrg.7 for ; Tue, 21 Dec 2021 11:14:13 -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=k+Pm7SGau0A6FfYjEsnntJGGNVfvsDtk+S+0iUpQIRE=; b=XwuJzTzcUcTBqgEj2DMehBbtYD4xgEA9PDDMcWSpPb7iDO2ST9S4GXMpXE0emrOHJh gaLxvdMDAlP2BitjP/Q/OaFqVqZblAvY5lpy9KpRtUrOfeAC4eGOcGu+iTeVrNbGe0Qd tSvcPA0hk7wIjY71xuG7PTA3FJ69AjFZ3LPQN/wc+vicT2ZmHe3nduGj3RtQaJk5jt6x eIacT2M/3IuwDhqKMMtZVbV7naaKOKSQ9q6dNIK+zkpvX19SDUa96GfwZ80mJoPdD48v THDLf07O5JiD7ip0JIaX/hgWhItT9E9LAWdwuBkPAarxMz6NxkvbclWM9wuMbxg2bqb9 Z+ZQ== 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=k+Pm7SGau0A6FfYjEsnntJGGNVfvsDtk+S+0iUpQIRE=; b=3ZTEZAb6JB4aXoIOpSOYsepJEuOyDuWxlan2r3oUTez1aPg5bcSA1CEjMKbebmZ+G5 lVgwnTM17PEtLmpudljSoWwwUquZWokCyC/dZcf3EVwsvCa61igVY7HPsDMlie0Z1irg n3vrmJrdsi5fEjfiZxnMmFQmvICO0d0+sbSrKIJYtUb0Nqjkzu4N+BTHmvWJjwCPPFhC YP845tMmBEub0E8GIgPFq2uZqdOrZjyxX+k6uqJYSI4KMP2xMOhJRvZArsZRBOqymJSE hI2lDCL+ivVlQU/xrtXEUiuEN2Nwmkl5I8rA6L71PA7/Ghijl/+wZgQx+elYPYoF84uM yH+A== X-Gm-Message-State: AOAM531M/+3JdbT3FF7+bPj+D+2wM+9PZIz+v92IOM6U+T6UryPCjIt8 gCzQ9ZRsNmRBdwbs8xcLcDAll3w5gTA= X-Google-Smtp-Source: ABdhPJzjPaTuTtqYIMFRgU+15t72ncL3jB2go/gh4F5/uszPOf6r4ZwJY8jG3MP3eYYGFSakWiVSnw== X-Received: by 2002:adf:f90d:: with SMTP id b13mr3847820wrr.524.1640114052128; Tue, 21 Dec 2021 11:14:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m15sm18900083wrw.27.2021.12.21.11.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 11:14:11 -0800 (PST) Message-Id: <22896e9bb04cdf022cc13468d60808df69a6854f.1640114048.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 21 Dec 2021 19:14:07 +0000 Subject: [PATCH v2 4/5] 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 The previous change added upgrade_to_worktree_config() to assist creating a worktree-specific config for the first time. However, this requires every config writer to care about that upgrade before writing to the worktree-specific config. In addition, callers need to know how to generate the name of the config.worktree file and pass it to the config API. To assist, create a new repo_config_set_worktree_gently() method in the config API that handles the upgrade_to_worktree_config() method in addition to assigning the value in the worktree-specific config. This will be consumed by an upcoming change. Signed-off-by: Derrick Stolee --- config.c | 10 ++++++++++ config.h | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/config.c b/config.c index 9c9eef16018..81f3a689c11 100644 --- a/config.c +++ b/config.c @@ -21,6 +21,7 @@ #include "dir.h" #include "color.h" #include "refs.h" +#include "worktree.h" struct config_source { struct config_source *prev; @@ -2880,6 +2881,15 @@ 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) +{ + return upgrade_to_worktree_config(r) || + git_config_set_multivar_in_file_gently( + repo_git_path(r, "config.worktree"), + 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..b05c51b3528 100644 --- a/config.h +++ b/config.h @@ -253,6 +253,13 @@ 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, + * which might trigger some changes to the root repository's config file. + */ +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 Tue Dec 21 19:14:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12690435 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 30A2DC433FE for ; Tue, 21 Dec 2021 19:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237671AbhLUTOQ (ORCPT ); Tue, 21 Dec 2021 14:14:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237403AbhLUTOP (ORCPT ); Tue, 21 Dec 2021 14:14:15 -0500 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 41C25C06173F for ; Tue, 21 Dec 2021 11:14:14 -0800 (PST) Received: by mail-wr1-x429.google.com with SMTP id c4so9511wrd.9 for ; Tue, 21 Dec 2021 11:14:14 -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=E5s3dvAoFicyBoAUjQuu/VMOk7fwtJ6lZsgxhzhDnIU=; b=UqnOOPusBZ9EyoQvwBhJgOtivOpFq7ewboDzyzyk9t68acAb+l1Ac9zEyiY+hmMAwV HRAXs25UobqkIX+v0qr4w1EIShVfcAInVft+hkYv5ym6YQWKC9V0k2T5J77/gAnFKWY0 8KuAQpLOqe3RCf4KlY3v390VugmLjVGntQ9hsI3EoisYTsghnSqxo7vELnkFo0+ou4dZ j3sFZ0lqXEI19HDWbz+XdGhwy3FDSWa0dIhfke+lrkGNOB7+ZnY51ZcdBUP4sUaD6CCH BwGat2ogLp+S3UmNMHDbZ/mN6ydDrfnGQDPVGfWa2J198mz2KVFfFdKz0AElEQiSs/ZR LsWA== 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=E5s3dvAoFicyBoAUjQuu/VMOk7fwtJ6lZsgxhzhDnIU=; b=NVNnnp12XLBlMHCv2crbL3IEzNX7khb9wdUB7ww4H6ZYvzuyZc4dPytWN4gwT/qzmJ V7Neon8S4iwnNZKu7320wT2OvN3a3rKdH3DOPcYtIIcky/2buBbLkj6ncP8Ri9UYEp1W GepOOTPGgj8qThsr5/8YY01gwCV0rFd2zxjFuMjeL2+HQKEblBg/29vphnfh8Dxe8r3l 7mxjVN4DO9Y3gvYgeEfN0gwtB69ss3EF6u+LQQdaj2A52mBnKwePEnB49ApRFFMINRaL KANTH2ayGQ5DWY0Q2/vpKqKWR1P6BArG0QSb5HiIXTavcfREWrIVY7vjk5Gnn6+KbS2S Oo7w== X-Gm-Message-State: AOAM533+BSSz8YA49CftYCK/JksqDoYnUbYsKLqrHpRMq9T/n38tlfDg 4W5D3oBrkB4hxF6bETjUOqpyxfGD8p4= X-Google-Smtp-Source: ABdhPJxZVmb7l7zwHjCern0mFsctFdelDyibgnNNnO0vtsCpIeUX4kknUq3hmL7HN/B9ZU8sAz8UDg== X-Received: by 2002:adf:d1ef:: with SMTP id g15mr3838257wrd.198.1640114052751; Tue, 21 Dec 2021 11:14:12 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m21sm19187280wrb.2.2021.12.21.11.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 11:14:12 -0800 (PST) Message-Id: <06457fafa78e18b7bb7f6d87408b0759d98344d8.1640114048.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 21 Dec 2021 19:14:08 +0000 Subject: [PATCH v2 5/5] 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 | 16 +++++++++++++++- 3 files changed, 26 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..b563ccfeb36 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -71,6 +71,20 @@ 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_must_fail git config core.bare && + git sparse-checkout set /* + ) && + git -C bare config --list --show-origin >actual && + grep "file:config.worktree core.bare=true" actual +' + test_expect_success 'git sparse-checkout list after init' ' git -C repo sparse-checkout list >actual && cat >expect <<-\EOF && @@ -219,7 +233,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 ) '