From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-0.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by dcvr.yhbt.net (Postfix) with ESMTP id 749B41F9FC for ; Tue, 8 Feb 2022 22:25:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386781AbiBHWZL (ORCPT ); Tue, 8 Feb 2022 17:25:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387266AbiBHWS5 (ORCPT ); Tue, 8 Feb 2022 17:18:57 -0500 Received: from pb-smtp21.pobox.com (pb-smtp21.pobox.com [173.228.157.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C78BC0612B8 for ; Tue, 8 Feb 2022 14:18:56 -0800 (PST) Received: from pb-smtp21.pobox.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id CB04B186BC9; Tue, 8 Feb 2022 17:18:55 -0500 (EST) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=KjXTUteIaLZCS8AuLCaaojmhZYU8c5ktNT8rhO 8+Tdc=; b=luRX69/19JE59TVieZYscJGT+7LRpLuuJcCKAAaqhrDi0Fzeb3ekVl 4hUh+S7lMeTM9Kd7rL1HDj4r7bfxLeoAzq6OtlYF94gLms/wVhrvZqV+GSRJEuGP NYGPx3TinkG1HxZb1JL4KN3kNgh5kF3H+z5tCyv8dbOgJUCymb2fw= Received: from pb-smtp21.sea.icgroup.com (unknown [127.0.0.1]) by pb-smtp21.pobox.com (Postfix) with ESMTP id C1E7C186BC8; Tue, 8 Feb 2022 17:18:55 -0500 (EST) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [35.185.212.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp21.pobox.com (Postfix) with ESMTPSA id 2D9C6186BC7; Tue, 8 Feb 2022 17:18:53 -0500 (EST) (envelope-from junio@pobox.com) From: Junio C Hamano To: "Derrick Stolee via GitGitGadget" Cc: git@vger.kernel.org, stolee@gmail.com, sunshine@sunshineco.com, allred.sean@gmail.com, Elijah Newren , Bagas Sanjaya , =?utf-8?Q?Jean-No=C3=ABl?= AVILA , derrickstolee@github.com, Derrick Stolee Subject: Re: [PATCH v6 3/6] config: add repo_config_set_worktree_gently() References: Date: Tue, 08 Feb 2022 14:18:52 -0800 In-Reply-To: (Derrick Stolee via GitGitGadget's message of "Mon, 07 Feb 2022 21:33:00 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 19439BE0-892D-11EC-8D94-CBA7845BAAA9-77302942!pb-smtp21.pobox.com Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org "Derrick Stolee via GitGitGadget" writes: > From: Derrick Stolee > > Some config settings, such as those for sparse-checkout, are likely > intended to only apply to one worktree at a time. To make this write > easier, add a new config API method, repo_config_set_worktree_gently(). > > This method will attempt to write to the worktree-specific config, but > will instead write to the common config file if worktree config is not > enabled. The next change will introduce a consumer of this method. Makes sense. > +int repo_config_set_worktree_gently(struct repository *r, > + const char *key, const char *value) > +{ > + /* Only use worktree-specific config if it is is already enabled. */ > + if (repository_format_worktree_config) { > + char *file = repo_git_path(r, "config.worktree"); > + int ret = git_config_set_multivar_in_file_gently( > + file, key, value, NULL, 0); > + free(file); > + return ret; > + } > + return repo_config_set_multivar_gently(r, key, value, NULL, 0); > +} OK. > @@ -3181,14 +3196,28 @@ 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, > - flags); > + return repo_config_set_multivar_gently(the_repository, key, value, > + value_pattern, flags); > +} Is this an unrelated "morally no-op" change? > +int repo_config_set_multivar_gently(struct repository *r, const char *key, > + const char *value, > + const char *value_pattern, unsigned flags) > +{ > + char *file = repo_git_path(r, "config"); > + int res = git_config_set_multivar_in_file_gently(file, > + key, value, > + value_pattern, > + flags); > + free(file); > + return res; > } OK. > 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, > + git_config_set_multivar_in_file(git_path("config"), > + key, value, value_pattern, > flags); > } Is this an unrelated "morally no-op" change? It might have value to make caller more explicit by reducing the use of "I give NULL, you use 'config' for me", but that doesn't sound related to the addition of set_per_worktree_config_gently() helper. > diff --git a/config.h b/config.h > index f119de01309..1d98ad269bd 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 that should apply to the current worktree. If > + * extensions.worktreeConfig is enabled, then the write will happen in the > + * current worktree's config. Otherwise, write to the common 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. > */ > @@ -281,6 +288,7 @@ 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); > int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, unsigned); > > /**