All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Julia Lawall" <julia@diku.dk>,
	git@vger.kernel.org, "Vasiliy Kulikov" <segooon@gmail.com>,
	"Matt Mooney" <mfmooney@gmail.com>,
	kernel-janitors@vger.kernel.org,
	"Dan Carpenter" <error27@gmail.com>
Subject: Re: [PATCH V3] git-send-email.perl: Add --to-cmd
Date: Fri, 24 Sep 2010 15:32:25 +0000	[thread overview]
Message-ID: <m3lj6rgnub.fsf@localhost.localdomain> (raw)
In-Reply-To: <1285291098.25928.220.camel@Joe-Laptop>

Joe Perches <joe@perches.com> writes:

> +# Execute a command (ie: $to_cmd) to get a list of email addresses
> +# and return a results array
> +sub recipients_cmd(@) {

Do not use subroutine prototypes: they do not do what you think they
do.  In this case using prototype is unnecessary and can be dangerous.

> +	my ($prefix, $what, $cmd, $file) = @_;
> +
> +	my $sanitized_sender = sanitize_address($sender);
> +	my @addresses = ();
> +	open(F, "$cmd \Q$file\E |")

For the future: use lexical filehandles instead of globals

  +	open(my $fh, "$cmd \Q$file\E |")


> +	    or die "($prefix) Could not execute '$cmd'";

You should use quote_command from gitweb/gitweb.perl (should probably
make it into Git.pm):

  # quote the given arguments for passing them to the shell
  # quote_command("command", "arg 1", "arg with ' and ! characters")
  # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
  # Try to avoid using this function wherever possible.
  sub quote_command {
  	return join(' ',
  		map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
  }

Or use String::ShellQuote :-)

But that is for a cleanup patch; you are using what it is already
there.

> +	while(<F>) {
> +		my $address = $_;
> +		$address =~ s/^\s*//g;
> +		$address =~ s/\n$//g;

Hmmm... why does it remove leading, but not trailing whitespace?

> +		$address = sanitize_address($address);
> +		next if ($address eq $sanitized_sender and $suppress_from);
> +		push @addresses, $address;
> +		printf("($prefix) Adding %s: %s from: '%s'\n",
> +		       $what, $address, $cmd) unless $quiet;
> +		}
> +	close F
> +	    or die "($prefix) failed to close pipe to '$cmd'";
> +	return @addresses;
> +}

-- 
Jakub Narebski
Poland
ShadeHawk on #git

WARNING: multiple messages have this Message-ID (diff)
From: Jakub Narebski <jnareb@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Julia Lawall" <julia@diku.dk>,
	git@vger.kernel.org, "Vasiliy Kulikov" <segooon@gmail.com>,
	"Matt Mooney" <mfmooney@gmail.com>,
	kernel-janitors@vger.kernel.org,
	"Dan Carpenter" <error27@gmail.com>
Subject: Re: [PATCH V3] git-send-email.perl: Add --to-cmd
Date: Fri, 24 Sep 2010 08:32:25 -0700 (PDT)	[thread overview]
Message-ID: <m3lj6rgnub.fsf@localhost.localdomain> (raw)
In-Reply-To: <1285291098.25928.220.camel@Joe-Laptop>

Joe Perches <joe@perches.com> writes:

> +# Execute a command (ie: $to_cmd) to get a list of email addresses
> +# and return a results array
> +sub recipients_cmd(@) {

Do not use subroutine prototypes: they do not do what you think they
do.  In this case using prototype is unnecessary and can be dangerous.

> +	my ($prefix, $what, $cmd, $file) = @_;
> +
> +	my $sanitized_sender = sanitize_address($sender);
> +	my @addresses = ();
> +	open(F, "$cmd \Q$file\E |")

For the future: use lexical filehandles instead of globals

  +	open(my $fh, "$cmd \Q$file\E |")


> +	    or die "($prefix) Could not execute '$cmd'";

You should use quote_command from gitweb/gitweb.perl (should probably
make it into Git.pm):

  # quote the given arguments for passing them to the shell
  # quote_command("command", "arg 1", "arg with ' and ! characters")
  # => "'command' 'arg 1' 'arg with '\'' and '\!' characters'"
  # Try to avoid using this function wherever possible.
  sub quote_command {
  	return join(' ',
  		map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ );
  }

Or use String::ShellQuote :-)

But that is for a cleanup patch; you are using what it is already
there.

> +	while(<F>) {
> +		my $address = $_;
> +		$address =~ s/^\s*//g;
> +		$address =~ s/\n$//g;

Hmmm... why does it remove leading, but not trailing whitespace?

> +		$address = sanitize_address($address);
> +		next if ($address eq $sanitized_sender and $suppress_from);
> +		push @addresses, $address;
> +		printf("($prefix) Adding %s: %s from: '%s'\n",
> +		       $what, $address, $cmd) unless $quiet;
> +		}
> +	close F
> +	    or die "($prefix) failed to close pipe to '$cmd'";
> +	return @addresses;
> +}

-- 
Jakub Narebski
Poland
ShadeHawk on #git

  reply	other threads:[~2010-09-24 15:32 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AANLkTinsM5jdU194FR8L3hTvBXk0Tr_oV2E5752NOUpq@mail.gmail.com>
2010-09-23  7:11 ` threaded patch series matt mooney
2010-09-23  7:36   ` Joe Perches
2010-09-23  8:55   ` Julia Lawall
2010-09-23  9:05     ` Joe Perches
2010-09-23  9:05       ` Joe Perches
2010-09-23  9:09   ` Vasiliy Kulikov
2010-09-23 12:00   ` Vasiliy Kulikov
2010-09-23 14:57   ` Joe Perches
2010-09-23 15:58   ` Julia Lawall
2010-09-23 17:17     ` [RFC PATCH] sit-send-email.pl: Add --to-cmd Joe Perches
2010-09-23 17:17       ` Joe Perches
2010-09-23 17:29       ` Ævar Arnfjörð Bjarmason
2010-09-23 17:46         ` Joe Perches
2010-09-23 17:46           ` Joe Perches
2010-09-23 17:50           ` Ævar Arnfjörð Bjarmason
2010-09-23 18:45             ` [PATCH V2] git-send-email.perl: " Joe Perches
2010-09-23 18:45               ` Joe Perches
2010-09-23 19:57               ` matt mooney
2010-09-23 19:57                 ` matt mooney
2010-09-23 22:37               ` Junio C Hamano
2010-09-23 22:37                 ` Junio C Hamano
2010-09-23 23:16                 ` Ævar Arnfjörð Bjarmason
2010-09-24  1:18                 ` [PATCH V3] " Joe Perches
2010-09-24  1:18                   ` Joe Perches
2010-09-24 15:32                   ` Jakub Narebski [this message]
2010-09-24 15:32                     ` Jakub Narebski
2010-09-24 16:06                     ` Joe Perches
2010-09-24 16:06                       ` Joe Perches
2010-09-24 16:47                       ` Ævar Arnfjörð Bjarmason
2010-09-24 17:03                         ` [PATCH V4] " Joe Perches
2010-09-24 17:03                           ` Joe Perches
2010-09-24  1:20                 ` [PATCH V2] " Joe Perches
2010-09-24  1:20                   ` Joe Perches
2010-09-23 18:01   ` threaded patch series matt mooney

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=m3lj6rgnub.fsf@localhost.localdomain \
    --to=jnareb@gmail.com \
    --cc=avarab@gmail.com \
    --cc=error27@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=joe@perches.com \
    --cc=julia@diku.dk \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=mfmooney@gmail.com \
    --cc=segooon@gmail.com \
    /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.