git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: tboegi@web.de
Cc: git@vger.kernel.org, random_n0body@icloud.com,
	levraiphilippeblain@gmail.com
Subject: Re: [PATCH v3 1/1] MacOS: precompose_argv_prefix()
Date: Tue, 02 Feb 2021 09:43:10 -0800	[thread overview]
Message-ID: <xmqqk0rqgyc1.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20210202151158.27028-1-tboegi@web.de> (tboegi@web.de's message of "Tue, 2 Feb 2021 16:11:58 +0100")

tboegi@web.de writes:

> diff --git a/builtin/diff-files.c b/builtin/diff-files.c
> index 1e352dd8f7..e3851dd1c0 100644
> --- a/builtin/diff-files.c
> +++ b/builtin/diff-files.c
> @@ -35,7 +35,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
>  	 */
>  	rev.diffopt.ita_invisible_in_index = 1;
>
> -	precompose_argv(argc, argv);
> +	prefix = precompose_argv_prefix(argc, argv, prefix);

When git.c::cmd_main() calls run_builtin() to call cmd_diff_files(),
precompose would have already been called, and we end up calling the
already processed argv[] and prefix again here.

Is there a codepath where cmd_diff_files() gets called _without_
making the call to precompose() in git.c::run_builtin()?

Previous round removed the precompose call and I thought the logic
was sound, but I must be missing something.

The same question applies to other built-ins.

Standalone commands that go through execv_dashed_external() should
still have a call to precompose() in their own cmd_main() as the
prefix is not affected for them, but I suspect that they are not
expected to be run from a subdirectory to begin with?

> +const char *precompose_argv_prefix(int argc, const char **argv, const char *prefix)
> +{
> +	int i = 0;
>
>  	while (i < argc) {
> -		size_t namelen;
> -		oldarg = argv[i];
> -		if (has_non_ascii(oldarg, (size_t)-1, &namelen)) {
> -			newarg = reencode_string_iconv(oldarg, namelen, ic_precompose, 0, NULL);
> -			if (newarg)
> -				argv[i] = newarg;
> -		}
> +		argv[i] = precompose_string_if_needed(argv[i]);
>  		i++;
>  	}
> -	iconv_close(ic_precompose);
> +	if (prefix) {
> +		prefix = precompose_string_if_needed(prefix);
> +	}
> +	return prefix;
>  }

OK.  I missed that the previous round did return NULL when the
original should have been returned.  It is clear that this caller,
and the updated precompose_string_if_needed(), returns the original.

Good.

> diff --git a/git.c b/git.c
> index a00a0a4d94..16a485fbe7 100644
> --- a/git.c
> +++ b/git.c
> @@ -420,7 +420,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
>  			int nongit_ok;
>  			prefix = setup_git_directory_gently(&nongit_ok);
>  		}
> -
> +		prefix = precompose_argv_prefix(argc, argv, prefix);
>  		if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY) &&
>  		    !(p->option & DELAY_PAGER_CONFIG))
>  			use_pager = check_pager_config(p->cmd);
> diff --git a/parse-options.c b/parse-options.c
> index f0507432ee..fbea16eaf5 100644
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -869,7 +869,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
>  		usage_with_options(usagestr, options);
>  	}
>
> -	precompose_argv(argc, argv);
> +	precompose_argv_prefix(argc, argv, NULL);

The correctness of this call also relies on that precompose() is
expected to be idempotent (not saying it is necessarily bad, but
just making a note), as argv[] must have been already processed
before a built-in calls this function.

> diff --git a/t/t3910-mac-os-precompose.sh b/t/t3910-mac-os-precompose.sh
> index 54ce19e353..8f7b49221f 100755
> --- a/t/t3910-mac-os-precompose.sh
> +++ b/t/t3910-mac-os-precompose.sh
> @@ -191,6 +191,22 @@ test_expect_failure 'handle existing decomposed filenames' '
>  	test_must_be_empty untracked
>  '
>
> +test_expect_success "unicode decomposed: git restore -p . " '
> +	DIRNAMEPWD=dir.Odiarnfc &&
> +	DIRNAMEINREPO=dir.$Adiarnfc &&
> +	export DIRNAMEPWD DIRNAMEINREPO &&

The above is fine, but

> +	git init $DIRNAMEPWD &&
> +	(
> +		cd $DIRNAMEPWD &&
> +		mkdir $DIRNAMEINREPO &&
> +		cd $DIRNAMEINREPO &&

Shouldn't these variable references be "quoted" for readers (I know
they happen to be free of $IFS whitespaces etc., but readers and
more importantly those who may casually cut-and-paste would not
know)?

> +		echo "Initial" >file &&
> +		git add file &&
> +		echo "More stuff" >>file &&
> +		echo y | git restore -p .
> +	)
> +'
> +
>  # Test if the global core.precomposeunicode stops autosensing
>  # Must be the last test case
>  test_expect_success "respect git config --global core.precomposeunicode" '
> --
> 2.30.0.155.g66e871b664

Thanks.

  reply	other threads:[~2021-02-02 17:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 11:35 git-bugreport-2021-01-06-1209.txt (git can't deal with special characters) Daniel Troger
2021-01-06 14:21 ` Torsten Bögershausen
2021-01-06 16:49   ` Daniel Troger
2021-01-06 21:47     ` Torsten Bögershausen
2021-01-06 22:21       ` Daniel Troger
2021-01-06 23:07         ` Randall S. Becker
2021-01-07 14:34           ` Philippe Blain
2021-01-07 15:49             ` Torsten Bögershausen
2021-01-07 16:21               ` Philippe Blain
2021-01-08 19:07                 ` Torsten Bögershausen
2021-01-24 15:13 ` [PATCH/RFC v1 1/1] git restore -p . and precomposed unicode tboegi
2021-01-24 19:51   ` Junio C Hamano
2021-01-25 16:53     ` Torsten Bögershausen
2021-01-29 17:15 ` [PATCH v2 1/1] MacOS: precompose_argv_prefix() tboegi
2021-01-29 23:19   ` Junio C Hamano
2021-01-31  0:43   ` Junio C Hamano
2021-01-31  9:50     ` Torsten =?unknown-8bit?Q?B=C3=B6gershausen?=
2021-02-02 15:11 ` [PATCH v3 " tboegi
2021-02-02 17:43   ` Junio C Hamano [this message]
2021-02-03 16:28 ` [PATCH v4 " tboegi
2021-02-03 19:33   ` Junio C Hamano
2021-02-03 22:13     ` Junio C Hamano
2021-02-05 17:31       ` Torsten Bögershausen

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqk0rqgyc1.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=levraiphilippeblain@gmail.com \
    --cc=random_n0body@icloud.com \
    --cc=tboegi@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).