Skip to content

Commit 785c17d

Browse files
pks-tgitster
authored andcommitted
parse-options: rename OPT_MAGNITUDE() to OPT_UNSIGNED()
With the preceding commit, `OPT_INTEGER()` has learned to support unit factors. Consequently, the major differencen between `OPT_INTEGER()` and `OPT_MAGNITUDE()` isn't the support of unit factors anymore, as both of them do support them now. Instead, the difference is that one handles signed and the other handles unsigned integers. Adapt the name of `OPT_MAGNITUDE()` accordingly by renaming it to `OPT_UNSIGNED()`. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ff1a34 commit 785c17d

File tree

9 files changed

+47
-47
lines changed

9 files changed

+47
-47
lines changed

Documentation/technical/api-parse-options.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ There are some macros to easily define options:
216216
scale the provided value by 1024, 1024^2 or 1024^3 respectively.
217217
The scaled value is put into `int_var`.
218218
219-
`OPT_MAGNITUDE(short, long, &unsigned_long_var, description)`::
220-
Introduce an option with a size argument. The argument must be a
219+
`OPT_UNSIGNED(short, long, &unsigned_long_var, description)`::
220+
Introduce an option with an unsigned integer argument. The argument must be a
221221
non-negative integer and may include a suffix of 'k', 'm' or 'g' to
222222
scale the provided value by 1024, 1024^2 or 1024^3 respectively.
223223
The scaled value is put into `unsigned_long_var`.

