Re: [PATCH 2/2] Move unsigned long option parsing out of pack-objects.c

2015-06-22 Thread Junio C Hamano
Charles Bailey char...@hashpling.org writes:

 On Sun, Jun 21, 2015 at 07:25:44PM +0100, Charles Bailey wrote:
 From: Charles Bailey cbaile...@bloomberg.net
 
 diff --git a/parse-options.c b/parse-options.c
 index 80106c0..101b649 100644
 --- a/parse-options.c
 +++ b/parse-options.c
 @@ -180,6 +180,23 @@ static int get_value(struct parse_opt_ctx_t *p,
  return opterror(opt, expects a numerical value, 
 flags);
  return 0;
  
 +case OPTION_MAGNITUDE:
 +if (unset) {
 +*(unsigned long *)opt-value = 0;
 +return 0;
 +}
 +if (opt-flags  PARSE_OPT_OPTARG  !p-opt) {
 +*(unsigned long *)opt-value = opt-defval;
 +return 0;
 +}
 +if (get_arg(p, opt, flags, arg))
 +return -1;
 +if (!git_parse_ulong(arg, opt-value))
 +return opterror(opt,
 +expects a integer value with an optional k/m/g 
 suffix,
 +flags);
 +return 0;
 +

 Spotted after sending:
 s/expects a integer/expects an integer/

Thanks.
--
To unsubscribe from this list: send the line unsubscribe git in


Re: [PATCH 2/2] Move unsigned long option parsing out of pack-objects.c

2015-06-22 Thread Junio C Hamano
Charles Bailey char...@hashpling.org writes:

 From: Charles Bailey cbaile...@bloomberg.net

 The unsigned long option parsing (including 'k'/'m'/'g' suffix parsing)
 is more widely applicable. Add support for OPT_MAGNITUDE to
 parse-options.h and change pack-objects.c use this support.

 The error behavior on parse errors follows that of OPT_INTEGER.
 The name of the option that failed to parse is reported with a brief
 message describing the expect format for the option argument and then
 the full usage message for the command invoked.

 This is differs from the previous behavior for OPT_ULONG used in

s/is //; (locally fixed--no need to resend).
--
To unsubscribe from this list: send the line unsubscribe git in


Re: [PATCH 2/2] Move unsigned long option parsing out of pack-objects.c

2015-06-21 Thread Charles Bailey
On Sun, Jun 21, 2015 at 07:25:44PM +0100, Charles Bailey wrote:
 From: Charles Bailey cbaile...@bloomberg.net
 
 diff --git a/parse-options.c b/parse-options.c
 index 80106c0..101b649 100644
 --- a/parse-options.c
 +++ b/parse-options.c
 @@ -180,6 +180,23 @@ static int get_value(struct parse_opt_ctx_t *p,
   return opterror(opt, expects a numerical value, 
 flags);
   return 0;
  
 + case OPTION_MAGNITUDE:
 + if (unset) {
 + *(unsigned long *)opt-value = 0;
 + return 0;
 + }
 + if (opt-flags  PARSE_OPT_OPTARG  !p-opt) {
 + *(unsigned long *)opt-value = opt-defval;
 + return 0;
 + }
 + if (get_arg(p, opt, flags, arg))
 + return -1;
 + if (!git_parse_ulong(arg, opt-value))
 + return opterror(opt,
 + expects a integer value with an optional k/m/g 
 suffix,
 + flags);
 + return 0;
 +

Spotted after sending:
s/expects a integer/expects an integer/
--
To unsubscribe from this list: send the line unsubscribe git in


[PATCH 2/2] Move unsigned long option parsing out of pack-objects.c

2015-06-21 Thread Charles Bailey
From: Charles Bailey cbaile...@bloomberg.net

The unsigned long option parsing (including 'k'/'m'/'g' suffix parsing)
is more widely applicable. Add support for OPT_MAGNITUDE to
parse-options.h and change pack-objects.c use this support.

The error behavior on parse errors follows that of OPT_INTEGER.
The name of the option that failed to parse is reported with a brief
message describing the expect format for the option argument and then
the full usage message for the command invoked.

This is differs from the previous behavior for OPT_ULONG used in
pack-objects for --max-pack-size and --window-memory which used to
display the value supplied in the error message and did not display the
full usage message.

Signed-off-by: Charles Bailey cbaile...@bloomberg.net
---
 Documentation/technical/api-parse-options.txt |  6 
 builtin/pack-objects.c| 25 +++
 parse-options.c   | 17 ++
 parse-options.h   |  3 ++
 t/t0040-parse-options.sh  | 45 ---
 test-parse-options.c  |  3 ++
 6 files changed, 73 insertions(+), 26 deletions(-)

diff --git a/Documentation/technical/api-parse-options.txt 
b/Documentation/technical/api-parse-options.txt
index 1f2db31..525cb2f 100644
--- a/Documentation/technical/api-parse-options.txt
+++ b/Documentation/technical/api-parse-options.txt
@@ -168,6 +168,12 @@ There are some macros to easily define options:
Introduce an option with integer argument.
The integer is put into `int_var`.
 
+`OPT_MAGNITUDE(short, long, unsigned_long_var, description)`::
+   Introduce an option with a size argument. The argument must be a
+   non-negative integer and may include a suffix of 'k', 'm' or 'g' to
+   scale the provided value by 1024, 1024^2 or 1024^3 respectively.
+   The scaled value is put into `unsigned_long_var`.
+
 `OPT_DATE(short, long, int_var, description)`::
Introduce an option with date argument, see `approxidate()`.
The timestamp is put into `int_var`.
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 80fe8c7..62cc16d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -2588,23 +2588,6 @@ static int option_parse_unpack_unreachable(const struct 
option *opt,
return 0;
 }
 
-static int option_parse_ulong(const struct option *opt,
- const char *arg, int unset)
-{
-   if (unset)
-   die(_(option %s does not accept negative form),
-   opt-long_name);
-
-   if (!git_parse_ulong(arg, opt-value))
-   die(_(unable to parse value '%s' for option %s),
-   arg, opt-long_name);
-   return 0;
-}
-
-#define OPT_ULONG(s, l, v, h) \
-   { OPTION_CALLBACK, (s), (l), (v), n, (h), \
- PARSE_OPT_NONEG, option_parse_ulong }
-
 int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 {
int use_internal_rev_list = 0;
@@ -2627,16 +2610,16 @@ int cmd_pack_objects(int argc, const char **argv, const 
char *prefix)
{ OPTION_CALLBACK, 0, index-version, NULL, 
N_(version[,offset]),
  N_(write the pack index file in the specified idx format 
version),
  0, option_parse_index_version },
-   OPT_ULONG(0, max-pack-size, pack_size_limit,
- N_(maximum size of each output pack file)),
+   OPT_MAGNITUDE(0, max-pack-size, pack_size_limit,
+ N_(maximum size of each output pack file)),
OPT_BOOL(0, local, local,
 N_(ignore borrowed objects from alternate object 
store)),
OPT_BOOL(0, incremental, incremental,
 N_(ignore packed objects)),
OPT_INTEGER(0, window, window,
N_(limit pack window by objects)),
-   OPT_ULONG(0, window-memory, window_memory_limit,
- N_(limit pack window by memory in addition to object 
limit)),
+   OPT_MAGNITUDE(0, window-memory, window_memory_limit,
+ N_(limit pack window by memory in addition to 
object limit)),
OPT_INTEGER(0, depth, depth,
N_(maximum length of delta chain allowed in the 
resulting pack)),
OPT_BOOL(0, reuse-delta, reuse_delta,
diff --git a/parse-options.c b/parse-options.c
index 80106c0..101b649 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -180,6 +180,23 @@ static int get_value(struct parse_opt_ctx_t *p,
return opterror(opt, expects a numerical value, 
flags);
return 0;
 
+   case OPTION_MAGNITUDE:
+   if (unset) {
+   *(unsigned long *)opt-value = 0;
+   return 0;
+   }
+   if (opt-flags