{"thread":{"id":"12054","subject":"[PATCH 1/2] config api: Add git_config_magic_int()","startedAt":"2008-02-12T08:21:21Z","lastAt":"2008-02-13T13:58:51Z","messageCount":3,"participants":["Andreas Ericsson","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"68495","messageId":"47B15701.8040803@op5.se","threadId":"12054","inReplyTo":null,"subject":"[PATCH 1/2] config api: Add git_config_magic_int()","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2008-02-12T08:21:21Z","receivedAt":"2008-02-12T08:21:21Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"There are some values where git can reasonably guess at an\noptimal value. For such occasions, this is a nifty addendum\nto the config api, letting the caller specify a magic string\nand a magic setting to return if the value of the variable\nmatches the magic string.\n\nAn example would be for threads, where 0 = auto is overly\nvoodoo-ish for some consumers, and typing \"auto\" is much\nnicer and more immediately obvious.\n\nSigned-off-by: Andreas Ericsson <ae@op5.se>\n---\n\n cache.h  |    1 +\n config.c |    9 +++++++++\n 2 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 3867ba7..1b923ad 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -623,6 +623,7 @@ extern int git_config(config_fn_t fn);\n extern int git_parse_long(const char *, long *);\n extern int git_parse_ulong(const char *, unsigned long *);\n extern int git_config_int(const char *, const char *);\n+extern int git_config_magic_int(const char *, const char *, const char *, int);\n extern unsigned long git_config_ulong(const char *, const char *);\n extern int git_config_bool(const char *, const char *);\n extern int git_config_set(const char *, const char *);\ndiff --git a/config.c b/config.c\nindex 3e72778..635d92b 100644\n--- a/config.c\n+++ b/config.c\n@@ -288,6 +288,15 @@ int git_config_int(const char *name, const char *value)\n \treturn ret;\n }\n \n+int git_config_magic_int(const char *name, const char *value,\n+\t\t\t const char *magic_value, int magic_setting)\n+{\n+\tif (value && !strcasecmp(value, magic_value))\n+\t\treturn magic_setting;\n+\n+\treturn git_config_int(name, value);\n+}\n+\n unsigned long git_config_ulong(const char *name, const char *value)\n {\n \tunsigned long ret;\n-- \n1.5.4.rc5.11.g0eab8\n"},{"id":"68554","messageId":"7vir0t3l9s.fsf@gitster.siamese.dyndns.org","threadId":"12054","inReplyTo":"47B15701.8040803@op5.se","subject":"Re: [PATCH 1/2] config api: Add git_config_magic_int()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-12T21:41:35Z","receivedAt":"2008-02-12T21:41:35Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Ericsson <ae@op5.se> writes:\n\n> +int git_config_magic_int(const char *name, const char *value,\n> +\t\t\t const char *magic_value, int magic_setting)\n> +{\n> +\tif (value && !strcasecmp(value, magic_value))\n> +\t\treturn magic_setting;\n> +\n> +\treturn git_config_int(name, value);\n> +}\n\nI do not think this has much to do with any \"magic\".\n\nAn instruction \"use 0 threads\" when taken literally would mean\n\"do not use any CPU\" which would not make much sense.  In that\nsense, giving a magic meaning of \"guess an appropriate value\" to\n0 may be a good idea.  A valid alternative would be to make 0\nmean the same thing as 1, but that is much more boring ;-)\n\nBut if you did so, that means \"var = 0\" invokes the same magic\nas \"var = auto\".  The magic lives in \"0\", and not in \"auto\".\n\nI think the direction your patch leads us is good, but I think\nit should allow an array of symbolic ways to spell values to be\nuseful, that is:\n\n\tstruct config_symbolic_int {\n        \tconst char *name;\n                int value;\n\t};\n        int git_config_symbolic_int(const char *var, const char *value,\n\t\t\t\t    struct config_symbolic_int *);\n\nThat way, you can have\n\n\t{ { \"high\", 9 }, { \"default\", 0 }, { \"low\", 1 } };\n\nand say things like \"zlevel = high|default|low\".\n"},{"id":"68652","messageId":"47B2F79B.9090406@op5.se","threadId":"12054","inReplyTo":"7vir0t3l9s.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 1/2] config api: Add git_config_magic_int()","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2008-02-13T13:58:51Z","receivedAt":"2008-02-13T13:58:51Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Junio C Hamano wrote:\n> Andreas Ericsson <ae@op5.se> writes:\n> \n>> +int git_config_magic_int(const char *name, const char *value,\n>> +\t\t\t const char *magic_value, int magic_setting)\n>> +{\n>> +\tif (value && !strcasecmp(value, magic_value))\n>> +\t\treturn magic_setting;\n>> +\n>> +\treturn git_config_int(name, value);\n>> +}\n> \n> I do not think this has much to do with any \"magic\".\n> \n> An instruction \"use 0 threads\" when taken literally would mean\n> \"do not use any CPU\" which would not make much sense.  In that\n> sense, giving a magic meaning of \"guess an appropriate value\" to\n> 0 may be a good idea.  A valid alternative would be to make 0\n> mean the same thing as 1, but that is much more boring ;-)\n> \n> But if you did so, that means \"var = 0\" invokes the same magic\n> as \"var = auto\".  The magic lives in \"0\", and not in \"auto\".\n> \n> I think the direction your patch leads us is good, but I think\n> it should allow an array of symbolic ways to spell values to be\n> useful, that is:\n> \n> \tstruct config_symbolic_int {\n>         \tconst char *name;\n>                 int value;\n> \t};\n>         int git_config_symbolic_int(const char *var, const char *value,\n> \t\t\t\t    struct config_symbolic_int *);\n> \n> That way, you can have\n> \n> \t{ { \"high\", 9 }, { \"default\", 0 }, { \"low\", 1 } };\n> \n> and say things like \"zlevel = high|default|low\".\n\nGood idea. I'll look into it right away. I sorely need a break from\ncoding backends for webapps anyway. I'll send this one separately and\nthen tack 2/2 onto the builtin-pack-objects patch thing. That one\nshould probably be a /3 series anyway, when I come to think of it.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"}]}