Re: [PATCH 2/5] apply: read in the index in --intent-to-add mode
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 30, 2025, 18:47 UTC
- Message-ID
- <xmqqbjq512y5.fsf@gitster.g>
- In-Reply-To
- <20250628225819.1294068-4-ray@ameretat.dev>
"Raymond E. Pasco" <ray@ameretat.dev> writes:
Show 10 quoted lines
> There are three main modes of operation for apply: applying only to the > worktree, applying to the worktree and index (--index), and applying > only to the index (--cached). > > The --intent-to-add flag modifies the first of these modes, applying > only to the worktree, in a way which touches the index, because > intents to add are special index entries. However, it has not ever > worked correctly in any but the most trivial (empty repository) > cases, because the index was never read in (in apply, this is done > in read_apply_cache()) before writing to it.
As the inventor of "add -N", I think what "apply -N" does may be wrong (only judging from the above description; it's been a while since I really read the code in apply.c). It does not make any sense to write a new index that has only the ITA entries.
> If we merely gate read_apply_cache() behind update_index, then it will > not be read when state->apply is false, even if it must be checked. > Therefore, we instead read the index if it will be either checked or > updated, because reading the index is a prerequisite to either.
Makes sense.
Show 20 quoted lines
> Reported-by: Ryan Hodges <rhodges@cisco.com>
> Original-patch-by: Johannes Altmanninger <aclopte@gmail.com>
> Signed-off-by: Raymond E. Pasco <ray@ameretat.dev>
> ---
> apply.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/apply.c b/apply.c
> index e7856ae6b3..1757d34618 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -4837,7 +4837,7 @@ static int apply_patch(struct apply_state *state,
> LOCK_DIE_ON_ERROR);
> }
>
> - if (state->check_index && read_apply_cache(state) < 0) {
> + if ((state->check_index || state->update_index) && read_apply_cache(state) < 0) {
> error(_("unable to read index file"));
> res = -128;
> goto end;