git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: John Keeping <john@keeping.me.uk>
To: Michael Haggerty <mhagger@alum.mit.edu>
Cc: Junio C Hamano <gitster@pobox.com>,
	Ramkumar Ramachandra <artagnon@gmail.com>,
	Git List <git@vger.kernel.org>
Subject: Re: Review of git multimail
Date: Wed, 3 Jul 2013 09:29:02 +0100	[thread overview]
Message-ID: <20130703082902.GE9161@serenity.lan> (raw)
In-Reply-To: <51D3DA9A.9090604@alum.mit.edu>

On Wed, Jul 03, 2013 at 10:02:34AM +0200, Michael Haggerty wrote:
> On 07/03/2013 12:21 AM, Junio C Hamano wrote:
> > Ramkumar Ramachandra <artagnon@gmail.com> writes:
> > 
> >>>     def get(self, name, default=''):
> >>>         try:
> >>>             values = self._split(read_git_output(
> >>>                     ['config', '--get', '--null', '%s.%s' % (self.section, name)],
> >>>                     env=self.env, keepends=True,
> >>>                     ))
> >>
> >> Wait, what is the point of using --null and then splitting by hand
> >> using a poorly-defined static method?  Why not drop the --null and
> >> splitlines() as usual?
> > 
> > You may actually have spotted a bug or misuse of "--get" here.
> > 
> > With this sample configuration:
> > 
> >         $ cat >sample <<\EOF
> >         [a]
> >                 one = value
> >                 one = another
> > 
> >         [b]
> >                 one = "value\nanother"
> >         EOF
> > 
> > A script cannot differentiate between them without using '--null'.
> > 
> > 	$ git config -f sample --get-all a.one
> >         $ git config -f sample --get-all b.one
> > 
> > But that matters only when you use "--get-all", not "--get".  If
> > this method wants to make sure that the user did not misuse a.one
> > as a multi-valued configuration variable, use of "--null --get-all"
> > followed by checking how many items the command gives you back would
> > be a way to do so.
> 
> No, the code in question was a simple sanity check (i.e., mostly a check
> of my own sanity and understanding of "git config" behavior) preceding
> the information-losing next line "return values[0]".  If it had been
> meant as a check that the user hadn't misconfigured the system, then I
> wouldn't have used assert but rather raised a ConfigurationException
> with an explanatory message.
> 
> I would be happy to add the checking that you described, but I didn't
> have the impression that it is the usual convention.  Does code that
> wants a single value from the config usually verify that there is
> one-and-only-one value, or does it typically just do the equivalent of
> "git config --get" and use the returned (effectively the last) value?

Doesn't "git config --get" return an error if there are multiple values?
The answer is apparently "no" - I wrote the text below from
git-config(1) and then checked the behaviour.  This seems to be a
regression in git-config (bisect running now).

I think the "correct" answer is what's below, but it doesn't work like
this in current Git:

    If you want a single value then I think it's normal to just read the
    output of "git config" and let it handle the error cases, without
    needing to split the result at all.

    I think there is a different issue in the "except" block following
    the code quoted at the top though - you will return "default" if a
    key happens to be multi-valued.  The script should check the return
    code and raise a ConfigurationException if it is 2.

  parent reply	other threads:[~2013-07-03  8:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-02 19:23 Review of git multimail Ramkumar Ramachandra
2013-07-02 20:51 ` John Keeping
2013-07-02 21:34   ` Ramkumar Ramachandra
2013-07-02 22:21 ` Junio C Hamano
2013-07-03  8:02   ` Michael Haggerty
2013-07-03  8:16     ` Junio C Hamano
2013-07-03  8:29     ` John Keeping [this message]
2013-07-03  8:33       ` John Keeping
2013-07-03  0:10 ` Michael Haggerty
2013-07-03 10:23   ` Ramkumar Ramachandra
2013-07-03 11:02     ` Ramkumar Ramachandra
2013-07-03 11:41     ` Michael Haggerty
2013-07-03 21:09     ` Jed Brown
2013-07-04  8:11       ` Matthieu Moy
2013-07-04  8:27       ` Michael Haggerty

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130703082902.GE9161@serenity.lan \
    --to=john@keeping.me.uk \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mhagger@alum.mit.edu \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).