From: Phillip Wood <phillip.wood123@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 2/2] merge: remember conflict labels
Date: Thu, 1 Oct 2026 09:54:52 +0100 [thread overview]
Message-ID: <6e028692-447c-4a21-a9bb-739e42f1c9aa@gmail.com> (raw)
In-Reply-To: <xmqq1paad71z.fsf@gitster.g>
Hi Junio
On 30/09/2026 17:42, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
>
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> When recreating merge conflicts with "git checkout -m <path>" the
>> original conflict labels are lost. For commands like "git merge" and
>> "git cherry-pick" we could use the presence of the related root
>> ref (MERGE_HEAD and CHERRY_PICK_HEAD respectively) to recreate the
>> labels. However, if the conflicts are from "git stash pop" or "git
>> checkout -m <branch>", then there is no ref to deduce the labels from. To
>> ensure the labels are always available, the merge machinery is updated to
>> write ".git/MERGE_LABELS" when it updates the worktree and
>> there are conflicts. The labels are then read from that file by "git
>> checkout -m <path>" when recreating the conflicts.
>>
>> As "git checkout -m <branch>" calls remove_branch_state() which
>> ordinarily removes the labels file, we need to pass a flag down
>> to optionally prevent that so that the labels are available for any
>> subsequent "git checkout -m <path>". Note that merge_switch_to_result()
>> we assign "result->priv" to "opt->priv" and later clear "opt->priv" in
>> order to get a pointer to the private struct as result->priv is void*.
>>
>> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>> ---
>> branch.c | 11 ++++++--
>> branch.h | 1 +
>> builtin/checkout.c | 24 +++++++++++++++---
>> builtin/commit.c | 1 +
>> merge-ort.c | 19 ++++++++++++++
>> merge.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++
>> merge.h | 4 +++
>> path.c | 1 +
>> path.h | 1 +
>> repository.c | 1 +
>> repository.h | 1 +
>> sequencer.c | 1 +
>> t/t7201-co.sh | 21 ++++++++++++++++
>> 13 files changed, 143 insertions(+), 6 deletions(-)
>
> Where do we talk about MERGE_HEAD and CHERRY_PICK_HEAD in the
> current documentation set? Do we want to mention MERGE_LABELS
> alongside them?
We talk about those in gitrevisions, the "refs" section of gitglossary
and in the merge documentation. As this is not a ref I don't think it
fits with MERGE_HEAD, it is more like MERGE_MSG, or MERGE_MODE. The
merge man page mentions MERGE_MSG in passing but never explicitly says
what it contains and MERGE_MODE is undocumented as far as I can see. We
would perhaps benefit from documenting the common files like
COMMIT_EDITMSG, MERGE_MSG, SQUASH_MSG, MERGE_HEAD, FETCH_HEAD and
MERGE_LABELS somewhere in gitrepository briefly explaining what they
contain and how they are used as a separate series.
>> +static int parse_merge_label_line(const char **p, char **line)
>> +{
>> + const char *eol = strchr(*p, '\n');
>> +
>> + if (!eol)
>> + return -1;
>> +
>> + *line = xmemdupz(*p, eol - *p);
>> + *p = eol + 1;
>> +
>> + return 0;
>> +}
>
>
> OK, this reads one line at a time from the file contents already
> fully read by strbuf_read_file(), as seen below.
>
> Which means that the CRLF fprintf() may have written in
> write_merge_labels() will come back to this function, and our 'ours'
> may become 'ours\015' after stripping only the LF at the end?
That's a good point, I've changed it to use strbuf_getline() instead.
> Thanks for working on these patches.
Thanks for reviewing them, I'll send a re-roll in a couple of days
Phillip
next prev parent reply other threads:[~2026-10-01 8:55 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 9:48 [PATCH 0/2] checkout -m: recreate conflict labels Phillip Wood
2026-09-30 9:48 ` [PATCH 1/2] remove_branch_state: convert boolean argument to flags Phillip Wood
2026-09-30 9:48 ` [PATCH 2/2] merge: remember conflict labels Phillip Wood
2026-09-30 16:42 ` Junio C Hamano
2026-10-01 8:54 ` Phillip Wood [this message]
2026-10-01 17:14 ` Junio C Hamano
2026-09-30 20:24 ` [PATCH 0/2] checkout -m: recreate " Johannes Sixt
2026-09-30 20:40 ` Junio C Hamano
2026-09-30 21:20 ` Johannes Sixt
2026-10-01 8:45 ` Phillip Wood
2026-10-05 13:24 ` [PATCH v2 " Phillip Wood
2026-10-05 13:24 ` [PATCH v2 1/2] remove_branch_state: convert boolean argument to flags Phillip Wood
2026-10-05 13:24 ` [PATCH v2 2/2] merge: remember conflict labels Phillip Wood
2026-10-05 16:19 ` Junio C Hamano
2026-10-06 15:21 ` Phillip Wood
2026-10-05 16:31 ` Junio C Hamano
2026-10-06 15:05 ` Phillip Wood
2026-10-06 15:46 ` Junio C Hamano
2026-10-07 13:38 ` Phillip Wood
2026-10-05 14:48 ` [PATCH v2 0/2] checkout -m: recreate " Johannes Sixt
2026-10-05 15:09 ` Phillip Wood
2026-10-05 15:53 ` Junio C Hamano
2026-10-09 9:13 ` [PATCH v3 " Phillip Wood
2026-10-09 9:13 ` [PATCH v3 1/2] remove_branch_state: convert boolean argument to flags Phillip Wood
2026-10-09 9:13 ` [PATCH v3 2/2] merge: remember conflict labels Phillip Wood
2026-10-10 0:24 ` Junio C Hamano
2026-10-09 20:31 ` [PATCH v3 0/2] checkout -m: recreate " Junio C Hamano
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=6e028692-447c-4a21-a9bb-739e42f1c9aa@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=newren@gmail.com \
--cc=phillip.wood@dunelm.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox