{"thread":{"id":"16232","subject":"[PATCH] git send-email: edit recipient addresses with the --compose flag","startedAt":"2008-11-09T12:59:48Z","lastAt":"2008-11-11T22:14:21Z","messageCount":17,"participants":["Ian Hilt","Francis Galiegue","Junio C Hamano","Aristotle Pagaltzis","Tait"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"95255","messageId":"1226235588-2997-1-git-send-email-ian.hilt@gmx.com","threadId":"16232","inReplyTo":null,"subject":"[PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Ian Hilt","fromEmail":"ian.hilt@gmx.com","sentAt":"2008-11-09T12:59:48Z","receivedAt":"2008-11-09T12:59:48Z","isPatch":true,"sender":{"key":"ian.hilt@gmx.com","avatar":null},"body":"Sometimes specifying the recipient addresses can be tedious on the\ncommand-line.  This commit will allow the user to edit the recipient\naddresses in their editor of choice.\n\nSigned-off-by: Ian Hilt <ian.hilt@gmx.com>\n---\nThis is on top of Pierre's most recent series.  I'm not exactly happy\nwith the way it turned out, but it seems to function correctly.\nComments are most welcome.\n\n  [ This is a resend.  I don't know what happened to the first mail I\n    sent to the list. ]\n\n git-send-email.perl |   60 ++++++++++++++++++++++++++++++++++++++++++++++++--\n 1 files changed, 57 insertions(+), 3 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex fd72127..3a22767 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -455,6 +455,9 @@ if ($compose) {\n \tmy $tpl_sender = $sender || $repoauthor || $repocommitter || '';\n \tmy $tpl_subject = $initial_subject || '';\n \tmy $tpl_reply_to = $initial_reply_to || '';\n+\tmy $tpl_to = join(', ', @to);\n+\tmy $tpl_cc = join(', ', @initial_cc);\n+\tmy $tpl_bcc = join(', ', @bcclist);\n \n \tprint C <<EOT;\n From $tpl_sender # This line is ignored.\n@@ -464,6 +467,9 @@ GIT: for the patch you are writing.\n GIT:\n GIT: Clear the body content if you don't wish to send a summary.\n From: $tpl_sender\n+To: $tpl_to\n+Cc: $tpl_cc\n+Bcc: $tpl_bcc\n Subject: $tpl_subject\n In-Reply-To: $tpl_reply_to\n \n@@ -487,9 +493,31 @@ EOT\n \topen(C,\"<\",$compose_filename)\n \t\tor die \"Failed to open $compose_filename : \" . $!;\n \n+\tlocal $/;\n+\tmy $c_file = <C>;\n+\t$/ = \"\\n\";\n+\tclose(C);\n+\n+\tmy (@tmp_to, @tmp_cc, @tmp_bcc);\n+\n+\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n+\t\t@tmp_to = get_recipients($1);\n+\t}\n+\tif ($c_file =~ /^Cc:\\s*+(.+)\\s*\\nBcc:/ism) {\n+\t\t@tmp_cc = get_recipients($1);\n+\t}\n+\tif ($c_file =~ /^Bcc:\\s*+(.+)\\s*\\nSubject:/ism) {\n+\t\t@tmp_bcc = get_recipients($1);\n+\t}\n+\n+\n \tmy $need_8bit_cte = file_has_nonascii($compose_filename);\n \tmy $in_body = 0;\n \tmy $summary_empty = 1;\n+\n+\topen(C,\"<\",$compose_filename)\n+\t\tor die \"Failed to open $compose_filename : \" . $!;\n+\n \twhile(<C>) {\n \t\tnext if m/^GIT: /;\n \t\tif ($in_body) {\n@@ -518,15 +546,21 @@ EOT\n \t\t} elsif (/^From:\\s*(.+)\\s*$/i) {\n \t\t\t$sender = $1;\n \t\t\tnext;\n-\t\t} elsif (/^(?:To|Cc|Bcc):/i) {\n-\t\t\tprint \"To/Cc/Bcc fields are not interpreted yet, they have been ignored\\n\";\n-\t\t\tnext;\n \t\t}\n \t\tprint C2 $_;\n \t}\n \tclose(C);\n \tclose(C2);\n \n+\tif (@tmp_to) {\n+\t\t@to = @tmp_to;\n+\t}\n+\tif (@tmp_cc) {\n+\t\t@initial_cc = @tmp_cc;\n+\t}\n+\tif (@tmp_bcc) {\n+\t\t@bcclist = @tmp_bcc;\n+\t}\n \tif ($summary_empty) {\n \t\tprint \"Summary email is empty, skpping it\\n\";\n \t\t$compose = -1;\n@@ -1070,3 +1104,23 @@ sub file_has_nonascii {\n \t}\n \treturn 0;\n }\n+\n+sub get_recipients {\n+\tmy $match = shift(@_);\n+\tmy @recipients = split(/\\s*,\\s*/, $match);\n+\tfor (my $i = 0; $i <= $#recipients; ++$i) {\n+\t\tif ($recipients[$i] eq \"\") {\n+\t\t\tsplice(@recipients, $i, 1);\n+\t\t} elsif ($recipients[$i] =~ /\"/) {\n+\t\t\tmy $x = $i;\n+\t\t\tmy $tmp;\n+\t\t\twhile ($recipients[$i] !~ /</) {\n+\t\t\t\t$tmp = join(', ', $recipients[$i],$recipients[$i+1]);\n+\t\t\t\t++$i;\n+\t\t\t\tsplice(@recipients, $i, 1, $tmp);\n+\t\t\t}\n+\t\t\tsplice(@recipients, $x, $i, $tmp);\n+\t\t}\n+\t}\n+\treturn @recipients;\n+}\n-- \n1.6.0.3.523.g304d0\n"},{"id":"95258","messageId":"200811091513.55544.fg@one2team.com","threadId":"16232","inReplyTo":"1226235588-2997-1-git-send-email-ian.hilt@gmx.com","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Francis Galiegue","fromEmail":"fg@one2team.com","sentAt":"2008-11-09T14:13:55Z","receivedAt":"2008-11-09T14:13:55Z","isPatch":true,"sender":{"key":"fg@one2team.com","avatar":null},"body":"Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n> Sometimes specifying the recipient addresses can be tedious on the\n> command-line.  This commit will allow the user to edit the recipient\n> addresses in their editor of choice.\n>\n> Signed-off-by: Ian Hilt <ian.hilt@gmx.com>\n> ---\n[...]\n> +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n\nGreedy operators are only supported with perl 5.10 or more... I think it's a \nbad idea to use them...\n\n-- \nFrancis Galiegue\nONE2TEAM\nIngénieur système\nMob : +33 (0) 6 83 87 78 75\nTel : +33 (0) 1 78 94 55 52\nfge@one2team.com\n40 avenue Raymond Poincaré\n75116 Paris\n"},{"id":"95280","messageId":"alpine.LFD.2.00.0811091344480.20499@sys-0.hiltweb.site","threadId":"16232","inReplyTo":"200811091513.55544.fg@one2team.com","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Ian Hilt","fromEmail":"ian.hilt@gmx.com","sentAt":"2008-11-09T20:09:21Z","receivedAt":"2008-11-09T20:09:21Z","isPatch":true,"sender":{"key":"ian.hilt@gmx.com","avatar":null},"body":"On Sun, 9 Nov 2008, Francis Galiegue wrote:\n> Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n> > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> \n> Greedy operators are only supported with perl 5.10 or more... I think it's a \n> bad idea to use them...\n\nThe problem here was that a space should follow the field, but it may\nnot.  The user may unwarily backup over it.  \"\\s*\" would match this\ncase.\n\nBut if there is a space, it is included in the \"(.+)\".  So I tried\n\"\\s+\", which did not include the space, but it won't include the first\naddress if there isn't a space after the field.\n\nThe quantified subpattern seemed to do the trick.  But, if it could\nresult in a dependency issue, I would agree this would be a bad idea.\n\n\n\tIan"},{"id":"95287","messageId":"7viqqwa6wo.fsf@gitster.siamese.dyndns.org","threadId":"16232","inReplyTo":"alpine.LFD.2.00.0811091344480.20499@sys-0.hiltweb.site","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-11-09T22:09:11Z","receivedAt":"2008-11-09T22:09:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ian Hilt <ian.hilt@gmx.com> writes:\n\n> On Sun, 9 Nov 2008, Francis Galiegue wrote:\n>> Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n>> > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n>> \n>> Greedy operators are only supported with perl 5.10 or more... I think it's a \n>> bad idea to use them...\n>\n> The problem here was that a space should follow the field, but it may\n> not.  The user may unwarily backup over it.  \"\\s*\" would match this\n> case.\n>\n> But if there is a space, it is included in the \"(.+)\".  So I tried\n> \"\\s+\", which did not include the space, but it won't include the first\n> address if there isn't a space after the field.\n>\n> The quantified subpattern seemed to do the trick.  But, if it could\n> result in a dependency issue, I would agree this would be a bad idea.\n\nYou expect something non-blank there anyway, so why not do:\n\n\tTo:\\s*(\\S.*?)\\s*\\n....\n"},{"id":"95295","messageId":"alpine.LFD.2.00.0811091910570.21142@sys-0.hiltweb.site","threadId":"16232","inReplyTo":"7viqqwa6wo.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Ian Hilt","fromEmail":"ian.hilt@gmx.com","sentAt":"2008-11-10T00:38:30Z","receivedAt":"2008-11-10T00:38:30Z","isPatch":true,"sender":{"key":"ian.hilt@gmx.com","avatar":null},"body":"On Sun, 9 Nov 2008, Junio C Hamano wrote:\n> Ian Hilt <ian.hilt@gmx.com> writes:\n> \n> > On Sun, 9 Nov 2008, Francis Galiegue wrote:\n> >> Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n> >> > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> >> \n> >> Greedy operators are only supported with perl 5.10 or more... I think it's a \n> >> bad idea to use them...\n> >\n> > The problem here was that a space should follow the field, but it may\n> > not.  The user may unwarily backup over it.  \"\\s*\" would match this\n> > case.\n> >\n> > But if there is a space, it is included in the \"(.+)\".  So I tried\n> > \"\\s+\", which did not include the space, but it won't include the first\n> > address if there isn't a space after the field.\n> >\n> > The quantified subpattern seemed to do the trick.  But, if it could\n> > result in a dependency issue, I would agree this would be a bad idea.\n> \n> You expect something non-blank there anyway, so why not do:\n> \n> \tTo:\\s*(\\S.*?)\\s*\\n....\n\nThat works.  Although, I seem to be missing Francis' point.  According\nto perlre, a quantified subpattern is \"greedy\".  So a \"greedy operator\"\nis any one of the standard quantified subpatterns.  The \"+\" and \"?\"\nmodify its matching behavior.  And it seems to me that it _has_ to use a\nq.s. to work ..."},{"id":"95302","messageId":"7vbpwo88gh.fsf@gitster.siamese.dyndns.org","threadId":"16232","inReplyTo":"alpine.LFD.2.00.0811091910570.21142@sys-0.hiltweb.site","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-11-10T05:18:38Z","receivedAt":"2008-11-10T05:18:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ian Hilt <ian.hilt@gmx.com> writes:\n\n> On Sun, 9 Nov 2008, Junio C Hamano wrote:\n>> Ian Hilt <ian.hilt@gmx.com> writes:\n>> \n>> > On Sun, 9 Nov 2008, Francis Galiegue wrote:\n>> >> Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n>> >> > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n>> >> \n>> >> Greedy operators are only supported with perl 5.10 or more... I think it's a \n>> >> bad idea to use them...\n>> ...\n>> You expect something non-blank there anyway, so why not do:\n>> \n>> \tTo:\\s*(\\S.*?)\\s*\\n....\n>\n> That works.  Although, I seem to be missing Francis' point.  According\n> to perlre, a quantified subpattern is \"greedy\".  So a \"greedy operator\"\n> is any one of the standard quantified subpatterns.  The \"+\" and \"?\"\n> modify its matching behavior.  And it seems to me that it _has_ to use a\n> q.s. to work ...\n\nThe \"perlre\" documentation you are reading is from Perl 5.10.0; check\n\"perldelta\" documentation next to it.\n\nI think you are wrong in saying that \"it _has_ to use\".  Yes, you _can_\nuse possessive quantifiers to write that pattern (provided if you can\nlimit your users to Perl 5.10.0 or later), but you do _not_ have to (and I\njust showed you how).  By not using the new feature, you can make it work\nfor people with older version of Perl.\n\nNot everybody who uses git can upgrade their Perl to newer versions.  We\ntry to stick to \"5.6.1 or later\"; anything that is not available in 5.8\nseries is too new to be used outside the contrib/ area.\n\nThat's the point Francis raised that you missed.  \n"},{"id":"95309","messageId":"200811100849.36736.fg@one2team.com","threadId":"16232","inReplyTo":"alpine.LFD.2.00.0811091910570.21142@sys-0.hiltweb.site","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Francis Galiegue","fromEmail":"fg@one2team.com","sentAt":"2008-11-10T07:49:36Z","receivedAt":"2008-11-10T07:49:36Z","isPatch":true,"sender":{"key":"fg@one2team.com","avatar":null},"body":"Le Monday 10 November 2008 01:38:30 Ian Hilt, vous avez écrit :\n> On Sun, 9 Nov 2008, Junio C Hamano wrote:\n> > Ian Hilt <ian.hilt@gmx.com> writes:\n> > > On Sun, 9 Nov 2008, Francis Galiegue wrote:\n> > >> Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n> > >> > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> > >>\n> > >> Greedy operators are only supported with perl 5.10 or more... I think\n> > >> it's a bad idea to use them...\n> > >\n> > > The problem here was that a space should follow the field, but it may\n> > > not.  The user may unwarily backup over it.  \"\\s*\" would match this\n> > > case.\n> > >\n> > > But if there is a space, it is included in the \"(.+)\".  So I tried\n> > > \"\\s+\", which did not include the space, but it won't include the first\n> > > address if there isn't a space after the field.\n> > >\n> > > The quantified subpattern seemed to do the trick.  But, if it could\n> > > result in a dependency issue, I would agree this would be a bad idea.\n> >\n> > You expect something non-blank there anyway, so why not do:\n> >\n> > \tTo:\\s*(\\S.*?)\\s*\\n....\n>\n> That works.  Although, I seem to be missing Francis' point.\n\nNo. The _lazy_ quantifiers (*?, ??, *?, +?, {...}?) are supported all right. \nBut they should be avoided in general.\n\n> According \n> to perlre, a quantified subpattern is \"greedy\".  So a \"greedy operator\"\n> is any one of the standard quantified subpatterns.  The \"+\" and \"?\"\n> modify its matching behavior.  And it seems to me that it _has_ to use a\n> q.s. to work ...\n\nMy wording may be bad, then. They're not greedy, they just don't allow for \nbacktracking. They are more than greedy. Let me explain.\n\nConsider \"number 42\" for instance. If you match it against:\n\n* .*(\\d+) => $1 would be \"2\": the * eats everything but _has_ to backtrack for \n\\d+ to get anything, but just one number is enough;\n* .*?(\\d+) => $1 would be \"42\": as *? is lazy, this means that after each \nmatch, it looks to see whether the next element in the regex would match \nanything; as soon as \\d+ matches 4, .*? stops there;\n* .*+(\\d+) => $1 would match nothing! *+ eats everything, but the + afterwards \n_doesn't allow it to backtrack_.\n\nI hope this makes things a little clearer ;) I think the correct term for *+, \n++, ?+ etc is \"possessive\" quantifiers, I'm just not sure.\n\n-- \nFrancis Galiegue\nONE2TEAM\nIngénieur système\nMob : +33 (0) 6 83 87 78 75\nTel : +33 (0) 1 78 94 55 52\nfge@one2team.com\n40 avenue Raymond Poincaré\n75116 Paris\n"},{"id":"95310","messageId":"200811100857.10802.fg@one2team.net","threadId":"16232","inReplyTo":"1226235588-2997-1-git-send-email-ian.hilt@gmx.com","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Francis Galiegue","fromEmail":"fg@one2team.net","sentAt":"2008-11-10T07:57:10Z","receivedAt":"2008-11-10T07:57:10Z","isPatch":true,"sender":{"key":"fg@one2team.net","avatar":null},"body":"Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n[...]\n> +\tmy @recipients = split(/\\s*,\\s*/, $match);\n\nThis is where it gets complicated, for the \"hey, I am\" <some@one> case...\n\nBut then there is a solution: use a negative lookahead for the split regex.\n\nI thought about splitting against /\\s*,\\s*(?![^\"]+(?:\\\"[^*]*)*)\"/.\n\nA negative lookbehind would have been clearer to write, but perl doesn't \nsupport arbitrary length negative lookbehinds, except by using a very, very \narcane construct.\n\n\n-- \nfge\n"},{"id":"95311","messageId":"200811100859.48918.fg@one2team.com","threadId":"16232","inReplyTo":"200811100857.10802.fg@one2team.net","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Francis Galiegue","fromEmail":"fg@one2team.com","sentAt":"2008-11-10T07:59:48Z","receivedAt":"2008-11-10T07:59:48Z","isPatch":true,"sender":{"key":"fg@one2team.com","avatar":null},"body":"Le Monday 10 November 2008 08:57:10 Francis Galiegue, vous avez écrit :\n> Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n> [...]\n>\n> > +\tmy @recipients = split(/\\s*,\\s*/, $match);\n>\n> This is where it gets complicated, for the \"hey, I am\" <some@one> case...\n>\n> But then there is a solution: use a negative lookahead for the split regex.\n>\n> I thought about splitting against /\\s*,\\s*(?![^\"]+(?:\\\"[^*]*)*)\"/.\n>\n\nOops, that should have been /\\s*,\\s*(?![^\"]+(?:\\\"[^*]*)*\")/, sorry :/\n\n-- \nFrancis Galiegue\nONE2TEAM\nIngénieur système\nMob : +33 (0) 6 83 87 78 75\nTel : +33 (0) 1 78 94 55 52\nfge@one2team.com\n40 avenue Raymond Poincaré\n75116 Paris\n"},{"id":"95312","messageId":"20081110080848.GA325@klangraum.plasmasturm.org","threadId":"16232","inReplyTo":"200811100849.36736.fg@one2team.com","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Aristotle Pagaltzis","fromEmail":"pagaltzis@gmx.de","sentAt":"2008-11-10T08:08:48Z","receivedAt":"2008-11-10T08:08:48Z","isPatch":true,"sender":{"key":"pagaltzis@gmx.de","avatar":"https://gravatar.com/avatar/871c072f71b6f76a364de75e147b5b46319ca6361257be8817c1cee77548ac74?d=mp&s=160"},"body":"* Francis Galiegue <fg@one2team.com> [2008-11-10 08:55]:\n> Le Monday 10 November 2008 01:38:30 Ian Hilt, vous avez écrit :\n> > On Sun, 9 Nov 2008, Junio C Hamano wrote:\n> > > Ian Hilt <ian.hilt@gmx.com> writes:\n> > > > On Sun, 9 Nov 2008, Francis Galiegue wrote:\n> > > >> Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n> > > >> > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> > > >>\n> > > >> Greedy operators are only supported with perl 5.10 or more... I think\n> > > >> it's a bad idea to use them...\n\nPossessive quantification is supported in much earlier versions\nof Perl, it’s just more awkward syntactically:\n\n    /^To:(?>\\s*)(.+)\\s*\\nCc:/ism\n\nBut possessification is not going to make a difference in this\nregex, since .+ can match anything that \\s* can also match, so\nthe only difference is that if the regex does happen to\nbacktrack, it will backtrack over all the spaces after the To:\nat once instead of one at a time.\n\nI have only just subscribed so I do not have enough context to\nknow what the problem is, but based on what I have seen so far it\nseems to me that all you want is simply\n\n    /^To:\\s?(.+)\\s*\\nCc:/ism\n\nalthough I have to wonder if the /s modifier here is really what\nyou want.\n\n> I think the correct term for *+, ++, ?+ etc is \"possessive\"\n> quantifiers, I'm just not sure.\n\nThat is correct.\n\nRegards,\n-- \nAristotle Pagaltzis // <http://plasmasturm.org/>\n"},{"id":"95353","messageId":"alpine.LFD.2.00.0811101303090.30187@maintenance05.msc.mcgregor-surmount.com","threadId":"16232","inReplyTo":"7vbpwo88gh.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Ian Hilt","fromEmail":"ian.hilt@gmx.com","sentAt":"2008-11-10T18:12:00Z","receivedAt":"2008-11-10T18:12:00Z","isPatch":true,"sender":{"key":"ian.hilt@gmx.com","avatar":null},"body":"On Mon, 10 Nov 2008, Junio C Hamano wrote:\n> Ian Hilt <ian.hilt@gmx.com> writes:\n> \n> > On Sun, 9 Nov 2008, Junio C Hamano wrote:\n> >> Ian Hilt <ian.hilt@gmx.com> writes:\n> >> \n> >> > On Sun, 9 Nov 2008, Francis Galiegue wrote:\n> >> >> Le Sunday 09 November 2008 13:59:48 Ian Hilt, vous avez écrit :\n> >> >> > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> >> >> \n> >> >> Greedy operators are only supported with perl 5.10 or more... I think it's a \n> >> >> bad idea to use them...\n> >> ...\n> >> You expect something non-blank there anyway, so why not do:\n> >> \n> >> \tTo:\\s*(\\S.*?)\\s*\\n....\n> >\n> > That works.  Although, I seem to be missing Francis' point.  According\n> > to perlre, a quantified subpattern is \"greedy\".  So a \"greedy operator\"\n> > is any one of the standard quantified subpatterns.  The \"+\" and \"?\"\n> > modify its matching behavior.  And it seems to me that it _has_ to use a\n> > q.s. to work ...\n> \n> The \"perlre\" documentation you are reading is from Perl 5.10.0; check\n> \"perldelta\" documentation next to it.\n> \n> I think you are wrong in saying that \"it _has_ to use\".  Yes, you _can_\n> use possessive quantifiers to write that pattern (provided if you can\n> limit your users to Perl 5.10.0 or later), but you do _not_ have to (and I\n> just showed you how).  By not using the new feature, you can make it work\n> for people with older version of Perl.\n\nRight.  I was saying it has to use quantifiers, in general, not that it\nhas to use possessive quantifiers."},{"id":"95424","messageId":"20081111014919.GI7408@ece.pdx.edu","threadId":"16232","inReplyTo":"alpine.LFD.2.00.0811091344480.20499@sys-0.hiltweb.site","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Tait","fromEmail":"git.git@t41t.com","sentAt":"2008-11-11T01:49:19Z","receivedAt":"2008-11-11T01:49:19Z","isPatch":true,"sender":{"key":"git.git@t41t.com","avatar":null},"body":"> > > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> > \n> > Greedy operators are only supported with perl 5.10 or more... I think it's a \n> > bad idea to use them...\n> \n> The problem here was that a space should follow the field, but it may\n> not.  The user may unwarily backup over it.  \"\\s*\" would match this\n> case.\n> \n> But if there is a space, it is included in the \"(.+)\".\n\nNot in any version of Perl to which I have access. \n\nWhy doesn't\n\t/^To:\\s*(.+)\\s*\\nCc:/ism\nwork?\n"},{"id":"95454","messageId":"200811111230.28076.fg@one2team.com","threadId":"16232","inReplyTo":"20081111014919.GI7408@ece.pdx.edu","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Francis Galiegue","fromEmail":"fg@one2team.com","sentAt":"2008-11-11T11:30:27Z","receivedAt":"2008-11-11T11:30:27Z","isPatch":true,"sender":{"key":"fg@one2team.com","avatar":null},"body":"Le Tuesday 11 November 2008 02:49:19 Tait, vous avez écrit :\n> > > > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> > >\n> > > Greedy operators are only supported with perl 5.10 or more... I think\n> > > it's a bad idea to use them...\n> >\n> > The problem here was that a space should follow the field, but it may\n> > not.  The user may unwarily backup over it.  \"\\s*\" would match this\n> > case.\n> >\n> > But if there is a space, it is included in the \"(.+)\".\n>\n> Not in any version of Perl to which I have access.\n>\n\nAnd if you see a space in (.+), your regex engine is buggy anyway.\n\n\n-- \nFrancis Galiegue\nONE2TEAM\nIngénieur système\nMob : +33 (0) 6 83 87 78 75\nTel : +33 (0) 1 78 94 55 52\nfge@one2team.com\n40 avenue Raymond Poincaré\n75116 Paris\n"},{"id":"95486","messageId":"alpine.LFD.2.00.0811111542230.24205@sys-0.hiltweb.site","threadId":"16232","inReplyTo":"200811111230.28076.fg@one2team.com","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Ian Hilt","fromEmail":"ian.hilt@gmx.com","sentAt":"2008-11-11T20:47:55Z","receivedAt":"2008-11-11T20:47:55Z","isPatch":true,"sender":{"key":"ian.hilt@gmx.com","avatar":null},"body":"On Tue, 11 Nov 2008, Francis Galiegue wrote:\n> Le Tuesday 11 November 2008 02:49:19 Tait, vous avez écrit :\n> > > > > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> > > >\n> > > > Greedy operators are only supported with perl 5.10 or more... I think\n> > > > it's a bad idea to use them...\n> > >\n> > > The problem here was that a space should follow the field, but it may\n> > > not.  The user may unwarily backup over it.  \"\\s*\" would match this\n> > > case.\n> > >\n> > > But if there is a space, it is included in the \"(.+)\".\n> >\n> > Not in any version of Perl to which I have access.\n> >\n> \n> And if you see a space in (.+), your regex engine is buggy anyway.\n\nSo what does this script produce on your systems?\n\n\n#!/usr/bin/perl -Tw\n--8<--\nuse strict;\nmy $ws = \"To: \\nCc:\";\n\n$ws =~ /^To:\\s*(.+)\\s*\\nCc:/ism;\n\nif ($1 eq ' ') {\n\tprint \"\\$1 is equal to a space.\\n\";\n}\n-->8--\n\nOn mine, it prints the message.  So it seems it is matching _a_ space.\nThis resulted in an illegal recipient field.  Junio's suggestion to\nchange this to\n\n  /^To:\\s*(\\S.+?)\\s*\\nCc:/ism\n\nworked beautifully."},{"id":"95487","messageId":"alpine.LFD.2.00.0811111551450.24205@sys-0.hiltweb.site","threadId":"16232","inReplyTo":"alpine.LFD.2.00.0811111542230.24205@sys-0.hiltweb.site","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Ian Hilt","fromEmail":"ian.hilt@gmx.com","sentAt":"2008-11-11T20:53:17Z","receivedAt":"2008-11-11T20:53:17Z","isPatch":true,"sender":{"key":"ian.hilt@gmx.com","avatar":null},"body":"On Tue, 11 Nov 2008, Ian Hilt wrote:\n\nHm, how about keeping the path to perl in the snippet,\n\n--8<--\n#!/usr/bin/perl -Tw\nuse strict;\nmy $ws = \"To: \\nCc:\";\n\n$ws =~ /^To:\\s*(.+)\\s*\\nCc:/ism;\n\nif ($1 eq ' ') {\n\tprint \"\\$1 is equal to a space.\\n\";\n}\n-->8--\n"},{"id":"95488","messageId":"200811112153.31214.fg@one2team.com","threadId":"16232","inReplyTo":"alpine.LFD.2.00.0811111542230.24205@sys-0.hiltweb.site","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Francis Galiegue","fromEmail":"fg@one2team.com","sentAt":"2008-11-11T20:53:30Z","receivedAt":"2008-11-11T20:53:30Z","isPatch":true,"sender":{"key":"fg@one2team.com","avatar":null},"body":"Le Tuesday 11 November 2008 21:47:55 Ian Hilt, vous avez écrit :\n> On Tue, 11 Nov 2008, Francis Galiegue wrote:\n> > Le Tuesday 11 November 2008 02:49:19 Tait, vous avez écrit :\n> > > > > > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> > > > >\n> > > > > Greedy operators are only supported with perl 5.10 or more... I\n> > > > > think it's a bad idea to use them...\n> > > >\n> > > > The problem here was that a space should follow the field, but it may\n> > > > not.  The user may unwarily backup over it.  \"\\s*\" would match this\n> > > > case.\n> > > >\n> > > > But if there is a space, it is included in the \"(.+)\".\n> > >\n> > > Not in any version of Perl to which I have access.\n> >\n> > And if you see a space in (.+), your regex engine is buggy anyway.\n>\n> So what does this script produce on your systems?\n>\n>\n> #!/usr/bin/perl -Tw\n> --8<--\n> use strict;\n> my $ws = \"To: \\nCc:\";\n>\n> $ws =~ /^To:\\s*(.+)\\s*\\nCc:/ism;\n>\n> if ($1 eq ' ') {\n> \tprint \"\\$1 is equal to a space.\\n\";\n> }\n> -->8--\n>\n> On mine, it prints the message.  So it seems it is matching _a_ space.\n\nWhich is perfectly normal. The first \\s* wanted spaces, it got them. But it \nleft nothing for the capturing .+ behind. And any quantifier (except when it \nis possessive) _MUST_ backtrack in order for the full regex to complete. This \nis why the .+ captured the space: the first \\s* was perfectly fine with no \nspace at all, and the second, well, didn't find any space but it didn't care \neither.\n\n-- \nFrancis Galiegue\nONE2TEAM\nIngénieur système\nMob : +33 (0) 6 83 87 78 75\nTel : +33 (0) 1 78 94 55 52\nfge@one2team.com\n40 avenue Raymond Poincaré\n75116 Paris\n"},{"id":"95500","messageId":"20081111221421.GJ7408@ece.pdx.edu","threadId":"16232","inReplyTo":"alpine.LFD.2.00.0811111542230.24205@sys-0.hiltweb.site","subject":"Re: [PATCH] git send-email: edit recipient addresses with the --compose flag","fromName":"Tait","fromEmail":"git.git@t41t.com","sentAt":"2008-11-11T22:14:21Z","receivedAt":"2008-11-11T22:14:21Z","isPatch":true,"sender":{"key":"git.git@t41t.com","avatar":null},"body":"> > > > > > +\tif ($c_file =~ /^To:\\s*+(.+)\\s*\\nCc:/ism) {\n> > > > >\n> > > > > Greedy operators are only supported with perl 5.10 or more... I think\n> > > > > it's a bad idea to use them...\n> > > >\n> > > > The problem here was that a space should follow the field, but it may\n> > > > not.  The user may unwarily backup over it.  \"\\s*\" would match this\n> > > > case.\n> > > >\n> > > > But if there is a space, it is included in the \"(.+)\".\n> > >\n> > > Not in any version of Perl to which I have access.\n> > >\n> > \n> > And if you see a space in (.+), your regex engine is buggy anyway.\n> \n> So what does this script produce on your systems?\n> \n> --8<--\n> #!/usr/bin/perl -Tw\n> use strict;\n> my $ws = \"To: \\nCc:\";\n> \n> $ws =~ /^To:\\s*(.+)\\s*\\nCc:/ism;\n> \n> if ($1 eq ' ') {\n> \tprint \"\\$1 is equal to a space.\\n\";\n> }\n> -->8--\n\nIt does match a space in that case. I misunderstood the problem this was \ntrying to solve. (Sorry for the confusion.)\n"}]}