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

[PATCH v2] add -p: fix 2.17.0-rc* regression due to moved code

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 31, 2018, 12:50 UTC
Message-ID
<20180331125058.4506-1-avarab@gmail.com>
In-Reply-To
<20180331123605.30076-1-avarab@gmail.com>

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:

    $ 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;
 					}
 				}
-- 
2.17.0.rc1.321.gba9d0f2565
Previous: Ævar Arnfjörð BjarmasonNext: Phillip Wood
Message 6 of 9 in “add -p: improve help messages”
  1. 0/3 add -p: improve help messagesPhillip Wood, Feb 13, 2018
  2. 3/3 add -p: improve error messagesPhillip Wood, Feb 13, 2018
  3. 1/3 add -p: only display help for active keysPhillip Wood, Feb 13, 2018
  4. 2/3 add -p: Only bind search key if there's more than one hunkPhillip Wood, Feb 13, 2018
  5. add -p: fix 2.17.0-rc* regression due to moved codeÆvar Arnfjörð Bjarmason, Mar 31, 2018
  6. add -p: fix 2.17.0-rc* regression due to moved codeÆvar Arnfjörð Bjarmason, Mar 31, 2018
  7. Phillip WoodMar 31, 2018
  8. Ævar Arnfjörð BjarmasonMar 31, 2018
  9. Junio C HamanoApr 1, 2018

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.