git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Brandon Williams <bmwill@google.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, "Wincent Colaiuta" <win@wincent.com>,
	"Mislav Marohnić" <mislav.marohnic@gmail.com>
Subject: Re: [PATCH] add--interactive: do not expand pathspecs with ls-files
Date: Tue, 14 Mar 2017 10:25:04 -0700	[thread overview]
Message-ID: <20170314172504.GA102212@google.com> (raw)
In-Reply-To: <20170314163024.et2cp5e3imrrrf7k@sigill.intra.peff.net>

On 03/14, Jeff King wrote:
>   b. If the repository contains filenames with literal wildcard
>      characters (e.g., "foo*"), the original code expanded
>      them via "ls-files" and then fed those wildcard names
>      to "diff-index", which would have treated them as
>      wildcards. This was a bug, which is now fixed (though
>      unless you really go through some contortions with
>      ":(literal)", it's likely that your original pathspec
>      would match whatever the accidentally-expanded wildcard
>      would anyway).
> 
>      So this takes us one step closer to working correctly
>      with files whose names contain wildcard characters, but
>      it's likely that others remain (e.g., if "git add -i"
>      feeds the selected paths to "git add").

It definitely makes things more difficult when people use wildcard
characters in filenames.  Is there any reason people use wildcards as
literal characters in filenames other than them not knowing any better?

> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index f5c816e27..77b4ed53a 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -275,20 +275,11 @@ sub list_modified {
>  	my ($only) = @_;
>  	my (%data, @return);
>  	my ($add, $del, $adddel, $file);
> -	my @tracked = ();
> -
> -	if (@ARGV) {
> -		@tracked = map {
> -			chomp $_;
> -			unquote_path($_);
> -		} run_cmd_pipe(qw(git ls-files --), @ARGV);
> -		return if (!@tracked);
> -	}
>  
>  	my $reference = get_diff_reference($patch_mode_revision);
>  	for (run_cmd_pipe(qw(git diff-index --cached
>  			     --numstat --summary), $reference,
> -			     '--', @tracked)) {
> +			     '--', @ARGV)) {
>  		if (($add, $del, $file) =
>  		    /^([-\d]+)	([-\d]+)	(.*)/) {
>  			my ($change, $bin);
> @@ -313,7 +304,7 @@ sub list_modified {
>  		}
>  	}
>  
> -	for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @tracked)) {
> +	for (run_cmd_pipe(qw(git diff-files --numstat --summary --raw --), @ARGV)) {

Such a small and easy change for that big of a perf win.

>  		if (($add, $del, $file) =
>  		    /^([-\d]+)	([-\d]+)	(.*)/) {
>  			$file = unquote_path($file);
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index aaa258daa..f9528fa00 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -412,4 +412,47 @@ test_expect_success 'patch-mode via -i prompts for files' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'add -p handles globs' '
> +	git reset --hard &&
> +
> +	mkdir -p subdir &&
> +	echo base >one.c &&
> +	echo base >subdir/two.c &&
> +	git add "*.c" &&
> +	git commit -m base &&
> +
> +	echo change >one.c &&
> +	echo change >subdir/two.c &&
> +	git add -p "*.c" <<-\EOF &&
> +	y
> +	y
> +	EOF
> +
> +	cat >expect <<-\EOF &&
> +	one.c
> +	subdir/two.c
> +	EOF
> +	git diff --cached --name-only >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_expect_success 'add -p does not expand argument lists' '
> +	git reset --hard &&
> +
> +	echo content >not-changed &&
> +	git add not-changed &&
> +	git commit -m "add not-changed file" &&
> +
> +	echo change >file &&
> +	GIT_TRACE=$(pwd)/trace.out git add -p . <<-\EOF &&
> +	y
> +	EOF
> +
> +	# we know that "file" must be mentioned since we actually
> +	# update it, but we want to be sure that our "." pathspec
> +	# was not expanded into the argument list of any command.
> +	# So look only for "not-changed".
> +	! grep not-changed trace.out
> +'
> +
>  test_done

Tests look sane to me.

-- 
Brandon Williams

  parent reply	other threads:[~2017-03-14 17:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-14 16:30 [PATCH] add--interactive: do not expand pathspecs with ls-files Jeff King
2017-03-14 16:31 ` Jeff King
2017-03-14 17:25 ` Brandon Williams [this message]
2017-03-14 17:31   ` Jeff King
2017-03-14 22:03 ` Junio C Hamano
2017-03-14 22:09   ` Jeff King

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=20170314172504.GA102212@google.com \
    --to=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=mislav.marohnic@gmail.com \
    --cc=peff@peff.net \
    --cc=win@wincent.com \
    /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).