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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tboegi@xxxxxx writes:

> From: Torsten Bögershausen <tboegi@xxxxxx>
>
> 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.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux