Git fork

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>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
785c17df 8ff1a34b

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