builtin/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ struct repository *repo UNUSED)
709709
.defval = (intptr_t)prune_expire_arg,
710710
},
711711
OPT_BOOL(0, "cruft", &cfg.cruft_packs, N_("pack unreferenced objects separately")),
712-
OPT_MAGNITUDE(0, "max-cruft-size", &cfg.max_cruft_size,
713-
N_("with --cruft, limit the size of new cruft packs")),
712+
OPT_UNSIGNED(0, "max-cruft-size", &cfg.max_cruft_size,
713+
N_("with --cruft, limit the size of new cruft packs")),
714714
OPT_BOOL(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")),
715715
OPT_BOOL_F(0, "auto", &opts.auto_flag, N_("enable auto-gc mode"),
716716
PARSE_OPT_NOCOMPLETE),

builtin/multi-pack-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
245245
{
246246
struct option *options;
247247
static struct option builtin_multi_pack_index_repack_options[] = {
248-
OPT_MAGNITUDE(0, "batch-size", &opts.batch_size,
248+
OPT_UNSIGNED(0, "batch-size", &opts.batch_size,
249249
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
250250
OPT_BIT(0, "progress", &opts.flags,
251251
N_("force progress reporting"), MIDX_PROGRESS),

builtin/pack-objects.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4483,16 +4483,16 @@ int cmd_pack_objects(int argc,
44834483
OPT_CALLBACK_F(0, "index-version", &pack_idx_opts, N_("<version>[,<offset>]"),
44844484
N_("write the pack index file in the specified idx format version"),
44854485
PARSE_OPT_NONEG, option_parse_index_version),
4486-
OPT_MAGNITUDE(0, "max-pack-size", &pack_size_limit,
4487-
N_("maximum size of each output pack file")),
4486+
OPT_UNSIGNED(0, "max-pack-size", &pack_size_limit,
4487+
N_("maximum size of each output pack file")),
44884488
OPT_BOOL(0, "local", &local,
44894489
N_("ignore borrowed objects from alternate object store")),
44904490
OPT_BOOL(0, "incremental", &incremental,
44914491
N_("ignore packed objects")),
44924492
OPT_INTEGER(0, "window", &window,
44934493
N_("limit pack window by objects")),
4494-
OPT_MAGNITUDE(0, "window-memory", &window_memory_limit,
4495-
N_("limit pack window by memory in addition to object limit")),
4494+
OPT_UNSIGNED(0, "window-memory", &window_memory_limit,
4495+
N_("limit pack window by memory in addition to object limit")),
44964496
OPT_INTEGER(0, "depth", &depth,
44974497
N_("maximum length of delta chain allowed in the resulting pack")),
44984498
OPT_BOOL(0, "reuse-delta", &reuse_delta,

builtin/repack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,8 +1202,8 @@ int cmd_repack(int argc,
12021202
PACK_CRUFT),
12031203
OPT_STRING(0, "cruft-expiration", &cruft_expiration, N_("approxidate"),
12041204
N_("with --cruft, expire objects older than this")),
1205-
OPT_MAGNITUDE(0, "max-cruft-size", &cruft_po_args.max_pack_size,
1206-
N_("with --cruft, limit the size of new cruft packs")),
1205+
OPT_UNSIGNED(0, "max-cruft-size", &cruft_po_args.max_pack_size,
1206+
N_("with --cruft, limit the size of new cruft packs")),
12071207
OPT_BOOL('d', NULL, &delete_redundant,
12081208
N_("remove redundant packs, and run git-prune-packed")),
12091209
OPT_BOOL('f', NULL, &po_args.no_reuse_delta,
@@ -1233,8 +1233,8 @@ int cmd_repack(int argc,
12331233
N_("limits the maximum delta depth")),
12341234
OPT_STRING(0, "threads", &opt_threads, N_("n"),
12351235
N_("limits the maximum number of threads")),
1236-
OPT_MAGNITUDE(0, "max-pack-size", &po_args.max_pack_size,
1237-
N_("maximum size of each packfile")),
1236+
OPT_UNSIGNED(0, "max-pack-size", &po_args.max_pack_size,
1237+
N_("maximum size of each packfile")),
12381238
OPT_PARSE_LIST_OBJECTS_FILTER(&po_args.filter_options),
12391239
OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
12401240
N_("repack objects in packs marked with .keep")),

parse-options.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
191191
optname(opt, flags));
192192
return 0;
193193

194-
case OPTION_MAGNITUDE:
194+
case OPTION_UNSIGNED:
195195
if (unset) {
196196
*(unsigned long *)opt->value = 0;
197197
return 0;
@@ -656,7 +656,7 @@ static void show_negated_gitcomp(const struct option *opts, int show_all,
656656
case OPTION_STRING:
657657
case OPTION_FILENAME:
658658
case OPTION_INTEGER:
659-
case OPTION_MAGNITUDE:
659+
case OPTION_UNSIGNED:
660660
case OPTION_CALLBACK:
661661
case OPTION_BIT:
662662
case OPTION_NEGBIT:
@@ -708,7 +708,7 @@ static int show_gitcomp(const struct option *opts, int show_all)
708708
case OPTION_STRING:
709709
case OPTION_FILENAME:
710710
case OPTION_INTEGER:
711-
case OPTION_MAGNITUDE:
711+
case OPTION_UNSIGNED:
712712
case OPTION_CALLBACK:
713713
if (opts->flags & PARSE_OPT_NOARG)
714714
break;

parse-options.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum parse_opt_type {
2525
/* options with arguments (usually) */
2626
OPTION_STRING,
2727
OPTION_INTEGER,
28-
OPTION_MAGNITUDE,
28+
OPTION_UNSIGNED,
2929
OPTION_CALLBACK,
3030
OPTION_LOWLEVEL_CALLBACK,
3131
OPTION_FILENAME
@@ -270,8 +270,8 @@ struct option {
270270
#define OPT_CMDMODE(s, l, v, h, i) OPT_CMDMODE_F(s, l, v, h, i, 0)
271271

272272
#define OPT_INTEGER(s, l, v, h) OPT_INTEGER_F(s, l, v, h, 0)
273-
#define OPT_MAGNITUDE(s, l, v, h) { \
274-
.type = OPTION_MAGNITUDE, \
273+
#define OPT_UNSIGNED(s, l, v, h) { \
274+
.type = OPTION_UNSIGNED, \
275275
.short_name = (s), \
276276
.long_name = (l), \
277277
.value = (v), \

t/helper/test-parse-options.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
static int boolean = 0;
88
static int integer = 0;
9-
static unsigned long magnitude = 0;
9+
static unsigned long unsigned_integer = 0;
1010
static timestamp_t timestamp;
1111
static int abbrev = 7;
1212
static int verbose = -1; /* unspecified */
@@ -140,7 +140,7 @@ int cmd__parse_options(int argc, const char **argv)
140140
OPT_GROUP(""),
141141
OPT_INTEGER('i', "integer", &integer, "get a integer"),
142142
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
143-
OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
143+
OPT_UNSIGNED('u', "unsigned", &unsigned_integer, "get an unsigned integer"),
144144
OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
145145
OPT_CMDMODE(0, "mode1", &integer, "set integer to 1 (cmdmode option)", 1),
146146
OPT_CMDMODE(0, "mode2", &integer, "set integer to 2 (cmdmode option)", 2),
@@ -210,7 +210,7 @@ int cmd__parse_options(int argc, const char **argv)
210210
}
211211
show(&expect, &ret, "boolean: %d", boolean);
212212
show(&expect, &ret, "integer: %d", integer);
213-
show(&expect, &ret, "magnitude: %lu", magnitude);
213+
show(&expect, &ret, "unsigned: %lu", unsigned_integer);
214214
show(&expect, &ret, "timestamp: %"PRItime, timestamp);
215215
show(&expect, &ret, "string: %s", string ? string : "(not set)");
216216
show(&expect, &ret, "abbrev: %d", abbrev);

t/t0040-parse-options.sh

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ usage: test-tool parse-options <options>
2323
-i, --[no-]integer <n>
2424
get a integer
2525
-j <n> get a integer, too
26-
-m, --magnitude <n> get a magnitude
26+
-u, --unsigned <n> get an unsigned integer
2727
--[no-]set23 set integer to 23
2828
--mode1 set integer to 1 (cmdmode option)
2929
--mode2 set integer to 2 (cmdmode option)
@@ -115,30 +115,30 @@ test_expect_success 'OPT_INTEGER() negative' 'check integer: -2345 -i -2345'
115115
test_expect_success 'OPT_INTEGER() kilo' 'check integer: 239616 -i 234k'
116116
test_expect_success 'OPT_INTEGER() negative kilo' 'check integer: -239616 -i -234k'
117117

118-
test_expect_success 'OPT_MAGNITUDE() simple' '
119-
check magnitude: 2345678 -m 2345678
118+
test_expect_success 'OPT_UNSIGNED() simple' '
119+
check unsigned: 2345678 -u 2345678
120120
'
121121

122-
test_expect_success 'OPT_MAGNITUDE() kilo' '
123-
check magnitude: 239616 -m 234k
122+
test_expect_success 'OPT_UNSIGNED() kilo' '
123+
check unsigned: 239616 -u 234k
124124
'
125125

126-
test_expect_success 'OPT_MAGNITUDE() mega' '
127-
check magnitude: 104857600 -m 100m
126+
test_expect_success 'OPT_UNSIGNED() mega' '
127+
check unsigned: 104857600 -u 100m
128128
'
129129

130-
test_expect_success 'OPT_MAGNITUDE() giga' '
131-
check magnitude: 1073741824 -m 1g
130+
test_expect_success 'OPT_UNSIGNED() giga' '
131+
check unsigned: 1073741824 -u 1g
132132
'
133133

134-
test_expect_success 'OPT_MAGNITUDE() 3giga' '
135-
check magnitude: 3221225472 -m 3g
134+
test_expect_success 'OPT_UNSIGNED() 3giga' '
135+
check unsigned: 3221225472 -u 3g
136136
'
137137

138138
cat >expect <<\EOF
139139
boolean: 2
140140
integer: 1729
141-
magnitude: 16384
141+
unsigned: 16384
142142
timestamp: 0
143143
string: 123
144144
abbrev: 7
@@ -149,7 +149,7 @@ file: prefix/my.file
149149
EOF
150150

151151
test_expect_success 'short options' '
152-
test-tool parse-options -s123 -b -i 1729 -m 16k -b -vv -n -F my.file \
152+
test-tool parse-options -s123 -b -i 1729 -u 16k -b -vv -n -F my.file \
153153
>output 2>output.err &&
154154
test_cmp expect output &&
155155
test_must_be_empty output.err
@@ -158,7 +158,7 @@ test_expect_success 'short options' '
158158
cat >expect <<\EOF
159159
boolean: 2
160160
integer: 1729
161-
magnitude: 16384
161+
unsigned: 16384
162162
timestamp: 0
163163
string: 321
164164
abbrev: 10
@@ -169,7 +169,7 @@ file: prefix/fi.le
169169
EOF
170170

171171
test_expect_success 'long options' '
172-
test-tool parse-options --boolean --integer 1729 --magnitude 16k \
172+
test-tool parse-options --boolean --integer 1729 --unsigned 16k \
173173
--boolean --string2=321 --verbose --verbose --no-dry-run \
174174
--abbrev=10 --file fi.le --obsolete \
175175
>output 2>output.err &&
@@ -181,7 +181,7 @@ test_expect_success 'abbreviate to something longer than SHA1 length' '
181181
cat >expect <<-EOF &&
182182
boolean: 0
183183
integer: 0
184-
magnitude: 0
184+
unsigned: 0
185185
timestamp: 0
186186
string: (not set)
187187
abbrev: 100
@@ -255,7 +255,7 @@ test_expect_success 'superfluous value provided: cmdmode' '
255255
cat >expect <<\EOF
256256
boolean: 1
257257
integer: 13
258-
magnitude: 0
258+
unsigned: 0
259259
timestamp: 0
260260
string: 123
261261
abbrev: 7
@@ -278,7 +278,7 @@ test_expect_success 'intermingled arguments' '
278278
cat >expect <<\EOF
279279
boolean: 0
280280
integer: 2
281-
magnitude: 0
281+
unsigned: 0
282282
timestamp: 0
283283
string: (not set)
284284
abbrev: 7
@@ -345,7 +345,7 @@ cat >expect <<\EOF
345345
Callback: "four", 0
346346
boolean: 5
347347
integer: 4
348-
magnitude: 0
348+
unsigned: 0
349349
timestamp: 0
350350
string: (not set)
351351
abbrev: 7
@@ -370,7 +370,7 @@ test_expect_success 'OPT_CALLBACK() and callback errors work' '
370370
cat >expect <<\EOF
371371
boolean: 1
372372
integer: 23
373-
magnitude: 0
373+
unsigned: 0
374374
timestamp: 0
375375
string: (not set)
376376
abbrev: 7
@@ -449,7 +449,7 @@ test_expect_success 'OPT_NUMBER_CALLBACK() works' '
449449
cat >expect <<\EOF
450450
boolean: 0
451451
integer: 0
452-
magnitude: 0
452+
unsigned: 0
453453
timestamp: 0
454454
string: (not set)
455455
abbrev: 7
@@ -773,14 +773,14 @@ test_expect_success 'subcommands are incompatible with KEEP_DASHDASH unless in c
773773
grep ^BUG err
774774
'
775775

776-
test_expect_success 'negative magnitude' '
777-
test_must_fail test-tool parse-options --magnitude -1 >out 2>err &&
776+
test_expect_success 'negative unsigned' '
777+
test_must_fail test-tool parse-options --unsigned -1 >out 2>err &&
778778
grep "non-negative integer" err &&
779779
test_must_be_empty out
780780
'
781781

782-
test_expect_success 'magnitude with units but no numbers' '
783-
test_must_fail test-tool parse-options --magnitude m >out 2>err &&
782+
test_expect_success 'unsigned with units but no numbers' '
783+
test_must_fail test-tool parse-options --unsigned m >out 2>err &&
784784
grep "non-negative integer" err &&
785785
test_must_be_empty out
786786
'

0 commit comments

Comments
 (0)