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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 17, 2025 at 12:49 UTC 785c17df7817df8512d2cb92cfc079ef0b4de27c
9 files changed +47 -47
Documentation/technical/api-parse-options.adoc
+2 -2
@@ -216,8 +216,8 @@ There are some macros to easily define options:
216 scale the provided value by 1024, 1024^2 or 1024^3 respectively.
217 The scaled value is put into `int_var`.
218
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
221 non-negative integer and may include a suffix of 'k', 'm' or 'g' to
222 scale the provided value by 1024, 1024^2 or 1024^3 respectively.
223 The scaled value is put into `unsigned_long_var`.
builtin/gc.c
+2 -2
@@ -709,8 +709,8 @@ struct repository *repo UNUSED)
709 .defval = (intptr_t)prune_expire_arg,
710 },
711 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")),
714 OPT_BOOL(0, "aggressive", &aggressive, N_("be more thorough (increased runtime)")),
715 OPT_BOOL_F(0, "auto", &opts.auto_flag, N_("enable auto-gc mode"),
716 PARSE_OPT_NOCOMPLETE),
builtin/multi-pack-index.c
+1 -1
@@ -245,7 +245,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
245 {
246 struct option *options;
247 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,
249 N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
250 OPT_BIT(0, "progress", &opts.flags,
251 N_("force progress reporting"), MIDX_PROGRESS),
builtin/pack-objects.c
+4 -4
@@ -4483,16 +4483,16 @@ int cmd_pack_objects(int argc,
4483 OPT_CALLBACK_F(0, "index-version", &pack_idx_opts, N_("<version>[,<offset>]"),
4484 N_("write the pack index file in the specified idx format version"),
4485 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")),
4488 OPT_BOOL(0, "local", &local,
4489 N_("ignore borrowed objects from alternate object store")),
4490 OPT_BOOL(0, "incremental", &incremental,
4491 N_("ignore packed objects")),
4492 OPT_INTEGER(0, "window", &window,
4493 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")),
4496 OPT_INTEGER(0, "depth", &depth,
4497 N_("maximum length of delta chain allowed in the resulting pack")),
4498 OPT_BOOL(0, "reuse-delta", &reuse_delta,
builtin/repack.c
+4 -4
@@ -1202,8 +1202,8 @@ int cmd_repack(int argc,
1202 PACK_CRUFT),
1203 OPT_STRING(0, "cruft-expiration", &cruft_expiration, N_("approxidate"),
1204 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")),
1207 OPT_BOOL('d', NULL, &delete_redundant,
1208 N_("remove redundant packs, and run git-prune-packed")),
1209 OPT_BOOL('f', NULL, &po_args.no_reuse_delta,
@@ -1233,8 +1233,8 @@ int cmd_repack(int argc,
1233 N_("limits the maximum delta depth")),
1234 OPT_STRING(0, "threads", &opt_threads, N_("n"),
1235 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")),
1238 OPT_PARSE_LIST_OBJECTS_FILTER(&po_args.filter_options),
1239 OPT_BOOL(0, "pack-kept-objects", &pack_kept_objects,
1240 N_("repack objects in packs marked with .keep")),
parse-options.c
+3 -3
@@ -191,7 +191,7 @@ static enum parse_opt_result do_get_value(struct parse_opt_ctx_t *p,
191 optname(opt, flags));
192 return 0;
193
194 - case OPTION_MAGNITUDE:
194 + case OPTION_UNSIGNED:
195 if (unset) {
196 *(unsigned long *)opt->value = 0;
197 return 0;
@@ -656,7 +656,7 @@ static void show_negated_gitcomp(const struct option *opts, int show_all,
656 case OPTION_STRING:
657 case OPTION_FILENAME:
658 case OPTION_INTEGER:
659 - case OPTION_MAGNITUDE:
659 + case OPTION_UNSIGNED:
660 case OPTION_CALLBACK:
661 case OPTION_BIT:
662 case OPTION_NEGBIT:
@@ -708,7 +708,7 @@ static int show_gitcomp(const struct option *opts, int show_all)
708 case OPTION_STRING:
709 case OPTION_FILENAME:
710 case OPTION_INTEGER:
711 - case OPTION_MAGNITUDE:
711 + case OPTION_UNSIGNED:
712 case OPTION_CALLBACK:
713 if (opts->flags & PARSE_OPT_NOARG)
714 break;
parse-options.h
+3 -3
@@ -25,7 +25,7 @@ enum parse_opt_type {
25 /* options with arguments (usually) */
26 OPTION_STRING,
27 OPTION_INTEGER,
28 - OPTION_MAGNITUDE,
28 + OPTION_UNSIGNED,
29 OPTION_CALLBACK,
30 OPTION_LOWLEVEL_CALLBACK,
31 OPTION_FILENAME
@@ -270,8 +270,8 @@ struct option {
270 #define OPT_CMDMODE(s, l, v, h, i) OPT_CMDMODE_F(s, l, v, h, i, 0)
271
272 #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, \
275 .short_name = (s), \
276 .long_name = (l), \
277 .value = (v), \
t/helper/test-parse-options.c
+3 -3
@@ -6,7 +6,7 @@
6
7 static int boolean = 0;
8 static int integer = 0;
9 -static unsigned long magnitude = 0;
9 +static unsigned long unsigned_integer = 0;
10 static timestamp_t timestamp;
11 static int abbrev = 7;
12 static int verbose = -1; /* unspecified */
@@ -140,7 +140,7 @@ int cmd__parse_options(int argc, const char **argv)
140 OPT_GROUP(""),
141 OPT_INTEGER('i', "integer", &integer, "get a integer"),
142 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"),
144 OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
145 OPT_CMDMODE(0, "mode1", &integer, "set integer to 1 (cmdmode option)", 1),
146 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)
210 }
211 show(&expect, &ret, "boolean: %d", boolean);
212 show(&expect, &ret, "integer: %d", integer);
213 - show(&expect, &ret, "magnitude: %lu", magnitude);
213 + show(&expect, &ret, "unsigned: %lu", unsigned_integer);
214 show(&expect, &ret, "timestamp: %"PRItime, timestamp);
215 show(&expect, &ret, "string: %s", string ? string : "(not set)");
216 show(&expect, &ret, "abbrev: %d", abbrev);
t/t0040-parse-options.sh
+25 -25
@@ -23,7 +23,7 @@ usage: test-tool parse-options <options>
23 -i, --[no-]integer <n>
24 get a integer
25 -j <n> get a integer, too
26 - -m, --magnitude <n> get a magnitude
26 + -u, --unsigned <n> get an unsigned integer
27 --[no-]set23 set integer to 23
28 --mode1 set integer to 1 (cmdmode option)
29 --mode2 set integer to 2 (cmdmode option)
@@ -115,30 +115,30 @@ test_expect_success 'OPT_INTEGER() negative' 'check integer: -2345 -i -2345'
115 test_expect_success 'OPT_INTEGER() kilo' 'check integer: 239616 -i 234k'
116 test_expect_success 'OPT_INTEGER() negative kilo' 'check integer: -239616 -i -234k'
117
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
120 '
121
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
124 '
125
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
128 '
129
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
132 '
133
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
136 '
137
138 cat >expect <<\EOF
139 boolean: 2
140 integer: 1729
141 -magnitude: 16384
141 +unsigned: 16384
142 timestamp: 0
143 string: 123
144 abbrev: 7
@@ -149,7 +149,7 @@ file: prefix/my.file
149 EOF
150
151 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 \
153 >output 2>output.err &&
154 test_cmp expect output &&
155 test_must_be_empty output.err
@@ -158,7 +158,7 @@ test_expect_success 'short options' '
158 cat >expect <<\EOF
159 boolean: 2
160 integer: 1729
161 -magnitude: 16384
161 +unsigned: 16384
162 timestamp: 0
163 string: 321
164 abbrev: 10
@@ -169,7 +169,7 @@ file: prefix/fi.le
169 EOF
170
171 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 \
173 --boolean --string2=321 --verbose --verbose --no-dry-run \
174 --abbrev=10 --file fi.le --obsolete \
175 >output 2>output.err &&
@@ -181,7 +181,7 @@ test_expect_success 'abbreviate to something longer than SHA1 length' '
181 cat >expect <<-EOF &&
182 boolean: 0
183 integer: 0
184 - magnitude: 0
184 + unsigned: 0
185 timestamp: 0
186 string: (not set)
187 abbrev: 100
@@ -255,7 +255,7 @@ test_expect_success 'superfluous value provided: cmdmode' '
255 cat >expect <<\EOF
256 boolean: 1
257 integer: 13
258 -magnitude: 0
258 +unsigned: 0
259 timestamp: 0
260 string: 123
261 abbrev: 7
@@ -278,7 +278,7 @@ test_expect_success 'intermingled arguments' '
278 cat >expect <<\EOF
279 boolean: 0
280 integer: 2
281 -magnitude: 0
281 +unsigned: 0
282 timestamp: 0
283 string: (not set)
284 abbrev: 7
@@ -345,7 +345,7 @@ cat >expect <<\EOF
345 Callback: "four", 0
346 boolean: 5
347 integer: 4
348 -magnitude: 0
348 +unsigned: 0
349 timestamp: 0
350 string: (not set)
351 abbrev: 7
@@ -370,7 +370,7 @@ test_expect_success 'OPT_CALLBACK() and callback errors work' '
370 cat >expect <<\EOF
371 boolean: 1
372 integer: 23
373 -magnitude: 0
373 +unsigned: 0
374 timestamp: 0
375 string: (not set)
376 abbrev: 7
@@ -449,7 +449,7 @@ test_expect_success 'OPT_NUMBER_CALLBACK() works' '
449 cat >expect <<\EOF
450 boolean: 0
451 integer: 0
452 -magnitude: 0
452 +unsigned: 0
453 timestamp: 0
454 string: (not set)
455 abbrev: 7
@@ -773,14 +773,14 @@ test_expect_success 'subcommands are incompatible with KEEP_DASHDASH unless in c
773 grep ^BUG err
774 '
775
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 &&
778 grep "non-negative integer" err &&
779 test_must_be_empty out
780 '
781
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 &&
784 grep "non-negative integer" err &&
785 test_must_be_empty out
786 '