From: "Ping Yin" <pkufranky@gmail.com>
To: "Junio C Hamano" <junio@pobox.com>
Cc: git@vger.kernel.org, "Johannes Sixt" <johannes.sixt@telecom.at>
Subject: Re: [PATCH v2 2/3] builtin-status: submodule summary support
Date: Sat, 12 Apr 2008 13:28:22 +0800 [thread overview]
Message-ID: <46dff0320804112228i557652b2kcad8fe524a9638ff@mail.gmail.com> (raw)
In-Reply-To: <7vtzi8owf9.fsf@gitster.siamese.dyndns.org>
On Sat, Apr 12, 2008 at 6:31 AM, Junio C Hamano <junio@pobox.com> wrote:
> 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) != 0;
> }
>
> With that, your configuration parser can do something like:
>
>
> if (!strcmp(k, "status.submodulesummary")) {
> int is_bool, val;
> val = git_config_bool_or_int(k, v, &b);
> if (is_bool || val <= 0) {
> wt_status_submodule_summary_enabled = val;
> } else {
> wt_status_submodule_summary = val;
> wt_status_submodule_summary_enabled = 1;
> }
> }
>
> and skip the call to wt_status_print_submodule_summary() when not
> enabled.
>
>
> > int wt_status_relative_paths = 1;
> > int wt_status_use_color = -1;
> > +int wt_status_submodule_summary = -1; /* unspecified */
> +int wt_status_submodule_summary_enabled;
>
> The call site in wt_status_print() would look like:
>
> ...
>
> wt_status_print_changed(s);
> if (wt_status_submodule_summary_enabled > 0)
>
> wt_status_print_submodule_summary(s);
> wt_status_print_untracked(s);
> ...
>
How about the following?
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);
+}
+
int git_config_string(const char **dest, const char *var, const char *value)
{
if (!value)
diff --git a/wt-status.c b/wt-status.c
index 22385f5..3baa128 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -366,7 +366,10 @@ void wt_status_print(struct wt_status *s)
int git_status_config(const char *k, const char *v)
{
if (!strcmp(k, "status.submodulesummary")) {
- wt_status_submodule_summary = atoi(v);
+ int is_bool;
+ wt_status_submodule_summary = git_config_bool_or_int(k, v, &is_bool);
+ if (is_bool && wt_status_submodule_summary)
+ wt_status_submodule_summary = -1;
return 0;
}
if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
--
Ping Yin
next prev parent reply other threads:[~2008-04-12 5:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-10 15:35 [PATCH v2] builtin-status: submodule summary support Ping Yin
2008-04-10 15:35 ` [PATCH v2 1/3] git-submodule summary: --for-status option Ping Yin
2008-04-10 15:35 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin
2008-04-10 15:35 ` [PATCH v2 3/3] buitin-status: Add tests for submodule summary Ping Yin
2008-04-11 22:31 ` [PATCH v2 2/3] builtin-status: submodule summary support Junio C Hamano
2008-04-12 5:28 ` Ping Yin [this message]
2008-04-12 14:47 ` Ping Yin
2008-04-12 16:13 ` Johannes Sixt
-- strict thread matches above, loose matches on Subject: below --
2008-04-10 15:50 [PATCH/RFC] submodule: fallback to .gitmodules and multiple level module definition Ping Yin
2008-04-10 15:50 ` [PATCH/RFC 1/7] git-submodule: Extract functions module_info and module_url Ping Yin
2008-04-10 15:50 ` [PATCH v2 1/3] git-submodule summary: --for-status option Ping Yin
2008-04-10 15:50 ` [PATCH v2 2/3] builtin-status: submodule summary support Ping Yin
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=46dff0320804112228i557652b2kcad8fe524a9638ff@mail.gmail.com \
--to=pkufranky@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.sixt@telecom.at \
--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).