threads / patch / 49819

patchSome left-over add-on for bw/config-h

Subject: [PATCH 0/1] Some left-over add-on for bw/config-h

## tl;dr

7 messages between Nov 13, 2018 and Nov 14, 2018. Diffs are folded; open one to read it.

replies: 6people: 3as markdown or json

Johannes Schindelin via GitGitGadget· Nov 13, 2018, 15:05 UTC · lore

Back when bw/config-h was developed (and backported to Git for Windows), I came up with this patch. It seems to not be strictly necessary, but I like the safety of falling back to the Git directory when no common directory is configured (for whatever reason).

Johannes Schindelin (1):
  do_git_config_sequence(): fall back to git_dir if commondir is NULL
 config.c | 2 ++
 1 file changed, 2 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-78%2Fdscho%2Fbw%2Fconfig-h-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-78/dscho/bw/config-h-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/78
-- 
gitgitgadget
Johannes Schindelin via GitGitGadget· Nov 13, 2018, 15:05 UTC · re: Johannes Schindelin via GitGitGadget · lore

[PATCH 1/1] do_git_config_sequence(): fall back to git_dir if commondir is NULL

From: Johannes Schindelin <johannes.schindelin@gmx.de>
Just some defensive programming.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 config.c | 2 ++
 1 file changed, 2 insertions(+)
