Skip to content

Commit 85dd6bf

Browse files
rscharfegitster
authored andcommitted
wt-status: use argv_array for environment
Instead of using a PATH_MAX buffer, use argv_array for constructing the environment for git submodule summary. This simplifies the code a bit and removes the arbitrary length limit. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 341e7e8 commit 85dd6bf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

wt-status.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,18 +735,16 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
735735
{
736736
struct child_process sm_summary;
737737
char summary_limit[64];
738-
char index[PATH_MAX];
739-
const char *env[] = { NULL, NULL };
738+
struct argv_array env = ARGV_ARRAY_INIT;
740739
struct argv_array argv = ARGV_ARRAY_INIT;
741740
struct strbuf cmd_stdout = STRBUF_INIT;
742741
struct strbuf summary = STRBUF_INIT;
743742
char *summary_content;
744743
size_t len;
745744

746745
sprintf(summary_limit, "%d", s->submodule_summary);
747-
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
746+
argv_array_pushf(&env, "GIT_INDEX_FILE=%s", s->index_file);
748747

749-
env[0] = index;
750748
argv_array_push(&argv, "submodule");
751749
argv_array_push(&argv, "summary");
752750
argv_array_push(&argv, uncommitted ? "--files" : "--cached");
@@ -758,13 +756,14 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
758756

759757
memset(&sm_summary, 0, sizeof(sm_summary));
760758
sm_summary.argv = argv.argv;
761-
sm_summary.env = env;
759+
sm_summary.env = env.argv;
762760
sm_summary.git_cmd = 1;
763761
sm_summary.no_stdin = 1;
764762
fflush(s->fp);
765763
sm_summary.out = -1;
766764

767765
run_command(&sm_summary);
766+
argv_array_clear(&env);
768767
argv_array_clear(&argv);
769768

770769
len = strbuf_read(&cmd_stdout, sm_summary.out, 1024);

0 commit comments

Comments
 (0)