difftool: use "env_array" to simplify memory management
Amend code added in 03831ef7b50 (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>
Ævar Arnfjörð Bjarmason committed
Nov 25, 2021 at 23:52 UTC
26a15355d60a0a5be08250512c05e1447036dce3
1 file changed
+4
-10
builtin/difftool.c
+4
-10
@@ -202,15 +202,10 @@ static void changed_files(struct hashmap *result, const char *index_path,
202
{
203
struct child_process update_index = CHILD_PROCESS_INIT;
204
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());
207
FILE *fp;
208
211
- strbuf_addf(&index_env, "GIT_INDEX_FILE=%s", index_path);
212
- env[0] = index_env.buf;
213
-
209
strvec_pushl(&update_index.args,
210
"--git-dir", git_dir, "--work-tree", workdir,
211
"update-index", "--really-refresh", "-q",
@@ -222,7 +217,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
217
update_index.use_shell = 0;
218
update_index.clean_on_exit = 1;
219
update_index.dir = workdir;
225
- update_index.env = env;
220
+ strvec_pushf(&update_index.env_array, "GIT_INDEX_FILE=%s", index_path);
221
/* Ignore any errors of update-index */
222
run_command(&update_index);
223
@@ -235,7 +230,7 @@ static void changed_files(struct hashmap *result, const char *index_path,
230
diff_files.clean_on_exit = 1;
231
diff_files.out = -1;
232
diff_files.dir = workdir;
238
- diff_files.env = env;
233
+ strvec_pushf(&diff_files.env_array, "GIT_INDEX_FILE=%s", index_path);
234
if (start_command(&diff_files))
235
die("could not obtain raw diff");
236
fp = xfdopen(diff_files.out, "r");
@@ -248,7 +243,6 @@ static void changed_files(struct hashmap *result, const char *index_path,
243
fclose(fp);
244
if (finish_command(&diff_files))
245
die("diff-files did not exit properly");
251
- strbuf_release(&index_env);
246
strbuf_release(&buf);
247
}
248