# [PATCH] submodule.c: use GIT_DIR_ENVIRONMENT consistently

4 messages from 2016-12-30 to 2017-01-04. Participants: Stefan Beller, René Scharfe, Jeff King.
Thread: https://gitlist.dev/t/44794

## Stefan Beller, 2016-12-30 00:47

Subject: [PATCH] submodule.c: use GIT_DIR_ENVIRONMENT consistently
Message-ID: <20161230004739.19144-1-sbeller@google.com>
URL: https://gitlist.dev/e/20161230004739.19144-1-sbeller%40google.com

```
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(-)

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, 2016-12-30 01:36

Subject: Re: [PATCH] submodule.c: use GIT_DIR_ENVIRONMENT consistently
Message-ID: <6dd0a31e-d877-5311-37ef-313ed9ab9716@web.de>
URL: https://gitlist.dev/e/6dd0a31e-d877-5311-37ef-313ed9ab9716%40web.de
In-Reply-To: <20161230004739.19144-1-sbeller@google.com>

```
Am 30.12.2016 um 01:47 schrieb Stefan Beller:
> 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, 2017-01-03 18:30

Subject: [PATCHv2] submodule.c: use GIT_DIR_ENVIRONMENT consistently
Message-ID: <20170103183047.17968-1-sbeller@google.com>
URL: https://gitlist.dev/e/20170103183047.17968-1-sbeller%40google.com
In-Reply-To: <6dd0a31e-d877-5311-37ef-313ed9ab9716@web.de>

```
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(-)

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, 2017-01-04 01:18

Subject: Re: [PATCHv2] submodule.c: use GIT_DIR_ENVIRONMENT consistently
Message-ID: <20170104011841.bpoiqvi5hqsdqu7y@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20170104011841.bpoiqvi5hqsdqu7y%40sigill.intra.peff.net
In-Reply-To: <20170103183047.17968-1-sbeller@google.com>

```
On Tue, Jan 03, 2017 at 10:30:47AM -0800, Stefan Beller wrote:

> 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

```
