Re: [PATCH v8 4/4] branch: let --delete-integrated find branches merged onto changed files
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Nov 18, 2026, 23:05 UTC
- Message-ID
- <xmqqik1t2119.fsf@gitster.g>
- In-Reply-To
- <22658105edeacf296a18373400e7b35141e053ef.1794921876.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 9 quoted lines
> @@ -888,6 +897,8 @@ static void collect_branch_changes(struct landing_search *search, > search->changes_alloc); > change = &search->changes[search->changes_nr++]; > change->path = xstrdup(p->two->path); > + oidcpy(&change->base_oid, DIFF_FILE_VALID(p->one) ? > + &p->one->oid : null_oid(the_hash_algo)); > oidcpy(&change->branch_oid, DIFF_FILE_VALID(p->two) ? > &p->two->oid : null_oid(the_hash_algo)); > change->branch_mode = p->two->mode;
Mental note. We are recording the mode in the "branch", but never record the mode of the path in the base here.
Show 13 quoted lines
> @@ -895,25 +906,65 @@ static void collect_branch_changes(struct landing_search *search,
> diff_flush(&diffopt);
> }
>
> +static int merge_keeps_upstream(const struct branch_change *change)
> +{
> + mmfile_t base, upstream, branch;
> + mmfile_t result = { 0 };
> + int ret;
> +
> + read_mmblob(&base, the_repository->objects, &change->base_oid);
> + read_mmblob(&upstream, the_repository->objects, &change->upstream_oid);
> + read_mmblob(&branch, the_repository->objects, &change->branch_oid);Imagine that a path that originally was a gitlink has been replaced with different regular files on our branch and the upstream. If this function ever gets called on such a path from changes_landed(), the base_oid would record the submodule's commit object name, and read_mmblob() would probably crash.
Show 33 quoted lines
> + ret = ll_merge(&result, change->path, &base, "base",
> + &upstream, "upstream", &branch, "branch",
> + the_repository->index, NULL) == LL_MERGE_OK &&
> + result.size == upstream.size &&
> + !memcmp(result.ptr, upstream.ptr, upstream.size);
> +
> + free(base.ptr);
> + free(upstream.ptr);
> + free(branch.ptr);
> + free(result.ptr);
> + return ret;
> +}
> +
> +static enum change_state change_state_at(struct branch_change *change,
> + struct commit *commit)
> {
> unsigned short mode;
>
> if (get_tree_entry(the_repository, get_commit_tree_oid(commit),
> + change->path, &change->upstream_oid, &mode))
> + return is_null_oid(&change->branch_oid) ?
> + CHANGE_LANDED : CHANGE_MISSING;
> + if (oideq(&change->upstream_oid, &change->branch_oid))
> + return mode == change->branch_mode ?
> + CHANGE_LANDED : CHANGE_MISSING;
>
> + if (is_null_oid(&change->base_oid) ||
> + is_null_oid(&change->branch_oid) ||
> + oideq(&change->upstream_oid, &change->base_oid) ||
> + mode != change->branch_mode || !S_ISREG(mode))
> + return CHANGE_MISSING;
> + return CHANGE_NEEDS_MERGE;
> }Now, if a gitlink was turned into different regular files, as object names in upstream/branch/base are all different, none of them is null_oid, and as we saw earlier, branch_mode is from p->two->mode found in collect_branch_changes(), and mode would also be for the regular file. As the mode is the same, we end up returning CHANGE_NEEDS_NERGE from here. Which would cause ...
Show 19 quoted lines
> static int changes_landed(struct landing_search *search,
> struct commit *commit)
> {
> - for (size_t i = 0; i < search->changes_nr; i++)
> - if (!change_landed(&search->changes[i], commit))
> + for (size_t i = 0; i < search->changes_nr; i++) {
> + struct branch_change *change = &search->changes[i];
> +
> + change->state = change_state_at(change, commit);
> + if (change->state == CHANGE_MISSING)
> return 0;
> + }
> + for (size_t i = 0; i < search->changes_nr; i++) {
> + struct branch_change *change = &search->changes[i];
> +
> + if (change->state == CHANGE_NEEDS_MERGE &&
> + !merge_keeps_upstream(change))
> + return 0;
> + }... this code to call merge_keeps_upstream(), causing read_mmfile() on the gitlink commit from submodule object database, leading to a crash, no?
Or am I misreading the code flow?
> return 1; > }