Skip to content

Commit 5ce9086

Browse files
Oblomovgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 74ae141 commit 5ce9086

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

submodule.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,19 @@ void show_submodule_summary(FILE *f, const char *path,
123123

124124
int is_submodule_modified(const char *path)
125125
{
126-
int len;
126+
int len, i;
127127
struct child_process cp;
128128
const char *argv[] = {
129129
"status",
130130
"--porcelain",
131131
NULL,
132132
};
133-
char *env[4];
133+
const char *env[LOCAL_REPO_ENV_SIZE + 3];
134134
struct strbuf buf = STRBUF_INIT;
135135

136+
for (i = 0; i < LOCAL_REPO_ENV_SIZE; i++)
137+
env[i] = local_repo_env[i];
138+
136139
strbuf_addf(&buf, "%s/.git/", path);
137140
if (!is_directory(buf.buf)) {
138141
strbuf_release(&buf);
@@ -143,16 +146,14 @@ int is_submodule_modified(const char *path)
143146
strbuf_reset(&buf);
144147

145148
strbuf_addf(&buf, "GIT_WORK_TREE=%s", path);
146-
env[0] = strbuf_detach(&buf, NULL);
149+
env[i++] = strbuf_detach(&buf, NULL);
147150
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;
152153

153154
memset(&cp, 0, sizeof(cp));
154155
cp.argv = argv;
155-
cp.env = (const char *const *)env;
156+
cp.env = env;
156157
cp.git_cmd = 1;
157158
cp.no_stdin = 1;
158159
cp.out = -1;
@@ -165,9 +166,8 @@ int is_submodule_modified(const char *path)
165166
if (finish_command(&cp))
166167
die("git status --porcelain failed");
167168

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]);
171171
strbuf_release(&buf);
172172
return len != 0;
173173
}

0 commit comments

Comments
 (0)