git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ping Yin" <pkufranky@gmail.com>
To: "Junio C Hamano" <junio@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v3 1/4] config.c: Add git_config_bool_or_int to handle bool/int variable
Date: Sun, 13 Apr 2008 15:28:20 +0800	[thread overview]
Message-ID: <46dff0320804130028l76c69b55jb8d6be79125b6041@mail.gmail.com> (raw)
In-Reply-To: <7vmynye0cz.fsf@gitster.siamese.dyndns.org>

On Sun, Apr 13, 2008 at 2:26 PM, Junio C Hamano <junio@pobox.com> wrote:
> Ping Yin <pkufranky@gmail.com> writes:
>
>  > With git_config_bool_or_int, the caller can differentiate boolean true
>  > and integer 1 etc.
>  >
>  > Signed-off-by: Ping Yin <pkufranky@gmail.com>
>  > ---
>  >  config.c |   15 +++++++++++++++
>  >  1 files changed, 15 insertions(+), 0 deletions(-)
>  >
>  > diff --git a/config.c b/config.c
>  > index 0624494..e614456 100644
>  > --- a/config.c
>  > +++ b/config.c
>  > @@ -316,6 +316,21 @@ int git_config_bool(const char *name, const char *value)
>  >       return git_config_int(name, value) != 0;
>  >  }
>  >
>  > +int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
>  > +{
>  > +     *is_bool = 1;
>  > +     if (!value)
>  > +             return 1;
>  > +     if (!*value)
>  > +             return 0;
>  > +     if (!strcasecmp(value, "true") || !strcasecmp(value, "yes"))
>  > +             return 1;
>  > +     if (!strcasecmp(value, "false") || !strcasecmp(value, "no"))
>  > +             return 0;
>  > +     *is_bool = 0;
>  > +     return git_config_int(name, value);
>  > +}
>  > +
>
>  I expected git_config_bool() to be implemented in terms of this new
>  function to avoid code duplication if we were actually going to do this.
>
>  You also need an external declaration in a header file for its users.
>
>  ---
>   cache.h  |    1 +
>   config.c |   10 +++++++++-
>   2 files changed, 10 insertions(+), 1 deletions(-)
>
>  diff --git a/cache.h b/cache.h
>  index 2a1e7ec..50b28fa 100644
>  --- a/cache.h
>  +++ b/cache.h
>  @@ -692,6 +692,7 @@ extern int git_parse_long(const char *, long *);
>   extern int git_parse_ulong(const char *, unsigned long *);
>   extern int git_config_int(const char *, const char *);
>   extern unsigned long git_config_ulong(const char *, const char *);
>  +extern int git_config_bool_or_int(const char *, const char *, int *);
>   extern int git_config_bool(const char *, const char *);
>   extern int git_config_string(const char **, const char *, const char *);
>   extern int git_config_set(const char *, const char *);
>
> diff --git a/config.c b/config.c
>  index 0624494..5ea18ef 100644
>
> --- a/config.c
>  +++ b/config.c
>  @@ -303,8 +303,9 @@ unsigned long git_config_ulong(const char *name, const char *value)
>         return ret;
>   }
>
>  -int git_config_bool(const char *name, const char *value)
>
> +int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
>   {
>  +       *is_bool = 1;
>         if (!value)
>                 return 1;
>         if (!*value)
>  @@ -313,9 +314,16 @@ int git_config_bool(const char *name, const char *value)
>
>                 return 1;
>         if (!strcasecmp(value, "false") || !strcasecmp(value, "no"))
>                 return 0;
>  +       *is_bool = 0;
>
>         return git_config_int(name, value) != 0;
>   }
>
>  +int git_config_bool(const char *name, const char *value)
>  +{
>  +       int discard;
>  +       return git_config_bool_or_int(name, value, &discard);

Is it better to use
+       return git_config_bool_or_int(name, value, &discard) != 0;

since git_config_bool_or_int(name, value, &discard) may return an
interger neither 0 nor 1


-- 
Ping Yin

  reply	other threads:[~2008-04-13  7:29 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-12 15:05 [PATCH v3 0/4] builtin-status: submodule summary support Ping Yin
2008-04-12 15:05 ` [PATCH v3 1/4] config.c: Add git_config_bool_or_int to handle bool/int variable Ping Yin
2008-04-12 15:05   ` [PATCH v3 2/4] git-submodule summary: --for-status option Ping Yin
2008-04-12 15:05     ` [PATCH v3 3/4] builtin-status: submodule summary support Ping Yin
2008-04-12 15:05       ` [PATCH v3 4/4] buitin-status: Add tests for submodule summary Ping Yin
2008-04-12 15:13         ` Ping Yin
2008-04-13  6:26   ` [PATCH v3 1/4] config.c: Add git_config_bool_or_int to handle bool/int variable Junio C Hamano
2008-04-13  7:28     ` Ping Yin [this message]
2008-04-13  7:30     ` Ping Yin
2008-04-13  9:03       ` Junio C Hamano
2008-04-13 19:14         ` Junio C Hamano

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=46dff0320804130028l76c69b55jb8d6be79125b6041@mail.gmail.com \
    --to=pkufranky@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=junio@pobox.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).