Show changes to config.c +2 −0
diff --git a/config.c b/config.c
index 4051e38823..279d0d7077 100644
--- a/config.c
+++ b/config.c
@@ -1676,6 +1676,8 @@ static int do_git_config_sequence(const struct config_options *opts,
 
 	if (opts->commondir)
 		repo_config = mkpathdup("%s/config", opts->commondir);
+	else if (opts->git_dir)
+		repo_config = mkpathdup("%s/config", opts->git_dir);
 	else
 		repo_config = NULL;
 
-- 
gitgitgadget
Junio C Hamano· Nov 14, 2018, 05:52 UTC · re: Johannes Schindelin via GitGitGadget · lore

Re: [PATCH 0/1] Some left-over add-on for bw/config-h

"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Back when bw/config-h was developed (and backported to Git for Windows), I
> came up with this patch. It seems to not be strictly necessary, but I like
> the safety of falling back to the Git directory when no common directory is
> configured (for whatever reason).

Shouldn't that be diagnosed as an error with BUG()? That is, if we know there is the current repository, and if commondir is not set, isn't it a bug that we want to look into in the start-up sequence?

The phrase "for whatever reason" makes me wonder if this is truly "defensive programming", rather than just sweeping the bug under the rug.

FWIW, with this toy patch applied on top of this patch, all tests that I usually run seem to pass.

 config.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to config.c +1 −1
diff --git a/config.c b/config.c
index c5726af14d..e667e2ebce 100644
--- a/config.c
+++ b/config.c
@@ -1669,7 +1669,7 @@ static int do_git_config_sequence(const struct config_options *opts,
 	if (opts->commondir)
 		repo_config = mkpathdup("%s/config", opts->commondir);
 	else if (opts->git_dir)
-		repo_config = mkpathdup("%s/config", opts->git_dir);
+		BUG("git-dir exists but no commondir?");
 	else
 		repo_config = NULL;
 
Jeff King· Nov 14, 2018, 07:31 UTC · re: Junio C Hamano · lore

Re: [PATCH 0/1] Some left-over add-on for bw/config-h

On Wed, Nov 14, 2018 at 02:52:24PM +0900, Junio C Hamano wrote:
Show 18 quoted lines
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
> 
> > Back when bw/config-h was developed (and backported to Git for Windows), I
> > came up with this patch. It seems to not be strictly necessary, but I like
> > the safety of falling back to the Git directory when no common directory is
> > configured (for whatever reason).
> 
> Shouldn't that be diagnosed as an error with BUG()?  That is, if we
> know there is the current repository, and if commondir is not set,
> isn't it a bug that we want to look into in the start-up sequence?
> 
> The phrase "for whatever reason" makes me wonder if this is truly
> "defensive programming", rather than just sweeping the bug under the
> rug.
> 
> FWIW, with this toy patch applied on top of this patch, all tests
> that I usually run seem to pass.

Heh, I independently made the same change after reading the patch and came here to report similar results.

I think the key thing here is that git_dir is never meant to be used as a source for config. It is there to let the "includeIf gitdir" directive work. So it would indeed be surprising and a bug if we had one but not the other.

-Peff
Johannes Schindelin via GitGitGadget· Nov 14, 2018, 13:59 UTC · re: Johannes Schindelin via GitGitGadget · lore

[PATCH v2 0/1] Some left-over add-on for bw/config-h

Back when bw/config-h was developed (and backported to Git for Windows), I came up with a patch to use git_dir if commondir is NULL, and contributed that as v1 of this patch. However, it was deemed a bug if that happens, so let's instead detect that condition and report it.

Change since v1:
 * Be loud about this bug instead of papering over it.
Johannes Schindelin (1):
  config: report a bug if git_dir exists without commondir
 config.c | 2 ++
 1 file changed, 2 insertions(+)
base-commit: 8858448bb49332d353febc078ce4a3abcc962efe
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-78%2Fdscho%2Fbw%2Fconfig-h-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-78/dscho/bw/config-h-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/78
Range-diff vs v1:
 1:  a3854e4ed8 ! 1:  0767f98378 do_git_config_sequence(): fall back to git_dir if commondir is NULL
     @@ -1,8 +1,9 @@
      Author: Johannes Schindelin <johannes.schindelin@gmx.de>
      
     -    do_git_config_sequence(): fall back to git_dir if commondir is NULL
     +    config: report a bug if git_dir exists without commondir
      
     -    Just some defensive programming.
     +    This did happen at some stage, and was fixed relatively quickly. Make
     +    sure that we detect very quickly, too, should that happen again.
      
          Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
      
     @@ -14,7 +15,7 @@
       	if (opts->commondir)
       		repo_config = mkpathdup("%s/config", opts->commondir);
      +	else if (opts->git_dir)
     -+		repo_config = mkpathdup("%s/config", opts->git_dir);
     ++		BUG("git_dir without commondir");
       	else
       		repo_config = NULL;
       
-- 
gitgitgadget
Johannes Schindelin via GitGitGadget· Nov 14, 2018, 13:59 UTC · re: Johannes Schindelin via GitGitGadget · lore

[PATCH v2 1/1] config: report a bug if git_dir exists without commondir

From: Johannes Schindelin <johannes.schindelin@gmx.de>

This did happen at some stage, and was fixed relatively quickly. Make sure that we detect very quickly, too, should that happen again.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 config.c | 2 ++
 1 file changed, 2 insertions(+)
Show changes to config.c +2 −0
diff --git a/config.c b/config.c
index 4051e38823..db6b0167c6 100644
--- a/config.c
+++ b/config.c
@@ -1676,6 +1676,8 @@ static int do_git_config_sequence(const struct config_options *opts,
 
 	if (opts->commondir)
 		repo_config = mkpathdup("%s/config", opts->commondir);
+	else if (opts->git_dir)
+		BUG("git_dir without commondir");
 	else
 		repo_config = NULL;
 
-- 
gitgitgadget
Jeff King· Nov 14, 2018, 21:42 UTC · re: Johannes Schindelin via GitGitGadget · lore

Re: [PATCH v2 1/1] config: report a bug if git_dir exists without commondir

On Wed, Nov 14, 2018 at 05:59:02AM -0800, Johannes Schindelin via GitGitGadget wrote:
Show 20 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> 
> This did happen at some stage, and was fixed relatively quickly. Make
> sure that we detect very quickly, too, should that happen again.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  config.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/config.c b/config.c
> index 4051e38823..db6b0167c6 100644
> --- a/config.c
> +++ b/config.c
> @@ -1676,6 +1676,8 @@ static int do_git_config_sequence(const struct config_options *opts,
>  
>  	if (opts->commondir)
>  		repo_config = mkpathdup("%s/config", opts->commondir);
> +	else if (opts->git_dir)
> +		BUG("git_dir without commondir");
Yeah, I think this is the right thing to do. Thanks!
-Peff

← back to recent threads