stash: replace all `write-tree` child processes with API calls

Avoid spawning write-tree child processes by replacing the calls with
in-core API calls.

Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Paul-Sebastian Ungureanu 2019-02-25 23:16:27 +00:00 committed by Junio C Hamano
parent ef0f0b4509
commit 48ee24ab72
1 changed files with 12 additions and 29 deletions

View File

@ -943,9 +943,8 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
{ {
int ret = 0; int ret = 0;
struct strbuf untracked_msg = STRBUF_INIT; struct strbuf untracked_msg = STRBUF_INIT;
struct strbuf out = STRBUF_INIT;
struct child_process cp_upd_index = CHILD_PROCESS_INIT; struct child_process cp_upd_index = CHILD_PROCESS_INIT;
struct child_process cp_write_tree = CHILD_PROCESS_INIT; struct index_state istate = { NULL };


cp_upd_index.git_cmd = 1; cp_upd_index.git_cmd = 1;
argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add", argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add",
@ -960,15 +959,11 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
goto done; goto done;
} }


cp_write_tree.git_cmd = 1; if (write_index_as_tree(&info->u_tree, &istate, stash_index_path.buf, 0,
argv_array_push(&cp_write_tree.args, "write-tree"); NULL)) {
argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s",
stash_index_path.buf);
if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) {
ret = -1; ret = -1;
goto done; goto done;
} }
get_oid_hex(out.buf, &info->u_tree);


if (commit_tree(untracked_msg.buf, untracked_msg.len, if (commit_tree(untracked_msg.buf, untracked_msg.len,
&info->u_tree, NULL, &info->u_commit, NULL, NULL)) { &info->u_tree, NULL, &info->u_commit, NULL, NULL)) {
@ -977,8 +972,8 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg,
} }


done: done:
discard_index(&istate);
strbuf_release(&untracked_msg); strbuf_release(&untracked_msg);
strbuf_release(&out);
remove_path(stash_index_path.buf); remove_path(stash_index_path.buf);
return ret; return ret;
} }
@ -987,11 +982,10 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
struct strbuf *out_patch, int quiet) struct strbuf *out_patch, int quiet)
{ {
int ret = 0; int ret = 0;
struct strbuf out = STRBUF_INIT;
struct child_process cp_read_tree = CHILD_PROCESS_INIT; struct child_process cp_read_tree = CHILD_PROCESS_INIT;
struct child_process cp_add_i = CHILD_PROCESS_INIT; struct child_process cp_add_i = CHILD_PROCESS_INIT;
struct child_process cp_write_tree = CHILD_PROCESS_INIT;
struct child_process cp_diff_tree = CHILD_PROCESS_INIT; struct child_process cp_diff_tree = CHILD_PROCESS_INIT;
struct index_state istate = { NULL };


remove_path(stash_index_path.buf); remove_path(stash_index_path.buf);


@ -1017,17 +1011,12 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
} }


/* State of the working tree. */ /* State of the working tree. */
cp_write_tree.git_cmd = 1; if (write_index_as_tree(&info->w_tree, &istate, stash_index_path.buf, 0,
argv_array_push(&cp_write_tree.args, "write-tree"); NULL)) {
argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s",
stash_index_path.buf);
if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) {
ret = -1; ret = -1;
goto done; goto done;
} }


get_oid_hex(out.buf, &info->w_tree);

cp_diff_tree.git_cmd = 1; cp_diff_tree.git_cmd = 1;
argv_array_pushl(&cp_diff_tree.args, "diff-tree", "-p", "HEAD", argv_array_pushl(&cp_diff_tree.args, "diff-tree", "-p", "HEAD",
oid_to_hex(&info->w_tree), "--", NULL); oid_to_hex(&info->w_tree), "--", NULL);
@ -1043,7 +1032,7 @@ static int stash_patch(struct stash_info *info, struct pathspec ps,
} }


done: done:
strbuf_release(&out); discard_index(&istate);
remove_path(stash_index_path.buf); remove_path(stash_index_path.buf);
return ret; return ret;
} }
@ -1053,9 +1042,8 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
int ret = 0; int ret = 0;
struct rev_info rev; struct rev_info rev;
struct child_process cp_upd_index = CHILD_PROCESS_INIT; struct child_process cp_upd_index = CHILD_PROCESS_INIT;
struct child_process cp_write_tree = CHILD_PROCESS_INIT;
struct strbuf out = STRBUF_INIT;
struct strbuf diff_output = STRBUF_INIT; struct strbuf diff_output = STRBUF_INIT;
struct index_state istate = { NULL };


init_revisions(&rev, NULL); init_revisions(&rev, NULL);


@ -1095,20 +1083,15 @@ static int stash_working_tree(struct stash_info *info, struct pathspec ps)
goto done; goto done;
} }


cp_write_tree.git_cmd = 1; if (write_index_as_tree(&info->w_tree, &istate, stash_index_path.buf, 0,
argv_array_push(&cp_write_tree.args, "write-tree"); NULL)) {
argv_array_pushf(&cp_write_tree.env_array, "GIT_INDEX_FILE=%s",
stash_index_path.buf);
if (pipe_command(&cp_write_tree, NULL, 0, &out, 0,NULL, 0)) {
ret = -1; ret = -1;
goto done; goto done;
} }


get_oid_hex(out.buf, &info->w_tree);

done: done:
discard_index(&istate);
UNLEAK(rev); UNLEAK(rev);
strbuf_release(&out);
object_array_clear(&rev.pending); object_array_clear(&rev.pending);
strbuf_release(&diff_output); strbuf_release(&diff_output);
remove_path(stash_index_path.buf); remove_path(stash_index_path.buf);