Re: [PATCH] stash: reuse cached index entries in --patch temporary index
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 20, 2026, 02:26 UTC
- Message-ID
- <xmqqldde6cl5.fsf@gitster.g>
- In-Reply-To
- <pull.2306.git.git.1779194605735.gitgitgadget@gmail.com>
"Adam Johnson via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 24 quoted lines
> 2 files changed, 83 insertions(+), 6 deletions(-)
>
> diff --git a/builtin/stash.c b/builtin/stash.c
> index 32dbc97b47..48189cb9f7 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -372,6 +372,57 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
> return 0;
> }
>
> +static int create_index_from_tree(const struct object_id *tree_id,
> + const char *index_path)
> +{
> + int nr_trees = 1;
> + int ret = 0;
> + struct unpack_trees_options opts;
> + struct tree_desc t[MAX_UNPACK_TREES];
> + struct tree *tree;
> + struct index_state dst_istate = INDEX_STATE_INIT(the_repository);
> + struct lock_file lock_file = LOCK_INIT;
> +
> + repo_read_index_preload(the_repository, NULL, 0);
> + if (refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, NULL))
> + return -1;Is this "non-zero return from refresh_index() leads to a failure" intended? The old "git read-tree HEAD" wouldn't have cared if the original index were unmerged, for example, but with this update, we will see an immediate failure. There are other conditions that refresh_index() flips its local variable has_errors on, which leads to its non-zero return.
Since "git stash -p" is almost always invoked when the user has unstaged modifications, I am not sure allowing refresh_index() to notice and barf is what we want here.