parse-options: drop OPT_DATE()
There are no users of OPT_DATE except for test-parse-options; its only caller went away in 27ec394a97 (prune: introduce OPT_EXPIRY_DATE() and use it, 2013-04-25). It also has a bug: it does not specify PARSE_OPT_NONEG, but its callback does not respect the "unset" flag, and will feed NULL to approxidate() and segfault. Probably this should be marked with NONEG, or the callback should set the timestamp to some sentinel value (e.g,. "0", or "(time_t)-1"). But since there are no callers, deleting it means we don't even have to think about what the right behavior should be. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Nov 5, 2018 at 01:44 UTC
0a8a16ade6b3a55114cd0f28e5e71c2a3483d825
5 files changed
-38
Documentation/technical/api-parse-options.txt
-4
@@ -183,10 +183,6 @@ There are some macros to easily define options:
183
scale the provided value by 1024, 1024^2 or 1024^3 respectively.
184
The scaled value is put into `unsigned_long_var`.
185
186
-`OPT_DATE(short, long, ×tamp_t_var, description)`::
187
- Introduce an option with date argument, see `approxidate()`.
188
- The timestamp is put into `timestamp_t_var`.
189
-
186
`OPT_EXPIRY_DATE(short, long, ×tamp_t_var, description)`::
187
Introduce an option with expiry date argument, see `parse_expiry_date()`.
188
The timestamp is put into `timestamp_t_var`.
parse-options-cb.c
-7
@@ -28,13 +28,6 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
28
return 0;
29
}
30
31
-int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
32
- int unset)
33
-{
34
- *(timestamp_t *)(opt->value) = approxidate(arg);
35
- return 0;
36
-}
37
-
31
int parse_opt_expiry_date_cb(const struct option *opt, const char *arg,
32
int unset)
33
{
parse-options.h
-4
@@ -150,9 +150,6 @@ struct option {
150
(h), 0, &parse_opt_string_list }
151
#define OPT_UYN(s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \
152
(h), PARSE_OPT_NOARG, &parse_opt_tertiary }
153
-#define OPT_DATE(s, l, v, h) \
154
- { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \
155
- parse_opt_approxidate_cb }
153
#define OPT_EXPIRY_DATE(s, l, v, h) \
154
{ OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0, \
155
parse_opt_expiry_date_cb }
@@ -232,7 +229,6 @@ extern struct option *parse_options_concat(struct option *a, struct option *b);
229
230
/*----- some often used options -----*/
231
extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
235
-extern int parse_opt_approxidate_cb(const struct option *, const char *, int);
232
extern int parse_opt_expiry_date_cb(const struct option *, const char *, int);
233
extern int parse_opt_color_flag_cb(const struct option *, const char *, int);
234
extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
t/helper/test-parse-options.c
-1
@@ -119,7 +119,6 @@ int cmd__parse_options(int argc, const char **argv)
119
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
120
OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
121
OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
122
- OPT_DATE('t', NULL, ×tamp, "get timestamp of <time>"),
122
OPT_CALLBACK('L', "length", &integer, "str",
123
"get length of <str>", length_callback),
124
OPT_FILENAME('F', "file", &file, "set file to <file>"),
t/t0040-parse-options.sh
-22
@@ -23,7 +23,6 @@ usage: test-tool parse-options <options>
23
-j <n> get a integer, too
24
-m, --magnitude <n> get a magnitude
25
--set23 set integer to 23
26
- -t <time> get timestamp of <time>
26
-L, --length <str> get length of <str>
27
-F, --file <file> set file to <file>
28
@@ -245,27 +244,6 @@ test_expect_success 'keep some options as arguments' '
244
test-tool parse-options --expect="arg 00: --quux" --quux
245
'
246
248
-cat >expect <<\EOF
249
-boolean: 0
250
-integer: 0
251
-magnitude: 0
252
-timestamp: 1
253
-string: (not set)
254
-abbrev: 7
255
-verbose: -1
256
-quiet: 1
257
-dry run: no
258
-file: (not set)
259
-arg 00: foo
260
-EOF
261
-
262
-test_expect_success 'OPT_DATE() works' '
263
- test-tool parse-options -t "1970-01-01 00:00:01 +0000" \
264
- foo -q >output 2>output.err &&
265
- test_must_be_empty output.err &&
266
- test_cmp expect output
267
-'
268
-
247
cat >expect <<\EOF
248
Callback: "four", 0
249
boolean: 5