Skip to content

Commit 26a1535

Browse files
avargitster
authored andcommitted
difftool: use "env_array" to simplify memory management
Amend code added in 03831ef (difftool: implement the functionality in the builtin, 2017-01-19) to use the "env_array" in the run_command.[ch] API. Now we no longer need to manage our own "index_env" buffer. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d3b2159 commit 26a1535

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

builtin/difftool.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,10 @@ static void changed_files(struct hashmap *result, const char *index_path,
202202
{
203203
struct child_process update_index = CHILD_PROCESS_INIT;
204204
struct child_process diff_files = CHILD_PROCESS_INIT;
205-
struct strbuf index_env = STRBUF_INIT, buf = STRBUF_INIT;
206-
const char *git_dir = absolute_path(get_git_dir()), *env[] = {
207-
NULL, NULL
208-
};
205+
struct strbuf buf = STRBUF_INIT;
206+
const char *git_dir = absolute_path(get_git_dir());
209207
FILE *fp;
210208

211-
strbuf_addf(&index_env, "GIT_INDEX_FILE=%s", index_path);
212-
env[0] = index_env.buf;
213-
214209
strvec_pushl(&update_index.args,
215210
"--git-dir", git_dir, "--work-tree", workdir,
216211
"update-index", "--really-refresh", "-q",
@@ -222,7 +217,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
222217
update_index.use_shell = 0;
223218
update_index.clean_on_exit = 1;
224219
update_index.dir = workdir;
225-
update_index.env = env;
220+
strvec_pushf(&update_index.env_array, "GIT_INDEX_FILE=%s", index_path);
226221
/* Ignore any errors of update-index */
227222
run_command(&update_index);
228223

@@ -235,7 +230,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
235230
diff_files.clean_on_exit = 1;
236231
diff_files.out = -1;
237232
diff_files.dir = workdir;
238-
diff_files.env = env;
233+
strvec_pushf(&diff_files.env_array, "GIT_INDEX_FILE=%s", index_path);
239234
if (start_command(&diff_files))
240235
die("could not obtain raw diff");
241236
fp = xfdopen(diff_files.out, "r");
@@ -248,7 +243,6 @@ static void changed_files(struct hashmap *result, const char *index_path,
248243
fclose(fp);
249244
if (finish_command(&diff_files))
250245
die("diff-files did not exit properly");
251-
strbuf_release(&index_env);
252246
strbuf_release(&buf);
253247
}
254248

0 commit comments

Comments
 (0)