git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Michal Nazarewicz <mpn@google.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Ted Zlatanov <tzz@lifelogs.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>,
	git@vger.kernel.org
Subject: Re: [PATCH 3/4] Git.pm: Add interface for git credential command.
Date: Wed, 6 Feb 2013 18:16:25 -0500	[thread overview]
Message-ID: <20130206231625.GL27507@sigill.intra.peff.net> (raw)
In-Reply-To: <f4b5413b0a55474346daa7b0866c7a4fed55778d.1360183427.git.mina86@mina86.com>

On Wed, Feb 06, 2013 at 09:47:05PM +0100, Michal Nazarewicz wrote:

> +sub _credential_read {
> +	my %credential;
> +	my ($reader, $op) = (@_);
> +	while (<$reader>) {
> +		chomp;
> +		my ($key, $value) = /([^=]*)=(.*)/;

Empty keys are not valid. Can we make this:

  /^([^=]+)=(.*)/

to fail the regex? Otherwise, I think this check:

> +		if (not defined $key) {
> +			throw Error::Simple("unable to parse git credential $op response:\n$_\n");
> +		}

would not pass because $key would be the empty string.

> +sub _credential_write {
> +	my ($credential, $writer) = @_;
> +
> +	for my $key (sort {
> +		# url overwrites other fields, so it must come first
> +		return -1 if $a eq 'url';
> +		return  1 if $b eq 'url';
> +		return $a cmp $b;
> +	} keys %$credential) {
> +		if (defined $credential->{$key} && length $credential->{$key}) {
> +			print $writer $key, '=', $credential->{$key}, "\n";
> +		}
> +	}

There are a few disallowed characters, like "\n" in key or value, and
"=" in a key. They should never happen unless the caller is buggy, but
should we check and catch them here?

> +In the second form, C<CODE> needs to be a reference to a subroutine.
> +The function will execute C<git credential fill> to fill provided
> +credential hash, than call C<CODE> with C<CREDENTIAL> as the sole
> +argument, and finally depending on C<CODE>'s return value execute
> +C<git credential approve> (if return value yields true) or C<git
> +credential reject> (otherwise).  The return value is the same as what
> +C<CODE> returned.  With this form, the usage might look as follows:

This is a nice touch. It makes the normal calling code a lot simpler.

-Peff

  reply	other threads:[~2013-02-06 23:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-06 20:47 [PATCH 0/4] Make git-send-email git-credential Michal Nazarewicz
2013-02-06 20:47 ` [PATCH 1/4] Git.pm: Allow command_close_bidi_pipe() to be called as method Michal Nazarewicz
2013-02-06 20:47 ` [PATCH 2/4] Git.pm: Allow pipes to be closed prior to calling command_close_bidi_pipe Michal Nazarewicz
2013-02-06 23:04   ` Jeff King
2013-02-07  0:14     ` Junio C Hamano
2013-02-06 20:47 ` [PATCH 3/4] Git.pm: Add interface for git credential command Michal Nazarewicz
2013-02-06 23:16   ` Jeff King [this message]
2013-02-07  7:19   ` Matthieu Moy
2013-02-07  7:22   ` Matthieu Moy
2013-02-06 20:47 ` [PATCH 4/4] git-send-email: Use git credential to obtain password Michal Nazarewicz
2013-02-06 23:19   ` Jeff King

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=20130206231625.GL27507@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mpn@google.com \
    --cc=tzz@lifelogs.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 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).