is_submodule_modified(): clear environment properly
Rather than only clearing GIT_INDEX_FILE, take the list of environment variables to clear from local_repo_env, appending the settings for GIT_DIR and GIT_WORK_TREE. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Giuseppe Bilotta committed
Feb 25, 2010 at 00:34 UTC
5ce9086ddfe6931ef34fcd99778c9235e2ee1839
1 file changed
+11
-11
submodule.c
+11
-11
@@ -123,16 +123,19 @@ void show_submodule_summary(FILE *f, const char *path,
123
124
int is_submodule_modified(const char *path)
125
{
126
- int len;
126
+ int len, i;
127
struct child_process cp;
128
const char *argv[] = {
129
"status",
130
"--porcelain",
131
NULL,
132
};
133
- char *env[4];
133
+ const char *env[LOCAL_REPO_ENV_SIZE + 3];
134
struct strbuf buf = STRBUF_INIT;
135
136
+ for (i = 0; i < LOCAL_REPO_ENV_SIZE; i++)
137
+ env[i] = local_repo_env[i];
138
+
139
strbuf_addf(&buf, "%s/.git/", path);
140
if (!is_directory(buf.buf)) {
141
strbuf_release(&buf);
@@ -143,16 +146,14 @@ int is_submodule_modified(const char *path)
146
strbuf_reset(&buf);
147
148
strbuf_addf(&buf, "GIT_WORK_TREE=%s", path);
146
- env[0] = strbuf_detach(&buf, NULL);
149
+ env[i++] = strbuf_detach(&buf, NULL);
150
strbuf_addf(&buf, "GIT_DIR=%s/.git", path);
148
- env[1] = strbuf_detach(&buf, NULL);
149
- strbuf_addf(&buf, "GIT_INDEX_FILE");
150
- env[2] = strbuf_detach(&buf, NULL);
151
- env[3] = NULL;
151
+ env[i++] = strbuf_detach(&buf, NULL);
152
+ env[i] = NULL;
153
154
memset(&cp, 0, sizeof(cp));
155
cp.argv = argv;
155
- cp.env = (const char *const *)env;
156
+ cp.env = env;
157
cp.git_cmd = 1;
158
cp.no_stdin = 1;
159
cp.out = -1;
@@ -165,9 +166,8 @@ int is_submodule_modified(const char *path)
166
if (finish_command(&cp))
167
die("git status --porcelain failed");
168
168
- free(env[0]);
169
- free(env[1]);
170
- free(env[2]);
169
+ for (i = LOCAL_REPO_ENV_SIZE; env[i]; i++)
170
+ free((char *)env[i]);
171
strbuf_release(&buf);
172
return len != 0;
173
}