On 08/08, Paul-Sebastian Ungureanu wrote:
> Instead of spawning a child process, make use of `reset_tree()`
> function already implemented in `stash-helper.c`.
> ---
>  builtin/stash--helper.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/builtin/stash--helper.c b/builtin/stash--helper.c
> index a4e57899b..887b78d05 100644
> --- a/builtin/stash--helper.c
> +++ b/builtin/stash--helper.c
> @@ -984,21 +984,18 @@ static int stash_patch(struct stash_info *info, const 
> char **argv)
>  static int stash_working_tree(struct stash_info *info, const char **argv)
>  {
>       int ret = 0;
> -     struct child_process cp0 = CHILD_PROCESS_INIT;
>       struct child_process cp1 = CHILD_PROCESS_INIT;
>       struct child_process cp2 = CHILD_PROCESS_INIT;
>       struct child_process cp3 = CHILD_PROCESS_INIT;
>       struct strbuf out1 = STRBUF_INIT;
>       struct strbuf out3 = STRBUF_INIT;
>  
> -     cp0.git_cmd = 1;
> -     argv_array_push(&cp0.args, "read-tree");
> -     argv_array_pushf(&cp0.args, "--index-output=%s", stash_index_path.buf);
> -     argv_array_pushl(&cp0.args, "-m", oid_to_hex(&info->i_tree), NULL);
> -     if (run_command(&cp0)) {
> +     set_alternate_index_output(stash_index_path.buf);
> +     if (reset_tree(&info->i_tree, 0, 0)) {
>               ret = -1;
>               goto done;
>       }
> +     set_alternate_index_output(".git/index");

I think this second 'set_alternate_index_output()' should be
'set_alternate_index_output(NULL)', which has slightly different
semantics than setting it to '.git/index'.  Having it set means that
the index is written unconditionally even if it is not set.

Also the index file could be something other than ".git/index", if
the GIT_INDEX_FILE environment variable is set, so it should be
replaced with 'get_index_file()' if we were to keep this.

I was also wondering if we could avoid writing a temporary index to
disk, in 'stash_working_tree', but I don't see an easy way for doing
that.

>  
>       cp1.git_cmd = 1;
>       argv_array_pushl(&cp1.args, "diff-index", "--name-only", "-z",
> -- 
> 2.18.0.573.g56500d98f
> 

Reply via email to