git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Lehmann <Jens.Lehmann@web.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Subject: [PATCH] is_submodule_modified(): clear environment properly
Date: Tue, 23 Feb 2010 22:47:51 +0100	[thread overview]
Message-ID: <4B844D07.8070406@web.de> (raw)

Only GIT_INDEX_FILE was cleared until now, but other environment variables
have to be cleared too before running git status in a submodule.

And while at it, don't allocate a new strbuf for GIT_INDEX_FILE but use
a string constant instead.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---


I think it makes sense to clear the same environment variables here
as Giuseppe Bilotta's patch did for the git shell commands, even
though i am not aware of any bug reports yet.


 submodule.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/submodule.c b/submodule.c
index 7d70c4f..f5707c2 100644
--- a/submodule.c
+++ b/submodule.c
@@ -130,7 +130,7 @@ int is_submodule_modified(const char *path)
 		"--porcelain",
 		NULL,
 	};
-	char *env[4];
+	char *env[9];
 	struct strbuf buf = STRBUF_INIT;

 	strbuf_addf(&buf, "%s/.git/", path);
@@ -146,9 +146,17 @@ int is_submodule_modified(const char *path)
 	env[0] = strbuf_detach(&buf, NULL);
 	strbuf_addf(&buf, "GIT_DIR=%s/.git", path);
 	env[1] = strbuf_detach(&buf, NULL);
-	strbuf_addf(&buf, "GIT_INDEX_FILE");
-	env[2] = strbuf_detach(&buf, NULL);
-	env[3] = NULL;
+	/*
+	 * Clear repo-local GIT_* environment variables (Also see
+	 * clear_local_git_env() in git-sh-setup.sh)
+	 */
+	env[2] = "GIT_ALTERNATE_OBJECT_DIRECTORIES";
+	env[3] = "GIT_CONFIG";
+	env[4] = "GIT_GRAFT_FILE";
+	env[5] = "GIT_INDEX_FILE";
+	env[6] = "GIT_NO_REPLACE_OBJECTS";
+	env[7] = "GIT_OBJECT_DIRECTORY";
+	env[8] = NULL;

 	memset(&cp, 0, sizeof(cp));
 	cp.argv = argv;
@@ -167,7 +175,6 @@ int is_submodule_modified(const char *path)

 	free(env[0]);
 	free(env[1]);
-	free(env[2]);
 	strbuf_release(&buf);
 	return len != 0;
 }
-- 
1.7.0.199.g508d1.dirty

             reply	other threads:[~2010-02-23 21:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-23 21:47 Jens Lehmann [this message]
2010-02-23 22:13 ` [PATCH] is_submodule_modified(): clear environment properly Giuseppe Bilotta
2010-02-24  3:32   ` Junio C Hamano
2010-02-24  6:43     ` Giuseppe Bilotta

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B844D07.8070406@web.de \
    --to=jens.lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=giuseppe.bilotta@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).