* [PATCH v1] perf/aggregate: tighten option parsing @ 2018-04-20 12:10 Christian Couder 2018-04-20 17:46 ` Eric Sunshine 0 siblings, 1 reply; 5+ messages in thread From: Christian Couder @ 2018-04-20 12:10 UTC (permalink / raw) To: git Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason, Christian Couder When passing an option '--foo' that it does not recognize, the aggregate.perl script should die with an helpful error message like: unknown option '--foo' at ./aggregate.perl line 80. rather than: fatal: Needed a single revision rev-parse --verify --foo: command returned error: 128 While at it let's also prevent something like 'foo--sort-by=regression' to be handled as if '--sort-by=regression' had been used. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> --- t/perf/aggregate.perl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl index 48637ef64b..2cc9eb0ac5 100755 --- a/t/perf/aggregate.perl +++ b/t/perf/aggregate.perl @@ -46,7 +46,7 @@ while (scalar @ARGV) { shift @ARGV; next; } - if ($arg =~ /--sort-by(?:=(.*))?/) { + if ($arg =~ /^--sort-by(?:=(.*))?$/) { shift @ARGV; if (defined $1) { $sortby = $1; @@ -76,6 +76,9 @@ while (scalar @ARGV) { } next; } + if ($arg =~ /^--.+$/) { + die "unknown option '$arg'"; + } last if -f $arg or $arg eq "--"; if (! -d $arg) { my $rev = Git::command_oneline(qw(rev-parse --verify), $arg); -- 2.17.0.257.g28b659db43 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1] perf/aggregate: tighten option parsing 2018-04-20 12:10 [PATCH v1] perf/aggregate: tighten option parsing Christian Couder @ 2018-04-20 17:46 ` Eric Sunshine 2018-04-20 18:27 ` Ævar Arnfjörð Bjarmason 0 siblings, 1 reply; 5+ messages in thread From: Eric Sunshine @ 2018-04-20 17:46 UTC (permalink / raw) To: Christian Couder Cc: Git List, Junio C Hamano, Ævar Arnfjörð Bjarmason, Christian Couder On Fri, Apr 20, 2018 at 8:10 AM, Christian Couder <christian.couder@gmail.com> wrote: > When passing an option '--foo' that it does not recognize, the > aggregate.perl script should die with an helpful error message > like: > > unknown option '--foo' at ./aggregate.perl line 80. > > rather than: > > fatal: Needed a single revision > rev-parse --verify --foo: command returned error: 128 > > While at it let's also prevent something like > 'foo--sort-by=regression' to be handled as if > '--sort-by=regression' had been used. > > Signed-off-by: Christian Couder <chriscool@tuxfamily.org> > --- > diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl > @@ -46,7 +46,7 @@ while (scalar @ARGV) { > - if ($arg =~ /--sort-by(?:=(.*))?/) { > + if ($arg =~ /^--sort-by(?:=(.*))?$/) { Makes sense. > @@ -76,6 +76,9 @@ while (scalar @ARGV) { > + if ($arg =~ /^--.+$/) { > + die "unknown option '$arg'"; > + } Nit: In this expression, the trailing +$ makes the match no tighter than the simpler /^--./, so the latter would be good enough. Not necessarily worth a re-roll. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] perf/aggregate: tighten option parsing 2018-04-20 17:46 ` Eric Sunshine @ 2018-04-20 18:27 ` Ævar Arnfjörð Bjarmason 2018-04-21 3:50 ` Junio C Hamano 0 siblings, 1 reply; 5+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2018-04-20 18:27 UTC (permalink / raw) To: Eric Sunshine Cc: Christian Couder, Git List, Junio C Hamano, Christian Couder On Fri, Apr 20 2018, Eric Sunshine wrote: > On Fri, Apr 20, 2018 at 8:10 AM, Christian Couder > <christian.couder@gmail.com> wrote: >> When passing an option '--foo' that it does not recognize, the >> aggregate.perl script should die with an helpful error message >> like: >> >> unknown option '--foo' at ./aggregate.perl line 80. >> >> rather than: >> >> fatal: Needed a single revision >> rev-parse --verify --foo: command returned error: 128 >> >> While at it let's also prevent something like >> 'foo--sort-by=regression' to be handled as if >> '--sort-by=regression' had been used. >> >> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> >> --- >> diff --git a/t/perf/aggregate.perl b/t/perf/aggregate.perl >> @@ -46,7 +46,7 @@ while (scalar @ARGV) { >> - if ($arg =~ /--sort-by(?:=(.*))?/) { >> + if ($arg =~ /^--sort-by(?:=(.*))?$/) { > > Makes sense. > >> @@ -76,6 +76,9 @@ while (scalar @ARGV) { >> + if ($arg =~ /^--.+$/) { >> + die "unknown option '$arg'"; >> + } > > Nit: In this expression, the trailing +$ makes the match no tighter > than the simpler /^--./, so the latter would be good enough. > > Not necessarily worth a re-roll. Not that it matters in this case, but just as a bit of Perl rx pedantry, yes his is tighter & more correct. You didn't consider how "." interacts with newlines: $ perl -wE 'my @rx = (qr/^--./, qr/^--.+$/, qr/^--./m, qr/^--.+$/m, qr/^--./s, qr/^--.+$/s); for (@rx) { my $s = "--foo\n--bar"; say $_, "\t", ($s =~ $_ ? 1 : 0) }' (?^u:^--.) 1 (?^u:^--.+$) 0 (?^um:^--.) 1 (?^um:^--.+$) 1 (?^us:^--.) 1 (?^us:^--.+$) 1 I don't think it matters here, not like someone will pass \n in options to aggregate.perl... ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] perf/aggregate: tighten option parsing 2018-04-20 18:27 ` Ævar Arnfjörð Bjarmason @ 2018-04-21 3:50 ` Junio C Hamano 2018-04-25 12:55 ` Christian Couder 0 siblings, 1 reply; 5+ messages in thread From: Junio C Hamano @ 2018-04-21 3:50 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: Eric Sunshine, Christian Couder, Git List, Christian Couder Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: >> Not necessarily worth a re-roll. > > Not that it matters in this case, but just as a bit of Perl rx pedantry, > yes his is tighter & more correct. You didn't consider how "." interacts > with newlines: > > $ perl -wE 'my @rx = (qr/^--./, qr/^--.+$/, qr/^--./m, qr/^--.+$/m, qr/^--./s, qr/^--.+$/s); for (@rx) { my $s = "--foo\n--bar"; say $_, "\t", ($s =~ $_ ? 1 : 0) }' > (?^u:^--.) 1 > (?^u:^--.+$) 0 > (?^um:^--.) 1 > (?^um:^--.+$) 1 > (?^us:^--.) 1 > (?^us:^--.+$) 1 > > I don't think it matters here, not like someone will pass \n in options > to aggregate.perl... Hmph, do we want the command not to barf when "--foo\n--bar" is given from the command line and we cannot find such an option? I thought that the location the match under discussion is used does want to see a hit with any option looking string that begins with double dashes. I would have expected "tigher and hence incorrect", in other words. Somewhat puzzled... ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1] perf/aggregate: tighten option parsing 2018-04-21 3:50 ` Junio C Hamano @ 2018-04-25 12:55 ` Christian Couder 0 siblings, 0 replies; 5+ messages in thread From: Christian Couder @ 2018-04-25 12:55 UTC (permalink / raw) To: Junio C Hamano Cc: Ævar Arnfjörð Bjarmason, Eric Sunshine, Git List, Christian Couder On Sat, Apr 21, 2018 at 5:50 AM, Junio C Hamano <gitster@pobox.com> wrote: > Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > >>> Not necessarily worth a re-roll. >> >> Not that it matters in this case, but just as a bit of Perl rx pedantry, >> yes his is tighter & more correct. You didn't consider how "." interacts >> with newlines: >> >> $ perl -wE 'my @rx = (qr/^--./, qr/^--.+$/, qr/^--./m, qr/^--.+$/m, qr/^--./s, qr/^--.+$/s); for (@rx) { my $s = "--foo\n--bar"; say $_, "\t", ($s =~ $_ ? 1 : 0) }' >> (?^u:^--.) 1 >> (?^u:^--.+$) 0 >> (?^um:^--.) 1 >> (?^um:^--.+$) 1 >> (?^us:^--.) 1 >> (?^us:^--.+$) 1 >> >> I don't think it matters here, not like someone will pass \n in options >> to aggregate.perl... > > Hmph, do we want the command not to barf when "--foo\n--bar" is > given from the command line and we cannot find such an option? > > I thought that the location the match under discussion is used does > want to see a hit with any option looking string that begins with > double dashes. I would have expected "tigher and hence incorrect", > in other words. > > Somewhat puzzled... I guess it might be better at this point to just "use Getopt::Long;" (along with "Getopt::Long::Configure qw/ pass_through /;") as git send-email does. It might avoid mistakes and subtle discussions like the above. Thanks for the reviews, Christian. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-04-25 12:55 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2018-04-20 12:10 [PATCH v1] perf/aggregate: tighten option parsing Christian Couder 2018-04-20 17:46 ` Eric Sunshine 2018-04-20 18:27 ` Ævar Arnfjörð Bjarmason 2018-04-21 3:50 ` Junio C Hamano 2018-04-25 12:55 ` Christian Couder
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 NNTP newsgroup(s).