threads / patch / 44794

patchsubmodule.c: use GIT_DIR_ENVIRONMENT consistently

Subject: [PATCH] submodule.c: use GIT_DIR_ENVIRONMENT consistently

## tl;dr

4 messages between Dec 30, 2016 and Jan 4, 2017. Diffs are folded; open one to read it.

replies: 3people: 3as markdown or json

Stefan Beller· Dec 30, 2016, 00:47 UTC · lore

In C code we have the luxury of having constants for all the important things that are hard coded. This is the only place in C, that hard codes the git directory environment variable, so fix it.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
  Signed-off-by-the-format-patch-config ;)
  
  This is the only occurrence for "GIT_DIR=" in C, but what about ".git"
  git grep "\.git\"" *.c finds some places, which we may want to convert
  to DEFAULT_GIT_DIR_ENVIRONMENT?
  (mainly things that are newer if I can judge the places correctly
  lots of submodules, worktrees and the no data in ".git" bug AFAICT)
  
  Thanks,
  Stefan
 submodule.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Show changes to submodule.c +2 −1
diff --git a/submodule.c b/submodule.c
index ece17315d6..973b9f3f96 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1333,5 +1333,6 @@ void prepare_submodule_repo_env(struct argv_array *out)
 		if (strcmp(*var, CONFIG_DATA_ENVIRONMENT))
 			argv_array_push(out, *var);
 	}
-	argv_array_push(out, "GIT_DIR=.git");
+	argv_array_push(out, "%s=%s", GIT_DIR_ENVIRONMENT,
+		DEFAULT_GIT_DIR_ENVIRONMENT);
 }
-- 
2.11.0.259.ga95e92af08.dirty
René Scharfe· Dec 30, 2016, 01:36 UTC · re: Stefan Beller · lore

Re: [PATCH] submodule.c: use GIT_DIR_ENVIRONMENT consistently

Am 30.12.2016 um 01:47 schrieb Stefan Beller:
Show 11 quoted lines
> diff --git a/submodule.c b/submodule.c
> index ece17315d6..973b9f3f96 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -1333,5 +1333,6 @@ void prepare_submodule_repo_env(struct argv_array *out)
>  		if (strcmp(*var, CONFIG_DATA_ENVIRONMENT))
>  			argv_array_push(out, *var);
>  	}
> -	argv_array_push(out, "GIT_DIR=.git");
> +	argv_array_push(out, "%s=%s", GIT_DIR_ENVIRONMENT,
> +		DEFAULT_GIT_DIR_ENVIRONMENT);
argv_array_pushf (with added "f") instead?

And indent continued lines to align them with the left parenthesis, like this:

	fn(arg1,
	   arg2);
>  }
>
Stefan Beller· Jan 3, 2017, 18:30 UTC · re: René Scharfe · lore

[PATCHv2] submodule.c: use GIT_DIR_ENVIRONMENT consistently

In C code we have the luxury of having constants for all the important things that are hard coded. This is the only place in C, that hard codes the git directory environment variable, so fix it.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
v2:
  argv_array_pushf and realigned.
v1:
  Signed-off-by-the-format-patch-config ;)
  
  This is the only occurrence for "GIT_DIR=" in C, but what about ".git"
  git grep "\.git\"" *.c finds some places, which we may want to convert
  to DEFAULT_GIT_DIR_ENVIRONMENT?
  (mainly things that are newer if I can judge the places correctly
  lots of submodules, worktrees and the no data in ".git" bug AFAICT)
  
  Thanks,
  Stefan
 submodule.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Show changes to submodule.c +2 −1
diff --git a/submodule.c b/submodule.c
index ece17315d6..973b9f3f96 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1333,5 +1333,6 @@ void prepare_submodule_repo_env(struct argv_array *out)
 		if (strcmp(*var, CONFIG_DATA_ENVIRONMENT))
 			argv_array_push(out, *var);
 	}
-	argv_array_push(out, "GIT_DIR=.git");
+	argv_array_pushf(out, "%s=%s", GIT_DIR_ENVIRONMENT,
+			 DEFAULT_GIT_DIR_ENVIRONMENT);
 }
-- 
2.11.0.259.ga95e92af08.dirty
Jeff King· Jan 4, 2017, 01:18 UTC · re: Stefan Beller · lore

Re: [PATCHv2] submodule.c: use GIT_DIR_ENVIRONMENT consistently

On Tue, Jan 03, 2017 at 10:30:47AM -0800, Stefan Beller wrote:
Show 5 quoted lines
> In C code we have the luxury of having constants for all the important
> things that are hard coded. This is the only place in C, that hard codes
> the git directory environment variable, so fix it.
> 
> Signed-off-by: Stefan Beller <sbeller@google.com>
This looks like a good change to me.
Minor nit: the comma after "C" in your commit message is extraneous. ;)
-Peff

← back to recent threads