All of lore.kernel.org
 help / color / mirror / Atom feed
From: avarab@gmail.com (Ævar Arnfjörð Bjarmason)
To: phillip.wood@dunelm.org.uk
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH v2] add -p: fix 2.17.0-rc* regression due to moved code
Date: Sat, 31 Mar 2018 19:13:40 +0200	[thread overview]
Message-ID: <87bmf4w4l7.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <f60a2014-3b02-3eae-76cb-950330113afa@talktalk.net> From: Ævar Arnfjörð Bjarmason <avarab@gmail.com>


On Sat, Mar 31 2018, Phillip Wood wrote:

> On 31/03/18 13:50, Ævar Arnfjörð Bjarmason wrote:
>> Fix a regression in 88f6ffc1c2 ("add -p: only bind search key if
>> there's more than one hunk", 2018-02-13) which is present in
>> 2.17.0-rc*, but not 2.16.0.
>>
>> In Perl, regex variables like $1 always refer to the last regex
>> match. When the aforementioned change added a new regex match between
>> the old match and the corresponding code that was expecting $1, the $1
>> variable would always be undef, since the newly inserted regex match
>> doesn't have any captures.
>>
>> As a result the "/" feature to search for a string in a hunk by regex
>> completely broke, on git.git:
>
> Good catch, I could have sworn I'd tested my patch but I obviously
> didn't notice the warning (I've got interactive.singlekey set so it
> prints the warning and then prompts as it always has done). Calling it
> completely broken is perhaps a little harsh as it does work if you
> enter the regex again and with interactive.singlekey set you only have
> to enter the regex once.

To clarify by "completely broken" I mean the "/" feature itself, but
yeah, you can still search by regex since we just so happen to have the
fallback codepath intended to catch "/" without an accompanying string,
which'll kick in and ask you for the regex since $1 will be undef at
that point, and will thus coerce stringwise to "".

> Thanks for fixing it
>
> Phillip
>>
>>      $ perl -pi -e 's/Git/Tig/g' README.md
>>      $ ./git --exec-path=$PWD add -p
>>      [..]
>>      Stage this hunk [y,n,q,a,d,j,J,g,/,s,e,?]? s
>>      Split into 4 hunks.
>>      [...]
>>      Stage this hunk [y,n,q,a,d,j,J,g,/,s,e,?]? /Many
>>      Use of uninitialized value $1 in string eq at /home/avar/g/git/git-add--interactive line 1568, <STDIN> line 1.
>>      search for regex? Many
>>
>> I.e. the initial "/regex" command wouldn't work, and would always emit
>> a warning and ask again for a regex, now it works as intended again.
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>
>> Of course I just noticed the grammar errors in the commit message
>> after sending. Here's a v2 with that fixed, also genreated the patch
>> with -U6 to make it clear what's going on.
>>
>>   git-add--interactive.perl | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
>> index d190469cd8..c1f52e457f 100755
>> --- a/git-add--interactive.perl
>> +++ b/git-add--interactive.perl
>> @@ -1561,13 +1561,13 @@ sub patch_update_file {
>>   			elsif ($line =~ m|^/(.*)|) {
>>   				my $regex = $1;
>>   				unless ($other =~ m|/|) {
>>   					error_msg __("No other hunks to search\n");
>>   					next;
>>   				}
>> -				if ($1 eq "") {
>> +				if ($regex eq "") {
>>   					print colored $prompt_color, __("search for regex? ");
>>   					$regex = <STDIN>;
>>   					if (defined $regex) {
>>   						chomp $regex;
>>   					}
>>   				}
>>

  reply	other threads:[~2018-03-31 17:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13 10:32 [PATCH 0/3] add -p: improve help messages Phillip Wood
2018-02-13 10:32 ` [PATCH 1/3] add -p: only display help for active keys Phillip Wood
2018-02-13 10:32 ` [PATCH 2/3] add -p: Only bind search key if there's more than one hunk Phillip Wood
2018-03-31 12:36   ` [PATCH] add -p: fix 2.17.0-rc* regression due to moved code Ævar Arnfjörð Bjarmason
2018-03-31 12:50     ` [PATCH v2] " Ævar Arnfjörð Bjarmason
2018-03-31 16:26       ` Phillip Wood
2018-03-31 17:13         ` Ævar Arnfjörð Bjarmason [this message]
2018-04-01  5:00       ` Junio C Hamano
2018-02-13 10:32 ` [PATCH 3/3] add -p: improve error messages Phillip Wood

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

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

  git send-email \
    --in-reply-to=87bmf4w4l7.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.