diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-01-21 15:29:58 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-01-22 11:44:01 -0800 |
commit | 81dd4fd384d24ad247a88d1d04778de241e1781a (patch) | |
tree | 5a31e1900133b68e24c3ca7d6623dec9228a1702 /parse-options.h | |
parent | 35c141768c4c7c486017a2d0cc615b9384b4b672 (diff) | |
download | git-jc/parse-options-humint.tar.gz |
parse-options: refactor human-friendly-integer parser out of pack-objectsjc/parse-options-humint
We only had code to understand unit suffixes such as g/m/k (as in
2g/400m/8k) in the configuration parser but not in the command line
option parser. "git pack-objects" worked it around by having a
custom extension to the parse-options API; make it available to
other callers.
The new macro is not called OPT_ULONG() but OPT_HUM_ULONG(), as it
would be bizzarre to have ULONG that understands human friendly
units while INTEGER that does not. It is not named with a shorter
"OPT_HULONG", primarily to avoid having to name a future parallel
for parsing human friendly integer "OPT_HINT".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'parse-options.h')
-rw-r--r-- | parse-options.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/parse-options.h b/parse-options.h index 9b94596e4a..d65ecdb4e2 100644 --- a/parse-options.h +++ b/parse-options.h @@ -16,6 +16,7 @@ enum parse_opt_type { /* options with arguments (usually) */ OPTION_STRING, OPTION_INTEGER, + OPTION_ULONG, OPTION_CALLBACK, OPTION_LOWLEVEL_CALLBACK, OPTION_FILENAME @@ -40,6 +41,7 @@ enum parse_opt_option_flags { PARSE_OPT_LASTARG_DEFAULT = 16, PARSE_OPT_NODASH = 32, PARSE_OPT_LITERAL_ARGHELP = 64, + PARSE_OPT_HUMAN_NUMBER = 128, PARSE_OPT_SHELL_EVAL = 256 }; @@ -131,6 +133,9 @@ struct option { #define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, \ (h), PARSE_OPT_NOARG, NULL, (p) } #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) } +#define OPT_ULONG(s, l, v, h) { OPTION_ULONG, (s), (l), (v), N_("n"), (h) } +#define OPT_HUM_ULONG(s, l, v, h) { OPTION_ULONG, (s), (l), (v), N_("n"), (h), \ + PARSE_OPT_HUMAN_NUMBER } #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) } #define OPT_STRING_LIST(s, l, v, a, h) \ { OPTION_CALLBACK, (s), (l), (v), (a), \ |