From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.9 required=3.0 tests=AWL,BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 56480203E2 for ; Tue, 26 Jul 2016 00:59:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753389AbcGZA7I (ORCPT ); Mon, 25 Jul 2016 20:59:08 -0400 Received: from mail-io0-f176.google.com ([209.85.223.176]:33073 "EHLO mail-io0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753438AbcGZA7F convert rfc822-to-8bit (ORCPT ); Mon, 25 Jul 2016 20:59:05 -0400 Received: by mail-io0-f176.google.com with SMTP id 38so185938721iol.0 for ; Mon, 25 Jul 2016 17:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ymYMC6s1lLoMqfm+SWuYGRWo037qWr1HuSs+dncL9TA=; b=WY9XNg4oCzpzZB409CNpGVCr7/CapE7ful1jzCo26iDyWoSYth3n3FAUjsceisWKf4 UEhlVejrpOz629/SzDASVcfzWVnjVXtpybuypsYRt3Hr+nvnp3+M+BVNTX9WER3q9ZMl ij+ucLAIF3uEIi+Q/qxEy62BiObW8RKXKRzuVMMwrQmhpVqbUmUlawGpTCuQ2qRIlfsl SmiyQBCXv3A3RBUJy586gFD+R4qgZc6fXA90n7RQOBYARErrOx5pj55fZJ4J6eqD6rSE qUgBLvCEKYnuamriBtxYY/Mtb84SwJ9dv+0yH6J2eZAYyFEarhQT3+FiykpQ1Zvim1Lc K3cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ymYMC6s1lLoMqfm+SWuYGRWo037qWr1HuSs+dncL9TA=; b=Z+k8IpZqURXvkzJuHh3NclI08MQ/bfn2Vmq2azpiYLF2oPIEtSnW17sihN9Ol0hAKC 9/NM5Cm5Vj3hW7TWW1Im7JPSjtSegZNmOpXivoXDyjyvP/AQM5433Cj8eR479UEQakPq +s22QTDMcT9Ew+GunE1GtS9PCwkB6qO1WvnAjZ1nprEad2DVNnJVspp81LHXZE3U/7Qg UArC7Cy/Q+vJHgrBsW8p4euEvGp8IaHlPnb34xHVlw6As8o5Cdw1eRLK3MJhBjXTyPyN k7CNt/OwMUm9NGS/38r3OasR6cnAh5VOjvJjN+ntbDSnJhxBylghJPb1uzW0OeftwK5N eMJg== X-Gm-Message-State: AEkoousNwQSs7oCo76ijAdIS7hWUMJevWC21y5Gz+xhvghVLofbskVLHSUNtjOg6doNrlV2+YVTeeLpyzF42faRa X-Received: by 10.107.144.10 with SMTP id s10mr22387623iod.165.1469494744485; Mon, 25 Jul 2016 17:59:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.128.66 with HTTP; Mon, 25 Jul 2016 17:59:03 -0700 (PDT) In-Reply-To: <20160720172419.25473-2-pclouds@gmail.com> References: <20160720172419.25473-1-pclouds@gmail.com> <20160720172419.25473-2-pclouds@gmail.com> From: Stefan Beller Date: Mon, 25 Jul 2016 17:59:03 -0700 Message-ID: Subject: Re: [PATCH v4 1/4] worktree: add per-worktree config files To: =?UTF-8?B?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Cc: "git@vger.kernel.org" , Max Kirillov , Junio C Hamano , Michael J Gruber , Jens Lehmann , Lars Schneider , Michael Haggerty Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Wed, Jul 20, 2016 at 10:24 AM, Nguyễn Thái Ngọc Duy wrote: > A new repo extension is added, worktreeConfig. When it is present: > > - Repository config reading by default includes $GIT_DIR/config _and_ > $GIT_DIR/config.worktree. "config" file remains shared in multiple > worktree setup. > > - The special treatment for core.bare and core.worktree, to stay > effective only in main worktree, is gone. These config files are > supposed to be in config.worktree. > > This extension is most useful in multiple worktree setup because you > now have an option to store per-worktree config (which is either > .git/config.worktree for main worktree, or > .git/worktrees/xx/config.worktree for linked ones). > > This extension can be used in single worktree mode, even though it's > pretty much useless (but this can happen after you remove all linked > worktrees and move back to single worktree). > > "git config" reads from both "config" and "config.worktree" by default > (i.e. without either --user, --file...) when this extension is > present. Default writes still go to "config", not "config.worktree". A > new option --worktree is added for that (*). > > Since a new repo extension is introduced, existing git binaries should > refuse to access to the repo (both from main and linked worktrees). So > they will not misread the config file (i.e. skip the config.worktree > part). They may still accidentally write to the config file anyway if > they use with "git config --file ". > > This design places a bet on the assumption that the majority of config > variables are shared so it is the default mode. A safer move would be > default writes go to per-worktree file, so that accidental changes are > isolated. > > (*) "git config --worktree" points back to "config" file when this > extension is not present so that it works in any setup. > > Signed-off-by: Nguyễn Thái Ngọc Duy I like the user facing design, but how am I supposed to use it internally? Say I want to read a value preferably from the worktree I'd do a /* * maybe I don't even have to set it to 1 as * the user is supposed to do that? */ repository_format_worktree_config = 1; git_config_get_{string,bool,int} (... as usual ...) and if I want to read the value globally I would set the variable to 0 and read? (I would need to restore it, so I'll have a temporary variable to keep the original value of repository_format_worktree_config) Thanks, Stefan > --- > Documentation/config.txt | 11 ++++- > Documentation/git-config.txt | 26 ++++++++---- > Documentation/git-worktree.txt | 31 ++++++++++++++ > Documentation/gitrepository-layout.txt | 8 ++++ > builtin/config.c | 18 +++++++- > cache.h | 2 + > config.c | 7 ++++ > environment.c | 1 + > setup.c | 5 ++- > t/t2028-worktree-config.sh (new +x) | 77 ++++++++++++++++++++++++++++++++++ > 10 files changed, 175 insertions(+), 11 deletions(-) > create mode 100755 t/t2028-worktree-config.sh > > diff --git a/Documentation/config.txt b/Documentation/config.txt > index 16dc22d..7d64da0 100644 > --- a/Documentation/config.txt > +++ b/Documentation/config.txt > @@ -2,8 +2,9 @@ CONFIGURATION FILE > ------------------ > > The Git configuration file contains a number of variables that affect > -the Git commands' behavior. The `.git/config` file in each repository > -is used to store the configuration for that repository, and > +the Git commands' behavior. The files `.git/config` and optionally > +`config.worktree` (see `extensions.worktreeConfig` below) are each > +repository is used to store the configuration for that repository, and > `$HOME/.gitconfig` is used to store a per-user configuration as > fallback values for the `.git/config` file. The file `/etc/gitconfig` > can be used to store a system-wide default configuration. > @@ -264,6 +265,12 @@ advice.*:: > show directions on how to proceed from the current state. > -- > > +extensions.worktreeConfig:: > + If set, by default "git config" reads from both "config" and > + "config.worktree" file in that order. In multiple working > + directory mode, "config" file is shared while > + "config.worktree" is per-working directory. > + > core.fileMode:: > Tells Git if the executable bit of files in the working tree > is to be honored. > diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt > index f163113..9dfdb6a 100644 > --- a/Documentation/git-config.txt > +++ b/Documentation/git-config.txt > @@ -47,13 +47,15 @@ checks or transformations are performed on the value. > > When reading, the values are read from the system, global and > repository local configuration files by default, and options > -`--system`, `--global`, `--local` and `--file ` can be > -used to tell the command to read from only that location (see <>). > +`--system`, `--global`, `--local`, `--worktree` and > +`--file ` can be used to tell the command to read from only > +that location (see <>). > > When writing, the new value is written to the repository local > configuration file by default, and options `--system`, `--global`, > -`--file ` can be used to tell the command to write to > -that location (you can say `--local` but that is the default). > +`--worktree`, `--file ` can be used to tell the command to > +write to that location (you can say `--local` but that is the > +default). > > This command will fail with non-zero status upon error. Some exit > codes are: > @@ -133,6 +135,11 @@ from all available files. > + > See also <>. > > +--worktree:: > + Similar to `--local` except that `.git/config.worktree` is > + read from or written to if `extensions.worktreeConfig` is > + present. If not it's the same as `--local`. > + > -f config-file:: > --file config-file:: > Use the given config file instead of the one specified by GIT_CONFIG. > @@ -253,6 +260,10 @@ $XDG_CONFIG_HOME/git/config:: > $GIT_DIR/config:: > Repository specific configuration file. > > +$GIT_DIR/config.worktree:: > + This is optional and is only searched when > + `extensions.worktreeConfig` is present in $GIT_DIR/config. > + > If no further options are given, all reading options will read all of these > files that are available. If the global or the system-wide configuration > file are not available they will be ignored. If the repository configuration > @@ -268,9 +279,10 @@ configuration file. Note that this also affects options like `--replace-all` > and `--unset`. *'git config' will only ever change one file at a time*. > > You can override these rules either by command-line options or by environment > -variables. The `--global` and the `--system` options will limit the file used > -to the global or system-wide file respectively. The `GIT_CONFIG` environment > -variable has a similar effect, but you can specify any filename you want. > +variables. The `--global`, `--system` and `--worktree` options will limit > +the file used to the global, system-wide or per-worktree file respectively. > +The `GIT_CONFIG` environment variable has a similar effect, but you > +can specify any filename you want. > > > ENVIRONMENT > diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt > index 7c4cfb0..41350db 100644 > --- a/Documentation/git-worktree.txt > +++ b/Documentation/git-worktree.txt > @@ -111,6 +111,37 @@ OPTIONS > --expire