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

Re: [PATCH v4 1/1] MacOS: precompose_argv_prefix()

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 3, 2021, 19:33 UTC
Message-ID
<xmqq35ydc5g3.fsf@gitster.c.googlers.com>
In-Reply-To
<20210203162823.15756-1-tboegi@web.de>
tboegi@web.de writes:
Show 75 quoted lines
> From: Torsten Bögershausen <tboegi@web.de>
>
> The following sequence leads to a "BUG" assertion running under MacOS:
>
>   DIR=git-test-restore-p
>   Adiarnfd=$(printf 'A\314\210')
>   DIRNAME=xx${Adiarnfd}yy
>   mkdir $DIR &&
>   cd $DIR &&
>   git init &&
>   mkdir $DIRNAME &&
>   cd $DIRNAME &&
>   echo "Initial" >file &&
>   git add file &&
>   echo "One more line" >>file &&
>   echo y | git restore -p .
>
>  Initialized empty Git repository in /tmp/git-test-restore-p/.git/
>  BUG: pathspec.c:495: error initializing pathspec_item
>  Cannot close git diff-index --cached --numstat
>  [snip]
>
> The command `git restore` is run from a directory inside a Git repo.
> Git needs to split the $CWD into 2 parts:
> The path to the repo and "the rest", if any.
> "The rest" becomes a "prefix" later used inside the pathspec code.
>
> As an example, "/path/to/repo/dir-inside-repå" would determine
> "/path/to/repo" as the root of the repo, the place where the
> configuration file .git/config is found.
>
> The rest becomes the prefix ("dir-inside-repå"), from where the
> pathspec machinery expands the ".", more about this later.
> If there is a decomposed form, (making the decomposing visible like this),
> "dir-inside-rep°a" doesn't match "dir-inside-repå".
>
> Git commands need to:
>
>  (a) read the configuration variable "core.precomposeunicode"
>  (b) precocompose argv[]
>  (c) precompose the prefix, if there was any
>
> The first commit,
> 76759c7dff53 "git on Mac OS and precomposed unicode"
> addressed (a) and (b).
>
> The call to precompose_argv() was added into parse-options.c,
> because that seemed to be a good place when the patch was written.
>
> Commands that don't use parse-options need to do (a) and (b) themselfs.
>
> The commands `diff-files`, `diff-index`, `diff-tree` and `diff`
> learned (a) and (b) in
> commit 90a78b83e0b8 "diff: run arguments through precompose_argv"
>
> Branch names (or refs in general) using decomposed code points
> resulting in decomposed file names had been fixed in
> commit 8e712ef6fc97 "Honor core.precomposeUnicode in more places"
>
> The bug report from above shows 2 things:
> - more commands need to handle precomposed unicode
> - (c) should be implemented for all commands using pathspecs
>
> Solution:
> precompose_argv() now handles the prefix (if needed), and is renamed into
> precompose_argv_prefix().
>
> Inside this function the config variable core.precomposeunicode is read
> into the global variable precomposed_unicode, as before.
> This reading is skipped if precomposed_unicode had been read before.
>
> The original patch for preocomposed unicode, 76759c7dff53, placed
> precompose_argv() into parse-options.c
> Now add it into git.c (as well) for commands that don't use parse-options.
> Note that precompose() may be called twice - it is idempotent.

Just as the prefix-less variant was idempotent and that was the reason why cmd_diff_files() had its own precompose() even if the incoming argv[] is supposed to be already precomposed because it was processed in another call to precompose() in run_builtin(), this patch keeps these seemingly redundant calls, because it is not meant as a clean-up but as a bugfix for the prefix part.

OK. ... Ah, no, the call in run_builtin() is a new thing. We didn't have it, and the redundant call is what this patch introduced, so we need to be a bit more careful about the analysis here. It is one thing to say "we leave the existing iffy code and address only a single bug" and do so. It is entirely different to say so and then do "we introduce an iffy code and address only a single bug". We need to admit that what we added _is_ iffy but supposed to be safe. Just saying "it is supposed to be safe" without saying why it is iffy is dishonest and does not help future developers who may want to jump in and clean the code.

Perhaps
	Now add it into git.c::run_builtin() as well.  Existing
	precompose calls in diff-files.c and others would become
	redundant but because we do not want to make sure that there
	is no way for the control to reach them without passing
	run_builtin(), we'll keep them in place just in case.  The
	calls to precompose() are idempotent so it should not hurt.
or something?
>  - And yes, there may be more work to be done. For the moment I would like to
>    get this merged into git.git, and address the rest later.
Sure.
Thanks.
Previous: tboegi@web.deNext: Junio C Hamano
Message 20 of 22 in “git-bugreport-2021-01-06-1209.txt (git can't deal with special characters)”
  1. Daniel TrogerJan 6, 2021
  2. Torsten BögershausenJan 6, 2021
  3. Daniel TrogerJan 6, 2021
  4. Torsten BögershausenJan 6, 2021
  5. Daniel TrogerJan 6, 2021
  6. Randall S. BeckerJan 6, 2021
  7. Philippe BlainJan 7, 2021
  8. Torsten BögershausenJan 7, 2021
  9. Philippe BlainJan 7, 2021
  10. Torsten BögershausenJan 8, 2021
  11. 1/1 git restore -p . and precomposed unicodetboegi@web.de, Jan 24, 2021
  12. Junio C HamanoJan 24, 2021
  13. Torsten BögershausenJan 25, 2021
  14. 1/1 MacOS: precompose_argv_prefix()tboegi@web.de, Jan 29, 2021
  15. Junio C HamanoJan 29, 2021
  16. Junio C HamanoJan 31, 2021
  17. 1/1 MacOS: precompose_argv_prefix()tboegi@web.de, Feb 2, 2021
  18. Junio C HamanoFeb 2, 2021
  19. 1/1 MacOS: precompose_argv_prefix()tboegi@web.de, Feb 3, 2021
  20. Junio C HamanoFeb 3, 2021
  21. Junio C HamanoFeb 3, 2021
  22. Torsten BögershausenFeb 5, 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.