Skip to content

Commit a53f2ec

Browse files
committed
git_config_bool_or_int()
This new function can be used by config parsers to tell if a variable is simply set, set to 1, or set to "true". Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4cdda2b commit a53f2ec

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ extern int git_parse_long(const char *, long *);
692692
extern int git_parse_ulong(const char *, unsigned long *);
693693
extern int git_config_int(const char *, const char *);
694694
extern unsigned long git_config_ulong(const char *, const char *);
695+
extern int git_config_bool_or_int(const char *, const char *, int *);
695696
extern int git_config_bool(const char *, const char *);
696697
extern int git_config_string(const char **, const char *, const char *);
697698
extern int git_config_set(const char *, const char *);

config.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ unsigned long git_config_ulong(const char *name, const char *value)
303303
return ret;
304304
}
305305

306-
int git_config_bool(const char *name, const char *value)
306+
int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
307307
{
308+
*is_bool = 1;
308309
if (!value)
309310
return 1;
310311
if (!*value)
@@ -313,9 +314,16 @@ int git_config_bool(const char *name, const char *value)
313314
return 1;
314315
if (!strcasecmp(value, "false") || !strcasecmp(value, "no"))
315316
return 0;
317+
*is_bool = 0;
316318
return git_config_int(name, value) != 0;
317319
}
318320

321+
int git_config_bool(const char *name, const char *value)
322+
{
323+
int discard;
324+
return git_config_bool_or_int(name, value, &discard);
325+
}
326+
319327
int git_config_string(const char **dest, const char *var, const char *value)
320328
{
321329
if (!value)

0 commit comments

Comments
 (0)