git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH V2] git-apply: Allow simultaneous --cached and --3way options

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 5, 2021, 22:46 UTC
Message-ID
<xmqqr1jo4aex.fsf@gitster.g>
In-Reply-To
<20210405221902.27998-1-jerry@skydio.com>
Jerry Zhang <jerry@skydio.com> writes:
> Subject: Re: [PATCH V2] git-apply: Allow simultaneous --cached and --3way options
s/Allow/allow/ (cf. "git shortlog --no-merged" output for recent examples)
> Previously, --cached and --3way were not
> allowed to be used together, since --3way
> wrote conflict markers into the working tree.

Hint that you are talking about the "git apply" command by mentioning the name somewhere.

Drop "previously"; we talk about the status quo in the present tense in our proposed commit log messages to set the stage, and then describe what the patch author percieves as a problem, before describing the proposed solution to the problem.

cf. Documentation/SubmittingPatches[[describe-changes]] (the whole section)
Show 7 quoted lines
> These changes change semantics so that if
> these flags are given together and there is
> a conflict, the conflicting objects are left
> at a higher order in the cache, and the command
> will return non-zero. If there is no conflict,
> the patch is applied directly to cache as
> expected and the command will return 0.
Give an order to the codebase to "be like so".  Here is my attempt.
    Teach "git apply" to accept "--cached" and "--3way" at the same
    time.  Only when all changes to all paths involved in the
    application auto-resolve cleanly, the result is placed in the
    index at stage #0 and the command exits with 0 status.  If there
    is any path whose conflict cannot be cleanly auto-resolved, the
    original contents from common ancestor (stage #1), our version
    (stage #2) and the contents from the patch (stage #3) for the
    conflicted paths are left at separate stages without any attempt
    to resolve the conflict at the content level, and the command
    exists with non-zero status, because there is no place (like the
    working tree files) to leave a half-resolved conflicted merge
    result to ask the end-user to resolve.
> The user can use `git diff` to view the contents
> of the conflict, or `git checkout -m -- .` to
> regenerate the conflict markers in the working
> directory.
Nice.
> With the combined --3way and --cached flags,
> The conflict markers won't be written to the
> working directory, so there is no point in
> attempting rerere.
I am not sure what this paragraph is trying to convey here.

I agree that when a *new* conflict is encountered in this new mode, writing out a rerere pre-image, in preparation for accepting the post-image the end-user gives us after the conflicts are resolved, does not make sense, because we are not giving the end-user the conflicted state and asking to help resolve it for us.

But if a rerere database entry records a previous merge result in which conflicts were resolved by the end user, it would make sense to try reusing the resolution, I would think. I offhand do not know how involved it would be to do so, so punting on that is fine, but that is "there is no point", but it is "we are not trying".

Perhaps
    When there are conflicts, theoretically, it would be nice to be
    able to replay an existing entry in the rerere database that
    records already resolved conflict that match the current one,
    but that would be too much work, so let's not try it for now.

would be a good explanation why we are not doing (i.e. we made a trade-off) and recording that is important, as it will allow others in the future to try building on the change we are proposing here (it is not like we decided that it is fundamentally wrong to try to use rerere in this situation).

> Signed-off-by: Jerry Zhang <jerry@skydio.com>
> Signed-off-by: Jerry Zhang <jerryxzha@googlemail.com>

Unless we are interacting with two people with the same name, please sign-off with the same name/address as the name/address that will be recorded as the author of this change. I am guessing that dropping the latter should be sufficient?

Thanks.
Previous: Jerry ZhangNext: Jerry Zhang
Message 12 of 29 in “git-apply: Allow simultaneous --cached and --3way options”
  1. 0/1 git-apply: Allow simultaneous --cached and --3way optionsJerry Zhang, Apr 3, 2021
  2. 1/1 git-apply: Allow simultaneous --cached and --3way optionsJerry Zhang, Apr 3, 2021
  3. Elijah NewrenApr 3, 2021
  4. Junio C HamanoApr 3, 2021
  5. Junio C HamanoApr 4, 2021
  6. Jerry ZhangApr 5, 2021
  7. Junio C HamanoApr 5, 2021
  8. Jerry ZhangApr 5, 2021
  9. Junio C HamanoApr 6, 2021
  10. Jerry ZhangApr 5, 2021
  11. git-apply: Allow simultaneous --cached and --3way optionsJerry Zhang, Apr 5, 2021
  12. Junio C HamanoApr 5, 2021
  13. Jerry ZhangApr 6, 2021
  14. Junio C HamanoApr 6, 2021
  15. Jerry ZhangApr 6, 2021
  16. Jerry ZhangApr 7, 2021
  17. git-apply: allow simultaneous --cached and --3way optionsJerry Zhang, Apr 6, 2021
  18. git-apply: allow simultaneous --cached and --3way optionsJerry Zhang, Apr 7, 2021
  19. Junio C HamanoApr 7, 2021
  20. git-apply: allow simultaneous --cached and --3way optionsJerry Zhang, Apr 8, 2021
  21. Junio C HamanoApr 8, 2021
  22. Elijah NewrenApr 12, 2021
  23. Junio C HamanoApr 12, 2021
  24. Elijah NewrenApr 12, 2021
  25. Junio C HamanoApr 12, 2021
  26. Elijah NewrenApr 3, 2021
  27. Jerry ZhangApr 5, 2021
  28. Bagas SanjayaApr 3, 2021
  29. Bagas SanjayaApr 3, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.