{"thread":{"id":"38084","subject":"[PATCH] git add -i: allow list (un)selection by regexp","startedAt":"2014-12-01T09:31:22Z","lastAt":"2014-12-03T16:13:46Z","messageCount":6,"participants":["Aarni Koskela","Junio C Hamano","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"252772","messageId":"DB3PR04MB25020F247555E521936E676EB7D0@DB3PR04MB250.eurprd04.prod.outlook.com","threadId":"38084","inReplyTo":null,"subject":"[PATCH] git add -i: allow list (un)selection by regexp","fromName":"Aarni Koskela","fromEmail":"aarni.koskela@andersinnovations.com","sentAt":"2014-12-01T09:31:22Z","receivedAt":"2014-12-01T09:31:22Z","isPatch":true,"sender":{"key":"aarni.koskela@andersinnovations.com","avatar":null},"body":"Hello!\n\nThis patch makes it possible to select or unselect files in `git add -i`\nby regular expression instead of unique prefix only.\n\nThe command syntax is `/foo` for selection and `-/foo` for unselection.\nI don't think the syntax will conflict with any existing use cases, but feel\nfree to prove me wrong.\n\nI'm not a Perl programmer, but I've tried to follow the style of the\nexisting code as much as possible. :)\n\nNote I'm currently not on the mailing list, so please cc.\n\nBest regards,\n\nAarni Koskela\n\n>From 53c12d9c9928dc93a57595e92d785ecc0b245390 Mon Sep 17 00:00:00 2001\nFrom: Aarni Koskela <akx@iki.fi>\nDate: Mon, 1 Dec 2014 11:06:10 +0200\nSubject: [PATCH] git-add--interactive: allow list (un)selection by regular\n expression\n\nTeach `list_and_choose` to allow `/regexp` and `-/regexp` syntax to\nselect items based on regular expression match.\n\nFor instance, `/jpg$` will select all options whose display name ends with\n`jpg`.\n\nSigned-off-by: Aarni Koskela <akx@iki.fi>\n---\n git-add--interactive.perl | 27 +++++++++++++++++++++++++++\n 1 file changed, 27 insertions(+)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 1fadd69..34cc603 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -483,6 +483,8 @@ sub is_valid_prefix {\n \t    !($prefix =~ /[\\s,]/) && # separators\n \t    !($prefix =~ /^-/) &&    # deselection\n \t    !($prefix =~ /^\\d+/) &&  # selection\n+\t    !($prefix =~ /^\\//) &&   # regexp selection\n+\t    !($prefix =~ /^-\\//) &&  # regexp unselection\n \t    ($prefix ne '*') &&      # \"all\" wildcard\n \t    ($prefix ne '?');        # prompt help\n }\n@@ -585,6 +587,28 @@ sub list_and_choose {\n \t\t\t    prompt_help_cmd();\n \t\t\tnext TOPLOOP;\n \t\t}\n+\t\tif ($line =~ /^(-)*\\/(.+)$/) {\n+\t\t\tmy $choose = !($1 && $1 eq '-');\n+\t\t\tmy $re = $2;\n+\t\t\tmy $found = 0;\n+\t\t\tfor ($i = 0; $i < @stuff; $i++) {\n+\t\t\t\tmy $val = $stuff[$i];\n+\t\t\t\tmy $ref = ref $val;\n+\t\t\t\tif ($ref eq 'ARRAY') {\n+\t\t\t\t\t$val = $val->[0];\n+\t\t\t\t}\n+\t\t\t\telsif ($ref eq 'HASH') {\n+\t\t\t\t\t$val = $val->{VALUE};\n+\t\t\t\t}\n+\t\t\t\tif ($val =~ /$re/) {\n+\t\t\t\t\t$chosen[$i] = $choose;\n+\t\t\t\t\t$found = 1;\n+\t\t\t\t\tlast if $opts->{SINGLETON};\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tlast if $found && ($opts->{IMMEDIATE});\n+\t\t\tnext TOPLOOP;\n+\t\t}\n \t\tfor my $choice (split(/[\\s,]+/, $line)) {\n \t\t\tmy $choose = 1;\n \t\t\tmy ($bottom, $top);\n@@ -635,6 +659,7 @@ sub singleton_prompt_help_cmd {\n Prompt help:\n 1          - select a numbered item\n foo        - select item based on unique prefix\n+/regexp    - select item based on regular expression\n            - (empty) select nothing\n EOF\n }\n@@ -648,6 +673,8 @@ Prompt help:\n foo        - select item based on unique prefix\n -...       - unselect specified items\n *          - choose all items\n+/regexp    - select items based on regular expression\n+-/regexp   - unselect items based on regular expression\n            - (empty) finish selecting\n EOF\n }\n-- \n1.9.2.msysgit.0\n"},{"id":"252785","messageId":"xmqqiohvqqqv.fsf@gitster.dls.corp.google.com","threadId":"38084","inReplyTo":"DB3PR04MB25020F247555E521936E676EB7D0@DB3PR04MB250.eurprd04.prod.outlook.com","subject":"Re: [PATCH] git add -i: allow list (un)selection by regexp","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-01T16:28:08Z","receivedAt":"2014-12-01T16:28:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aarni Koskela <aarni.koskela@andersinnovations.com> writes:\n\n> Hello!\n>\n> This patch makes it possible to select or unselect files in `git add -i`\n> by regular expression instead of unique prefix only.\n>\n> The command syntax is `/foo` for selection and `-/foo` for unselection.\n> I don't think the syntax will conflict with any existing use cases, but feel\n> free to prove me wrong.\n\nUsually the responsibility to ensure correctness lies on the person\nwho proposes a change, not those who relies on the continued correct\noperation of the existing code.\n\n> I'm not a Perl programmer, but I've tried to follow the style of the\n> existing code as much as possible. :)\n>\n> Note I'm currently not on the mailing list, so please cc.\n>\n> Best regards,\n>\n> Aarni Koskela\n\nAll of the above do not belong to the commit log message.  Please\nhave these commentaries after the three-dash line you have under\nyour Signed-off-by line.\n\n>\n> From 53c12d9c9928dc93a57595e92d785ecc0b245390 Mon Sep 17 00:00:00 2001\n> From: Aarni Koskela <akx@iki.fi>\n> Date: Mon, 1 Dec 2014 11:06:10 +0200\n> Subject: [PATCH] git-add--interactive: allow list (un)selection by regular\n>  expression\n\nRemove these four lines when sending out a patch in the e-mail.\n\n> Teach `list_and_choose` to allow `/regexp` and `-/regexp` syntax to\n> select items based on regular expression match.\n>\n> For instance, `/jpg$` will select all options whose display name ends with\n> `jpg`.\n\nIt has been a long time since I wrote this code, but is this about\nthe selection that happens after showing you a list of filenames to\nchoose from?  \"all options\" together with \"jpg\" made me go \"Huh?\nDoes any of our command have jpeg related options?  We are not in\nthe image processing business\".\n\nPerhaps s/all options/all files/ or something.\n\n> Signed-off-by: Aarni Koskela <akx@iki.fi>\n> ---\n>  git-add--interactive.perl | 27 +++++++++++++++++++++++++++\n>  1 file changed, 27 insertions(+)\n>\n> diff --git a/git-add--interactive.perl b/git-add--interactive.perl\n> index 1fadd69..34cc603 100755\n> --- a/git-add--interactive.perl\n> +++ b/git-add--interactive.perl\n> @@ -483,6 +483,8 @@ sub is_valid_prefix {\n>  \t    !($prefix =~ /[\\s,]/) && # separators\n>  \t    !($prefix =~ /^-/) &&    # deselection\n>  \t    !($prefix =~ /^\\d+/) &&  # selection\n> +\t    !($prefix =~ /^\\//) &&   # regexp selection\n> +\t    !($prefix =~ /^-\\//) &&  # regexp unselection\n>  \t    ($prefix ne '*') &&      # \"all\" wildcard\n>  \t    ($prefix ne '?');        # prompt help\n>  }\n> @@ -585,6 +587,28 @@ sub list_and_choose {\n>  \t\t\t    prompt_help_cmd();\n>  \t\t\tnext TOPLOOP;\n>  \t\t}\n> +\t\tif ($line =~ /^(-)*\\/(.+)$/) {\n\nYou want zero or one '-', not zero or arbitrary large number of '-',\nas a sign to unchoose.  (-)? instead of (-)*, perhaps?\n\n> +\t\t\tmy $choose = !($1 && $1 eq '-');\n\nThe first $1 is an attempt to catch non-negative case where it is\n\"undef\"; it might be more explicit this way?\n\n\t\t\tmy $choose = !(defined $1);\n\n> +\t\t\tmy $re = $2;\n\nMental note.  $re is an end-user supplied random string that may or\nmay not be a valid regular expression.\n\n> +\t\t\tmy $found = 0;\n> +\t\t\tfor ($i = 0; $i < @stuff; $i++) {\n> +\t\t\t\tmy $val = $stuff[$i];\n> +\t\t\t\tmy $ref = ref $val;\n> +\t\t\t\tif ($ref eq 'ARRAY') {\n> +\t\t\t\t\t$val = $val->[0];\n> +\t\t\t\t}\n> +\t\t\t\telsif ($ref eq 'HASH') {\n> +\t\t\t\t\t$val = $val->{VALUE};\n> +\t\t\t\t}\n> +\t\t\t\tif ($val =~ /$re/) {\n\n... which makes me wonder what happens when $re is a bogus regular\nexpression here.  Does the program die?  Does the user get an error\nmessage about bad regexp and the condition to this if expression is\nfalse?  Something else?\n\nPerhaps validating and catching regexp errors early like this might\nbe sufficient:\n\n        \t\tmy $re = eval { qr/$2/ };\n                        if (!$re) {\n\t\t\t\tprint STDERR \"$@\\n\";\n                                next TOPLOOP;\n\t\t\t}\n\n\nThanks.\n"},{"id":"252857","messageId":"DB3PR04MB2509E51F1DE708549483845EB7A0@DB3PR04MB250.eurprd04.prod.outlook.com","threadId":"38084","inReplyTo":"xmqqiohvqqqv.fsf@gitster.dls.corp.google.com","subject":"RE: [PATCH] git add -i: allow list (un)selection by regexp","fromName":"Aarni Koskela","fromEmail":"aarni.koskela@andersinnovations.com","sentAt":"2014-12-02T12:12:48Z","receivedAt":"2014-12-02T12:12:48Z","isPatch":true,"sender":{"key":"aarni.koskela@andersinnovations.com","avatar":null},"body":">From 9096652a71666920ae8d59dd4317d536ba974d5b Mon Sep 17 00:00:00 2001\nFrom: Aarni Koskela <akx@iki.fi>\nDate: Tue, 2 Dec 2014 13:56:15 +0200\nSubject: [PATCH] git-add--interactive: allow list (un)selection by regular\n expression\n\nTeach `list_and_choose` to allow `/regexp` and `-/regexp` syntax to\nselect items based on regular expression match.\n\nThis feature works in all list menus in `git-add--interactive`, and is not\nlimited to file menus only.\n\nFor instance, in file lists, `/\\.c$` will select all files whose extension\nis `.c`.  In option menus, such as the main menu, `/pa` could be used to\nchoose the `patch` option.\n\nSigned-off-by: Aarni Koskela <akx@iki.fi>\n---\n\nThank you for the insightful comments, Junio, and sorry for the confusion\nregarding email-patch formatting.  Hoping I get it right this time.\n\n> Usually the responsibility to ensure correctness lies on the person who\n> proposes a change, not those who relies on the continued correct operation\n> of the existing code.\n\nYou're of course absolutely right.  My point was that I can't think of an use\ncase where one would need to otherwise have \"/\" or \"-/\" as the first characters\nof input in a list_and_choose situation, but someone else might.\n\n> [...] but is this about the selection that happens after showing you a\n> list of filenames to choose from?\n\nI clarified this in the commit message.  Selection by regexp works in all\nlist_and_choose situations, including the main menu of `git add -i`, hence \"option\".\n\nRegarding the unchoose quantifier -- yes, silly me.\n\nAnd regarding error checking for the regular expression, you're right -- the\nprogram promptly blew up when entering an invalid regexp.  I incorporated your\nsuggestion for error checking, with the addition of using the `error_msg` sub\nfor colorized error reporting.\n\nBest regards,\n\nAarni Koskela\n\n git-add--interactive.perl | 49 +++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 49 insertions(+)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex 1fadd69..28e4c2d 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -483,6 +483,8 @@ sub is_valid_prefix {\n \t    !($prefix =~ /[\\s,]/) && # separators\n \t    !($prefix =~ /^-/) &&    # deselection\n \t    !($prefix =~ /^\\d+/) &&  # selection\n+\t    !($prefix =~ /^\\//) &&   # regexp selection\n+\t    !($prefix =~ /^-\\//) &&  # regexp unselection\n \t    ($prefix ne '*') &&      # \"all\" wildcard\n \t    ($prefix ne '?');        # prompt help\n }\n@@ -585,6 +587,50 @@ sub list_and_choose {\n \t\t\t    prompt_help_cmd();\n \t\t\tnext TOPLOOP;\n \t\t}\n+\t\tif ($line =~ /^(-)?\\/(.+)$/) {\n+\t\t\t# The first capture group (\"-\") being missing means \"choose\" is\n+\t\t\t# requested. If the first group exists at all, \"unchoose\" is\n+\t\t\t# requested.\n+\t\t\tmy $choose = !(defined $1);\n+\n+\t\t\t# Validate the regular expression and complain if compilation failed.\n+\t\t\tmy $re = eval { qr/$2/ };\n+\t\t\tif (!$re) {\n+\t\t\t\terror_msg \"Invalid regular expression:\\n  $@\\n\";\n+\t\t\t\tnext TOPLOOP;\n+\t\t\t}\n+\n+\t\t\tmy $found = 0;\n+\t\t\tfor ($i = 0; $i < @stuff; $i++) {\n+\t\t\t\tmy $val = $stuff[$i];\n+\n+\t\t\t\t# Figure out the display value for $val.\n+\t\t\t\t# Some lists passed to list_and_choose contain\n+\t\t\t\t# items other than strings; in order to match\n+\t\t\t\t# regexps against them, we need to extract the\n+\t\t\t\t# displayed string. The logic here is approximately\n+\t\t\t\t# equivalent to the display logic above.\n+\n+\t\t\t\tmy $ref = ref $val;\n+\t\t\t\tif ($ref eq 'ARRAY') {\n+\t\t\t\t\t$val = $val->[0];\n+\t\t\t\t}\n+\t\t\t\telsif ($ref eq 'HASH') {\n+\t\t\t\t\t$val = $val->{VALUE};\n+\t\t\t\t}\n+\n+\t\t\t\t# Match the string value against the regexp,\n+\t\t\t\t# then act accordingly.\n+\n+\t\t\t\tif ($val =~ $re) {\n+\t\t\t\t\t$chosen[$i] = $choose;\n+\t\t\t\t\t$found = $found || $choose;\n+\t\t\t\t\tlast if $choose && $opts->{SINGLETON};\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tlast if $found && ($opts->{IMMEDIATE});\n+\t\t\tnext TOPLOOP;\n+\t\t}\n \t\tfor my $choice (split(/[\\s,]+/, $line)) {\n \t\t\tmy $choose = 1;\n \t\t\tmy ($bottom, $top);\n@@ -635,6 +681,7 @@ sub singleton_prompt_help_cmd {\n Prompt help:\n 1          - select a numbered item\n foo        - select item based on unique prefix\n+/regexp    - select item based on regular expression\n            - (empty) select nothing\n EOF\n }\n@@ -648,6 +695,8 @@ Prompt help:\n foo        - select item based on unique prefix\n -...       - unselect specified items\n *          - choose all items\n+/regexp    - select items based on regular expression\n+-/regexp   - unselect items based on regular expression\n            - (empty) finish selecting\n EOF\n }\n-- \n1.9.2.msysgit.0\n\n\n-----Original Message-----\nFrom: Junio C Hamano [mailto:gitster@pobox.com] \nSent: 1. joulukuuta 2014 18:28\nTo: Aarni Koskela\nCc: git@vger.kernel.org; akx@iki.fi\nSubject: Re: [PATCH] git add -i: allow list (un)selection by regexp\n\nAarni Koskela <aarni.koskela@andersinnovations.com> writes:\n\n> Hello!\n>\n> This patch makes it possible to select or unselect files in `git add \n> -i` by regular expression instead of unique prefix only.\n>\n> The command syntax is `/foo` for selection and `-/foo` for unselection.\n> I don't think the syntax will conflict with any existing use cases, \n> but feel free to prove me wrong.\n\nUsually the responsibility to ensure correctness lies on the person who proposes a change, not those who relies on the continued correct operation of the existing code.\n\n> I'm not a Perl programmer, but I've tried to follow the style of the \n> existing code as much as possible. :)\n>\n> Note I'm currently not on the mailing list, so please cc.\n>\n> Best regards,\n>\n> Aarni Koskela\n\nAll of the above do not belong to the commit log message.  Please have these commentaries after the three-dash line you have under your Signed-off-by line.\n\n>\n> From 53c12d9c9928dc93a57595e92d785ecc0b245390 Mon Sep 17 00:00:00 2001\n> From: Aarni Koskela <akx@iki.fi>\n> Date: Mon, 1 Dec 2014 11:06:10 +0200\n> Subject: [PATCH] git-add--interactive: allow list (un)selection by \n> regular  expression\n\nRemove these four lines when sending out a patch in the e-mail.\n\n> Teach `list_and_choose` to allow `/regexp` and `-/regexp` syntax to \n> select items based on regular expression match.\n>\n> For instance, `/jpg$` will select all options whose display name ends \n> with `jpg`.\n\nIt has been a long time since I wrote this code, but is this about the selection that happens after showing you a list of filenames to choose from?  \"all options\" together with \"jpg\" made me go \"Huh?\nDoes any of our command have jpeg related options?  We are not in the image processing business\".\n\nPerhaps s/all options/all files/ or something.\n\n> Signed-off-by: Aarni Koskela <akx@iki.fi>\n> ---\n>  git-add--interactive.perl | 27 +++++++++++++++++++++++++++\n>  1 file changed, 27 insertions(+)\n>\n> diff --git a/git-add--interactive.perl b/git-add--interactive.perl \n> index 1fadd69..34cc603 100755\n> --- a/git-add--interactive.perl\n> +++ b/git-add--interactive.perl\n> @@ -483,6 +483,8 @@ sub is_valid_prefix {\n>  \t    !($prefix =~ /[\\s,]/) && # separators\n>  \t    !($prefix =~ /^-/) &&    # deselection\n>  \t    !($prefix =~ /^\\d+/) &&  # selection\n> +\t    !($prefix =~ /^\\//) &&   # regexp selection\n> +\t    !($prefix =~ /^-\\//) &&  # regexp unselection\n>  \t    ($prefix ne '*') &&      # \"all\" wildcard\n>  \t    ($prefix ne '?');        # prompt help\n>  }\n> @@ -585,6 +587,28 @@ sub list_and_choose {\n>  \t\t\t    prompt_help_cmd();\n>  \t\t\tnext TOPLOOP;\n>  \t\t}\n> +\t\tif ($line =~ /^(-)*\\/(.+)$/) {\n\nYou want zero or one '-', not zero or arbitrary large number of '-', as a sign to unchoose.  (-)? instead of (-)*, perhaps?\n\n> +\t\t\tmy $choose = !($1 && $1 eq '-');\n\nThe first $1 is an attempt to catch non-negative case where it is \"undef\"; it might be more explicit this way?\n\n\t\t\tmy $choose = !(defined $1);\n\n> +\t\t\tmy $re = $2;\n\nMental note.  $re is an end-user supplied random string that may or may not be a valid regular expression.\n\n> +\t\t\tmy $found = 0;\n> +\t\t\tfor ($i = 0; $i < @stuff; $i++) {\n> +\t\t\t\tmy $val = $stuff[$i];\n> +\t\t\t\tmy $ref = ref $val;\n> +\t\t\t\tif ($ref eq 'ARRAY') {\n> +\t\t\t\t\t$val = $val->[0];\n> +\t\t\t\t}\n> +\t\t\t\telsif ($ref eq 'HASH') {\n> +\t\t\t\t\t$val = $val->{VALUE};\n> +\t\t\t\t}\n> +\t\t\t\tif ($val =~ /$re/) {\n\n... which makes me wonder what happens when $re is a bogus regular expression here.  Does the program die?  Does the user get an error message about bad regexp and the condition to this if expression is false?  Something else?\n\nPerhaps validating and catching regexp errors early like this might be sufficient:\n\n        \t\tmy $re = eval { qr/$2/ };\n                        if (!$re) {\n\t\t\t\tprint STDERR \"$@\\n\";\n                                next TOPLOOP;\n\t\t\t}\n\n\nThanks.\n"},{"id":"252878","messageId":"xmqq8uiqm081.fsf@gitster.dls.corp.google.com","threadId":"38084","inReplyTo":"DB3PR04MB2509E51F1DE708549483845EB7A0@DB3PR04MB250.eurprd04.prod.outlook.com","subject":"Re: [PATCH] git add -i: allow list (un)selection by regexp","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-02T17:26:54Z","receivedAt":"2014-12-02T17:26:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aarni Koskela <aarni.koskela@andersinnovations.com> writes:\n\n> From 9096652a71666920ae8d59dd4317d536ba974d5b Mon Sep 17 00:00:00 2001\n> From: Aarni Koskela <akx@iki.fi>\n> Date: Tue, 2 Dec 2014 13:56:15 +0200\n> Subject: [PATCH] git-add--interactive: allow list (un)selection by regular\n>  expression\n\nRemove the three lines from the top, move the content on Subject: to\nthe subject of the e-mail.\n\nOther than that, everything I see in this message is very well\ndone.\n\nThanks, will queue.\n\n>\n> Teach `list_and_choose` to allow `/regexp` and `-/regexp` syntax to\n> select items based on regular expression match.\n>\n> This feature works in all list menus in `git-add--interactive`, and is not\n> limited to file menus only.\n>\n> For instance, in file lists, `/\\.c$` will select all files whose extension\n> is `.c`.  In option menus, such as the main menu, `/pa` could be used to\n> choose the `patch` option.\n>\n> Signed-off-by: Aarni Koskela <akx@iki.fi>\n> ---\n>\n> Thank you for the insightful comments, Junio, and sorry for the confusion\n> regarding email-patch formatting.  Hoping I get it right this time.\n>\n>> Usually the responsibility to ensure correctness lies on the person who\n>> proposes a change, not those who relies on the continued correct operation\n>> of the existing code.\n>\n> You're of course absolutely right.  My point was that I can't think of an use\n> case where one would need to otherwise have \"/\" or \"-/\" as the first characters\n> of input in a list_and_choose situation, but someone else might.\n>\n>> [...] but is this about the selection that happens after showing you a\n>> list of filenames to choose from?\n>\n> I clarified this in the commit message.  Selection by regexp works in all\n> list_and_choose situations, including the main menu of `git add -i`, hence \"option\".\n>\n> Regarding the unchoose quantifier -- yes, silly me.\n>\n> And regarding error checking for the regular expression, you're right -- the\n> program promptly blew up when entering an invalid regexp.  I incorporated your\n> suggestion for error checking, with the addition of using the `error_msg` sub\n> for colorized error reporting.\n>\n> Best regards,\n>\n> Aarni Koskela\n>\n>  git-add--interactive.perl | 49 +++++++++++++++++++++++++++++++++++++++++++++++\n>  1 file changed, 49 insertions(+)\n>\n> diff --git a/git-add--interactive.perl b/git-add--interactive.perl\n> index 1fadd69..28e4c2d 100755\n> --- a/git-add--interactive.perl\n> +++ b/git-add--interactive.perl\n> @@ -483,6 +483,8 @@ sub is_valid_prefix {\n>  \t    !($prefix =~ /[\\s,]/) && # separators\n>  \t    !($prefix =~ /^-/) &&    # deselection\n>  \t    !($prefix =~ /^\\d+/) &&  # selection\n> +\t    !($prefix =~ /^\\//) &&   # regexp selection\n> +\t    !($prefix =~ /^-\\//) &&  # regexp unselection\n>  \t    ($prefix ne '*') &&      # \"all\" wildcard\n>  \t    ($prefix ne '?');        # prompt help\n>  }\n> @@ -585,6 +587,50 @@ sub list_and_choose {\n>  \t\t\t    prompt_help_cmd();\n>  \t\t\tnext TOPLOOP;\n>  \t\t}\n> +\t\tif ($line =~ /^(-)?\\/(.+)$/) {\n> +\t\t\t# The first capture group (\"-\") being missing means \"choose\" is\n> +\t\t\t# requested. If the first group exists at all, \"unchoose\" is\n> +\t\t\t# requested.\n> +\t\t\tmy $choose = !(defined $1);\n> +\n> +\t\t\t# Validate the regular expression and complain if compilation failed.\n> +\t\t\tmy $re = eval { qr/$2/ };\n> +\t\t\tif (!$re) {\n> +\t\t\t\terror_msg \"Invalid regular expression:\\n  $@\\n\";\n> +\t\t\t\tnext TOPLOOP;\n> +\t\t\t}\n> +\n> +\t\t\tmy $found = 0;\n> +\t\t\tfor ($i = 0; $i < @stuff; $i++) {\n> +\t\t\t\tmy $val = $stuff[$i];\n> +\n> +\t\t\t\t# Figure out the display value for $val.\n> +\t\t\t\t# Some lists passed to list_and_choose contain\n> +\t\t\t\t# items other than strings; in order to match\n> +\t\t\t\t# regexps against them, we need to extract the\n> +\t\t\t\t# displayed string. The logic here is approximately\n> +\t\t\t\t# equivalent to the display logic above.\n> +\n> +\t\t\t\tmy $ref = ref $val;\n> +\t\t\t\tif ($ref eq 'ARRAY') {\n> +\t\t\t\t\t$val = $val->[0];\n> +\t\t\t\t}\n> +\t\t\t\telsif ($ref eq 'HASH') {\n> +\t\t\t\t\t$val = $val->{VALUE};\n> +\t\t\t\t}\n> +\n> +\t\t\t\t# Match the string value against the regexp,\n> +\t\t\t\t# then act accordingly.\n> +\n> +\t\t\t\tif ($val =~ $re) {\n> +\t\t\t\t\t$chosen[$i] = $choose;\n> +\t\t\t\t\t$found = $found || $choose;\n> +\t\t\t\t\tlast if $choose && $opts->{SINGLETON};\n> +\t\t\t\t}\n> +\t\t\t}\n> +\t\t\tlast if $found && ($opts->{IMMEDIATE});\n> +\t\t\tnext TOPLOOP;\n> +\t\t}\n>  \t\tfor my $choice (split(/[\\s,]+/, $line)) {\n>  \t\t\tmy $choose = 1;\n>  \t\t\tmy ($bottom, $top);\n> @@ -635,6 +681,7 @@ sub singleton_prompt_help_cmd {\n>  Prompt help:\n>  1          - select a numbered item\n>  foo        - select item based on unique prefix\n> +/regexp    - select item based on regular expression\n>             - (empty) select nothing\n>  EOF\n>  }\n> @@ -648,6 +695,8 @@ Prompt help:\n>  foo        - select item based on unique prefix\n>  -...       - unselect specified items\n>  *          - choose all items\n> +/regexp    - select items based on regular expression\n> +-/regexp   - unselect items based on regular expression\n>             - (empty) finish selecting\n>  EOF\n>  }\n"},{"id":"252902","messageId":"CAPig+cSAUkG7APutRcb3AG1hLCBQACThfDBi-p75CSk_UsSK7Q@mail.gmail.com","threadId":"38084","inReplyTo":"xmqq8uiqm081.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] git add -i: allow list (un)selection by regexp","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-12-03T00:08:46Z","receivedAt":"2014-12-03T00:08:46Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Dec 2, 2014 at 12:26 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Aarni Koskela <aarni.koskela@andersinnovations.com> writes:\n>\n>> From 9096652a71666920ae8d59dd4317d536ba974d5b Mon Sep 17 00:00:00 2001\n>> From: Aarni Koskela <akx@iki.fi>\n>> Date: Tue, 2 Dec 2014 13:56:15 +0200\n>> Subject: [PATCH] git-add--interactive: allow list (un)selection by regular\n>>  expression\n>\n> Remove the three lines from the top, move the content on Subject: to\n> the subject of the e-mail.\n>\n> Other than that, everything I see in this message is very well\n> done.\n>\n> Thanks, will queue.\n\nThis change deserve a documentation update\n(Documentation/git-add.txt), does it not?\n\nTests too, perhaps (assuming other git-add--interactive selections\nselection modes are already tested)?\n"},{"id":"252952","messageId":"xmqqwq68k8xx.fsf@gitster.dls.corp.google.com","threadId":"38084","inReplyTo":"CAPig+cSAUkG7APutRcb3AG1hLCBQACThfDBi-p75CSk_UsSK7Q@mail.gmail.com","subject":"Re: [PATCH] git add -i: allow list (un)selection by regexp","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-03T16:13:46Z","receivedAt":"2014-12-03T16:13:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Tue, Dec 2, 2014 at 12:26 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Aarni Koskela <aarni.koskela@andersinnovations.com> writes:\n>>\n>>> From 9096652a71666920ae8d59dd4317d536ba974d5b Mon Sep 17 00:00:00 2001\n>>> From: Aarni Koskela <akx@iki.fi>\n>>> Date: Tue, 2 Dec 2014 13:56:15 +0200\n>>> Subject: [PATCH] git-add--interactive: allow list (un)selection by regular\n>>>  expression\n>>\n>> Remove the three lines from the top, move the content on Subject: to\n>> the subject of the e-mail.\n>>\n>> Other than that, everything I see in this message is very well\n>> done.\n>>\n>> Thanks, will queue.\n>\n> This change deserve a documentation update\n> (Documentation/git-add.txt), does it not?\n\nSure.  Any volunteers?\n\n> Tests too, perhaps (assuming other git-add--interactive selections\n> selection modes are already tested)?\n\nThat too ;-).\n"}]}