* [PATCH 1/2] config api: Add git_config_magic_int()
@ 2008-02-12 8:21 Andreas Ericsson
2008-02-12 21:41 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Ericsson @ 2008-02-12 8:21 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
There are some values where git can reasonably guess at an
optimal value. For such occasions, this is a nifty addendum
to the config api, letting the caller specify a magic string
and a magic setting to return if the value of the variable
matches the magic string.
An example would be for threads, where 0 = auto is overly
voodoo-ish for some consumers, and typing "auto" is much
nicer and more immediately obvious.
Signed-off-by: Andreas Ericsson <ae@op5.se>
---
cache.h | 1 +
config.c | 9 +++++++++
2 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/cache.h b/cache.h
index 3867ba7..1b923ad 100644
--- a/cache.h
+++ b/cache.h
@@ -623,6 +623,7 @@ extern int git_config(config_fn_t fn);
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 int git_config_magic_int(const char *, const char *, const char *, int);
extern unsigned long git_config_ulong(const char *, const char *);
extern int git_config_bool(const char *, const char *);
extern int git_config_set(const char *, const char *);
diff --git a/config.c b/config.c
index 3e72778..635d92b 100644
--- a/config.c
+++ b/config.c
@@ -288,6 +288,15 @@ int git_config_int(const char *name, const char *value)
return ret;
}
+int git_config_magic_int(const char *name, const char *value,
+ const char *magic_value, int magic_setting)
+{
+ if (value && !strcasecmp(value, magic_value))
+ return magic_setting;
+
+ return git_config_int(name, value);
+}
+
unsigned long git_config_ulong(const char *name, const char *value)
{
unsigned long ret;
--
1.5.4.rc5.11.g0eab8
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] config api: Add git_config_magic_int()
2008-02-12 8:21 [PATCH 1/2] config api: Add git_config_magic_int() Andreas Ericsson
@ 2008-02-12 21:41 ` Junio C Hamano
2008-02-13 13:58 ` Andreas Ericsson
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2008-02-12 21:41 UTC (permalink / raw)
To: Andreas Ericsson; +Cc: Git Mailing List
Andreas Ericsson <ae@op5.se> writes:
> +int git_config_magic_int(const char *name, const char *value,
> + const char *magic_value, int magic_setting)
> +{
> + if (value && !strcasecmp(value, magic_value))
> + return magic_setting;
> +
> + return git_config_int(name, value);
> +}
I do not think this has much to do with any "magic".
An instruction "use 0 threads" when taken literally would mean
"do not use any CPU" which would not make much sense. In that
sense, giving a magic meaning of "guess an appropriate value" to
0 may be a good idea. A valid alternative would be to make 0
mean the same thing as 1, but that is much more boring ;-)
But if you did so, that means "var = 0" invokes the same magic
as "var = auto". The magic lives in "0", and not in "auto".
I think the direction your patch leads us is good, but I think
it should allow an array of symbolic ways to spell values to be
useful, that is:
struct config_symbolic_int {
const char *name;
int value;
};
int git_config_symbolic_int(const char *var, const char *value,
struct config_symbolic_int *);
That way, you can have
{ { "high", 9 }, { "default", 0 }, { "low", 1 } };
and say things like "zlevel = high|default|low".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] config api: Add git_config_magic_int()
2008-02-12 21:41 ` Junio C Hamano
@ 2008-02-13 13:58 ` Andreas Ericsson
0 siblings, 0 replies; 3+ messages in thread
From: Andreas Ericsson @ 2008-02-13 13:58 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
Junio C Hamano wrote:
> Andreas Ericsson <ae@op5.se> writes:
>
>> +int git_config_magic_int(const char *name, const char *value,
>> + const char *magic_value, int magic_setting)
>> +{
>> + if (value && !strcasecmp(value, magic_value))
>> + return magic_setting;
>> +
>> + return git_config_int(name, value);
>> +}
>
> I do not think this has much to do with any "magic".
>
> An instruction "use 0 threads" when taken literally would mean
> "do not use any CPU" which would not make much sense. In that
> sense, giving a magic meaning of "guess an appropriate value" to
> 0 may be a good idea. A valid alternative would be to make 0
> mean the same thing as 1, but that is much more boring ;-)
>
> But if you did so, that means "var = 0" invokes the same magic
> as "var = auto". The magic lives in "0", and not in "auto".
>
> I think the direction your patch leads us is good, but I think
> it should allow an array of symbolic ways to spell values to be
> useful, that is:
>
> struct config_symbolic_int {
> const char *name;
> int value;
> };
> int git_config_symbolic_int(const char *var, const char *value,
> struct config_symbolic_int *);
>
> That way, you can have
>
> { { "high", 9 }, { "default", 0 }, { "low", 1 } };
>
> and say things like "zlevel = high|default|low".
Good idea. I'll look into it right away. I sorely need a break from
coding backends for webapps anyway. I'll send this one separately and
then tack 2/2 onto the builtin-pack-objects patch thing. That one
should probably be a /3 series anyway, when I come to think of it.
--
Andreas Ericsson andreas.ericsson@op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-02-13 13:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-12 8:21 [PATCH 1/2] config api: Add git_config_magic_int() Andreas Ericsson
2008-02-12 21:41 ` Junio C Hamano
2008-02-13 13:58 ` Andreas Ericsson
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).