All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: git@vger.kernel.org, 重田一聖 <kazumasa.shigeta@kanamei.com>
Subject: Re: [PATCH v2 5/7] stash create: rework temporary index creation
Date: Wed, 14 Oct 2026 11:16:22 -0700	[thread overview]
Message-ID: <xmqqtsmorvux.fsf@gitster.g> (raw)
In-Reply-To: <f799d86f52796cc1b83788460568cc0d9849bed9.1791992404.git.phillip.wood@dunelm.org.uk> (Phillip Wood's message of "Wed, 14 Oct 2026 16:40:17 +0100")

Phillip Wood <phillip.wood123@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Use create_index_from_tree() instead of reset_tree() when we create a
> temporary index file to stash the working tree changes. This matches
> what we do for "git stash push -p" and means we can avoid messing with
> set_alternate_index_output(). Add a new parameter to control whether
> the index is reset, as we need to merge the index rather than reset
> it so that we still detect intent-to-add entries. We do not alter the
> in-memory index so we can remove the call to repo_read_index_preload()
> which saves one lstat() call per changed path.

It is unclear what problem we are trying to solve.  Obviously we can
enhance create_index_from_tree() and replace reset_tree() just fine,
but the proposed log message should make it clear why we are doing so.

Please follow the usual pattern to state "observation" (e.g., "we
use reset_tree() when we do X"), "problem" (e.g., "use of
reset_tree() is undesirable because ..."), and "solution" (e.g, "we
can improve by replacing reset_tree() with create_index_from_tree()
because the latter has these desirable characteristics") in this
order, perhaps in separate paragraphs for extra readability.



> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  builtin/stash.c | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)
>
> diff --git a/builtin/stash.c b/builtin/stash.c
> index b4fe7465e4..ddeb5a5d2a 100644
> --- a/builtin/stash.c
> +++ b/builtin/stash.c
> @@ -374,7 +374,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
>  }
>  
>  static int create_index_from_tree(const struct object_id *tree_id,
> -				  const char *index_path)
> +				  const char *index_path, bool reset)
>  {
>  	int nr_trees = 1;
>  	int ret = 0;
> @@ -403,7 +403,7 @@ static int create_index_from_tree(const struct object_id *tree_id,
>  	opts.src_index = the_repository->index;
>  	opts.dst_index = &dst_istate;
>  	opts.merge = 1;
> -	opts.reset = UNPACK_RESET_PROTECT_UNTRACKED;
> +	opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;
>  	opts.fn = oneway_merge;
>  
>  	if (unpack_trees(nr_trees, t, &opts)) {
> @@ -1399,7 +1399,7 @@ static enum create_result stash_patch(struct stash_info *info,
>  		goto done;
>  	}
>  
> -	if (create_index_from_tree(head_tree, stash_index_path.buf)) {
> +	if (create_index_from_tree(head_tree, stash_index_path.buf, true)) {
>  		ret = CREATE_ERROR;
>  		goto done;
>  	}
> @@ -1458,22 +1458,15 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps
>  	repo_init_revisions(the_repository, &rev, NULL);
>  	copy_pathspec(&rev.prune_data, ps);
>  
> -	set_alternate_index_output(stash_index_path.buf);
> -	if (reset_tree(&info->i_tree, 0, 0)) {
> +	if (create_index_from_tree(&info->i_tree, stash_index_path.buf, false)) {
>  		ret = -1;
>  		goto done;
>  	}
> -	set_alternate_index_output(NULL);
>  
>  	rev.diffopt.output_format = DIFF_FORMAT_CALLBACK;
>  	rev.diffopt.format_callback = add_diff_to_buf;
>  	rev.diffopt.format_callback_data = &diff_output;
>  
> -	if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0) {
> -		ret = -1;
> -		goto done;
> -	}
> -
>  	add_pending_object(&rev, parse_object(the_repository, &info->b_commit),
>  			   "");
>  	run_diff_index(&rev, 0);

  reply	other threads:[~2026-10-14 18:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05 16:35 [PATCH 0/2] stash: stop checking for changes twice Phillip Wood
2026-10-05 16:35 ` [PATCH 1/2] stash create: remove duplicate changes detection Phillip Wood
2026-10-06 12:44   ` Junio C Hamano
2026-10-07 13:49     ` Phillip Wood
2026-10-05 16:35 ` [PATCH 2/2] stash push: " Phillip Wood
2026-10-06 14:27   ` Junio C Hamano
2026-10-07 13:46     ` Phillip Wood
2026-10-07 17:15       ` Junio C Hamano
2026-10-08 13:35         ` Phillip Wood
2026-10-14 15:40 ` [PATCH v2 0/7] stash creation: avoid unecessary index loads and refreshes Phillip Wood
2026-10-14 15:40   ` [PATCH v2 1/7] stash: use an enum for create status Phillip Wood
2026-10-14 15:40   ` [PATCH v2 2/7] stash create: remove duplicate changes detection Phillip Wood
2026-10-14 15:40   ` [PATCH v2 3/7] stash push: " Phillip Wood
2026-10-14 15:40   ` [PATCH v2 4/7] stash push: avoid duplicate calls to preload_index() Phillip Wood
2026-10-14 18:09     ` Junio C Hamano
2026-10-14 15:40   ` [PATCH v2 5/7] stash create: rework temporary index creation Phillip Wood
2026-10-14 18:16     ` Junio C Hamano [this message]
2026-10-14 15:40   ` [PATCH v2 6/7] stash create: remove unnecessary index load and refresh Phillip Wood
2026-10-14 18:21     ` Junio C Hamano
2026-10-14 15:40   ` [PATCH v2 7/7] stash: simplify reset_tree() function signature Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqtsmorvux.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=kazumasa.shigeta@kanamei.com \
    --cc=phillip.wood123@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.