Skip to content

Commit 0a8a16a

Browse files
peffgitster
authored andcommitted
parse-options: drop OPT_DATE()
There are no users of OPT_DATE except for test-parse-options; its only caller went away in 27ec394 (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>
1 parent 735ca20 commit 0a8a16a

File tree

5 files changed

+0
-38
lines changed

5 files changed

+0
-38
lines changed

Documentation/technical/api-parse-options.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ There are some macros to easily define options:
183183
scale the provided value by 1024, 1024^2 or 1024^3 respectively.
184184
The scaled value is put into `unsigned_long_var`.
185185

186-
`OPT_DATE(short, long, &timestamp_t_var, description)`::
187-
Introduce an option with date argument, see `approxidate()`.
188-
The timestamp is put into `timestamp_t_var`.
189-
190186
`OPT_EXPIRY_DATE(short, long, &timestamp_t_var, description)`::
191187
Introduce an option with expiry date argument, see `parse_expiry_date()`.
192188
The timestamp is put into `timestamp_t_var`.

parse-options-cb.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset)
2828
return 0;
2929
}
3030

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-
3831
int parse_opt_expiry_date_cb(const struct option *opt, const char *arg,
3932
int unset)
4033
{

parse-options.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ struct option {
150150
(h), 0, &parse_opt_string_list }
151151
#define OPT_UYN(s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \
152152
(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 }
156153
#define OPT_EXPIRY_DATE(s, l, v, h) \
157154
{ OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0, \
158155
parse_opt_expiry_date_cb }
@@ -232,7 +229,6 @@ extern struct option *parse_options_concat(struct option *a, struct option *b);
232229

233230
/*----- some often used options -----*/
234231
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);
236232
extern int parse_opt_expiry_date_cb(const struct option *, const char *, int);
237233
extern int parse_opt_color_flag_cb(const struct option *, const char *, int);
238234
extern int parse_opt_verbosity_cb(const struct option *, const char *, int);

t/helper/test-parse-options.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ int cmd__parse_options(int argc, const char **argv)
119119
OPT_INTEGER('j', NULL, &integer, "get a integer, too"),
120120
OPT_MAGNITUDE('m', "magnitude", &magnitude, "get a magnitude"),
121121
OPT_SET_INT(0, "set23", &integer, "set integer to 23", 23),
122-
OPT_DATE('t', NULL, &timestamp, "get timestamp of <time>"),
123122
OPT_CALLBACK('L', "length", &integer, "str",
124123
"get length of <str>", length_callback),
125124
OPT_FILENAME('F', "file", &file, "set file to <file>"),

t/t0040-parse-options.sh

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ usage: test-tool parse-options <options>
2323
-j <n> get a integer, too
2424
-m, --magnitude <n> get a magnitude
2525
--set23 set integer to 23
26-
-t <time> get timestamp of <time>
2726
-L, --length <str> get length of <str>
2827
-F, --file <file> set file to <file>
2928
@@ -245,27 +244,6 @@ test_expect_success 'keep some options as arguments' '
245244
test-tool parse-options --expect="arg 00: --quux" --quux
246245
'
247246

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-
269247
cat >expect <<\EOF
270248
Callback: "four", 0
271249
boolean: 5

0 commit comments

Comments
 (0)