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

Re: What's cooking in git.git (Jan 2021, #02; Fri, 8)

From
David Aguilar <davvid@gmail.com>
Date
Jan 9, 2021, 21:38 UTC
Message-ID
<CAJDDKr6V+kKMs4yz+YQx1AhiY5qQwENfs_yZqxXWBqmLUk2oAw@mail.gmail.com>
In-Reply-To
<xmqqk0sni68g.fsf@gitster.c.googlers.com>
On Fri, Jan 8, 2021 at 11:28 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
>
> * fc/mergetool-automerge (2021-01-06) 5 commits
>  . mergetool: add automerge_enabled tool-specific override function
>  . mergetool: break setup_tool out into separate initialization function
>  . mergetool: add per-tool support for the autoMerge flag
>  . mergetool: alphabetize the mergetool config docs
>  . mergetool: add automerge configuration
>
>  "git mergetool" feeds three versions (base, local and remote) of
>  a conflicted path unmodified.  The command learned to optionally
>  prepare these files with unconflicted parts already resolved.
>
>  Breaks tests on macOS.
>  cf. https://github.com/git/git/runs/1659807735?check_suite_focus=true#step:4:1641
Thank you for seeing these changes through.  It's so close now!
I did some investigation into this issue and narrowed down the root cause.

Here is an example input file called "tiger" for testing the sed invocations in auto_merge():

$ cat tiger <<<<<<< HEAD branch1 both added ======= tiger both added

>>>>>>> tiger

There are two sed invocations that use \r\? to maybe-match \r for crlf support. \r\? is not portable to macOS (and freebsd?) sed.

For example, auto_merge() does the equivalent of this in one of the invocations:
    sed -e '/^<<<<<<< /,/^=======\r\?$/d' -e '/^>>>>>>> /d' tiger

It prints nothing on macOS. "gsed" (gnu-sed) from homebrew prints "tiger both added". This may affect other unix flavors where sed is not gnu as well.

To verify I changed the sed invocations in auto_merge() to use gsed and it's then able to pass the tests.

Fun times in sed portability land. After a bit of experimentation, this is what I've managed to whip up:

cr=$(printf '\x0d') sed -e "/^<<<<<<< /,/^=======$cr\{0,1\}$/d" -e '/^>>>>>>> /d' tiger

- Instead of \r use printf to capture CR into a string so that we can
embed the literal using $cr.
- DQ "..." instead of SQ '...' to allow $cr to be substituted in the string.
- Instead of \? use \{0,1\} which seems to work on both macOS and Linux.

That seems to work and the tests now pass. If not sed, is there perhaps a perl equivalent for these multi-line delete-from-X-until-Y expressions that might provide better portability?

I'll start putting together a patch shortly as this seems to work in practice. Let me know if y'all have any sugs or if there are any portability pitfalls I'm not considering.

cheers,

-- David

Previous: Junio C HamanoNext: Junio C Hamano
Message 19 of 34 in “What's cooking in git.git (Jan 2021, #02; Fri, 8)”
  1. Junio C HamanoJan 8, 2021
  2. Ævar Arnfjörð BjarmasonJan 9, 2021
  3. Junio C HamanoJan 9, 2021
  4. brian m. carlsonJan 9, 2021
  5. Junio C HamanoJan 9, 2021
  6. brian m. carlsonJan 11, 2021
  7. Junio C HamanoJan 11, 2021
  8. Ævar Arnfjörð BjarmasonJan 12, 2021
  9. Emily ShafferJan 14, 2021
  10. Emily ShafferJan 14, 2021
  11. Junio C HamanoJan 15, 2021
  12. brian m. carlsonJan 15, 2021
  13. Junio C HamanoJan 15, 2021
  14. Ævar Arnfjörð BjarmasonJan 16, 2021
  15. Jeff KingJan 17, 2021
  16. Ævar Arnfjörð BjarmasonJan 17, 2021
  17. Ævar Arnfjörð BjarmasonJan 10, 2021
  18. Junio C HamanoJan 11, 2021
  19. David AguilarJan 9, 2021
  20. Junio C HamanoJan 9, 2021
  21. Emily ShafferJan 14, 2021
  22. Junio C HamanoJan 15, 2021
  23. Taylor BlauJan 15, 2021
  24. Taylor BlauJan 15, 2021
  25. Derrick StoleeJan 15, 2021
  26. Derrick StoleeJan 15, 2021
  27. Junio C HamanoJan 15, 2021
  28. Junio C HamanoJan 15, 2021
  29. Derrick StoleeJan 15, 2021
  30. Junio C HamanoJan 15, 2021
  31. Emily ShafferJan 15, 2021
  32. Junio C HamanoJan 15, 2021
  33. Jeff KingJan 15, 2021
  34. Junio C HamanoJan 15, 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.