Re: [PATCH v4 2/2] worktree: add per-worktree config files

2018-10-25 Thread Junio C Hamano
Duy Nguyen  writes:

>> > +extensions.worktreeConfig::
>> > + If set, by default "git config" reads from both "config" and
>> > + "config.worktree" file from GIT_DIR in that order. In
>> > + multiple working directory mode, "config" file is shared while
>> > + "config.worktree" is per-working directory (i.e., it's in
>> > + GIT_COMMON_DIR/worktrees//config.worktree)
>> > +
>>
>> This obviously conflicts with your 59-patch series, but more
>> importantly
>>
>>  - I notice that this is the only description of extensions.* key in
>>the configuration files.  Don't we have any other extension
>>defined, and if so shouldn't we be describing them already (not
>>as a part of this series, obviously)?
>
> Right. We have two extensions already but it's described in
> technical/repository-format.txt. I'll move this extension there
> because it's written "This document will serve as the master list for
> extensions." in that document.
>
>>  - If we are going to describe other extensions.* keys, do we want
>>extensions-config.txt file to split this (and others) out and
>>later rename it to config/extensions.txt?  Or do we want to
>>collect related things together by logically not by name and have
>>this extension described in config/worktree.txt instead, perhaps
>>separate from other extensions.* keys?
>
> I think we would go with config/extensions.txt because if grouping
> logically, I'm not sure where extensions.preciousObjects and
> extensions.partialClone would go.

OK, that sounds sensible.

Other than that, I am getting the feeling that everybody agrees that
the problem this topic addresses is worth addressing, and the design
and the implementation of the solution presented here is sensible.

If so, let's move it forward to 'next' and plan to merge it down to
'master'.  The "extensions.*" description can happen incrementally,.
I'd think.



Re: [PATCH v4 2/2] worktree: add per-worktree config files

2018-10-22 Thread Duy Nguyen
On Mon, Oct 22, 2018 at 6:54 AM Junio C Hamano  wrote:
>
> Nguyễn Thái Ngọc Duy   writes:
>
> > diff --git a/Documentation/config.txt b/Documentation/config.txt
> > index 552827935a..244560a35e 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) in each
> > +repository are 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.
> > @@ -371,6 +372,13 @@ advice.*::
> >   editor input from the user.
> >  --
> >
> > +extensions.worktreeConfig::
> > + If set, by default "git config" reads from both "config" and
> > + "config.worktree" file from GIT_DIR in that order. In
> > + multiple working directory mode, "config" file is shared while
> > + "config.worktree" is per-working directory (i.e., it's in
> > + GIT_COMMON_DIR/worktrees//config.worktree)
> > +
>
> This obviously conflicts with your 59-patch series, but more
> importantly
>
>  - I notice that this is the only description of extensions.* key in
>the configuration files.  Don't we have any other extension
>defined, and if so shouldn't we be describing them already (not
>as a part of this series, obviously)?

Right. We have two extensions already but it's described in
technical/repository-format.txt. I'll move this extension there
because it's written "This document will serve as the master list for
extensions." in that document.

>  - If we are going to describe other extensions.* keys, do we want
>extensions-config.txt file to split this (and others) out and
>later rename it to config/extensions.txt?  Or do we want to
>collect related things together by logically not by name and have
>this extension described in config/worktree.txt instead, perhaps
>separate from other extensions.* keys?

I think we would go with config/extensions.txt because if grouping
logically, I'm not sure where extensions.preciousObjects and
extensions.partialClone would go.
-- 
Duy


Re: [PATCH v4 2/2] worktree: add per-worktree config files

2018-10-21 Thread Junio C Hamano
Nguyễn Thái Ngọc Duy   writes:

> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 552827935a..244560a35e 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) in each
> +repository are 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.
> @@ -371,6 +372,13 @@ advice.*::
>   editor input from the user.
>  --
>  
> +extensions.worktreeConfig::
> + If set, by default "git config" reads from both "config" and
> + "config.worktree" file from GIT_DIR in that order. In
> + multiple working directory mode, "config" file is shared while
> + "config.worktree" is per-working directory (i.e., it's in
> + GIT_COMMON_DIR/worktrees//config.worktree)
> +

This obviously conflicts with your 59-patch series, but more
importantly

 - I notice that this is the only description of extensions.* key in
   the configuration files.  Don't we have any other extension
   defined, and if so shouldn't we be describing them already (not
   as a part of this series, obviously)?

 - If we are going to describe other extensions.* keys, do we want
   extensions-config.txt file to split this (and others) out and
   later rename it to config/extensions.txt?  Or do we want to
   collect related things together by logically not by name and have
   this extension described in config/worktree.txt instead, perhaps
   separate from other extensions.* keys?



[PATCH v4 2/2] worktree: add per-worktree config files

2018-10-21 Thread Nguyễn Thái Ngọc Duy
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 settings 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 and there is only one worktree so that it
works in any both single and multiple worktree setups.

Signed-off-by: Nguyễn Thái Ngọc Duy 
---
 Documentation/config.txt   | 12 +++-
 Documentation/git-config.txt   | 26 ++---
 Documentation/git-worktree.txt | 33 +++
 Documentation/gitrepository-layout.txt |  8 +++
 builtin/config.c   | 19 ++-
 cache.h|  2 +
 config.c   | 11 
 environment.c  |  1 +
 setup.c| 40 ++---
 t/t2029-worktree-config.sh | 79 ++
 10 files changed, 213 insertions(+), 18 deletions(-)
 create mode 100755 t/t2029-worktree-config.sh

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 552827935a..244560a35e 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) in each
+repository are 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.
@@ -371,6 +372,13 @@ advice.*::
editor input from the user.
 --
 
+extensions.worktreeConfig::
+   If set, by default "git config" reads from both "config" and
+   "config.worktree" file from GIT_DIR in that order. In
+   multiple working directory mode, "config" file is shared while
+   "config.worktree" is per-working directory (i.e., it's in
+   GIT_COMMON_DIR/worktrees//config.worktree)
+
 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 5e87d82933..1bfe9f56a7 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -45,13 +45,15 @@ unset an existing `--type` specifier with `--no-type`.
 
 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:
@@ -131,6 +133,11 @@