prune: introduce OPT_EXPIRY_DATE() and use it

Earlier we added support for --expire=all (or --expire=now) that considers all crufts, regardless of their age, as eligible for garbage collection by turning command argument parsers that use approxidate() to use parse_expiry_date(), but "git prune" used a built-in parse-options facility OPT_DATE() and did not benefit from the new function. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Apr 25, 2013 at 11:13 UTC 27ec394a9701675762f02e9af464be2c297c6cf1
4 files changed +16 -2
Documentation/technical/api-parse-options.txt
+4
@@ -176,6 +176,10 @@ There are some macros to easily define options:
176 Introduce an option with date argument, see `approxidate()`.
177 The timestamp is put into `int_var`.
178
179 +`OPT_EXPIRY_DATE(short, long, &int_var, description)`::
180 + Introduce an option with expiry date argument, see `parse_expiry_date()`.
181 + The timestamp is put into `int_var`.
182 +
183 `OPT_CALLBACK(short, long, &var, arg_str, description, func_ptr)`::
184 Introduce an option with argument.
185 The argument will be fed into the function given by `func_ptr`
builtin/prune.c
+2 -2
@@ -132,8 +132,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
132 OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
133 OPT__VERBOSE(&verbose, N_("report pruned objects")),
134 OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
135 - OPT_DATE(0, "expire", &expire,
136 - N_("expire objects older than <time>")),
135 + OPT_EXPIRY_DATE(0, "expire", &expire,
136 + N_("expire objects older than <time>")),
137 OPT_END()
138 };
139 char *s;
parse-options-cb.c
+6
@@ -33,6 +33,12 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
33 return 0;
34 }
35
36 +int parse_opt_expiry_date_cb(const struct option *opt, const char *arg,
37 + int unset)
38 +{
39 + return parse_expiry_date(arg, (unsigned long *)opt->value);
40 +}
41 +
42 int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
43 int unset)
44 {
parse-options.h
+4
@@ -140,6 +140,9 @@ struct option {
140 #define OPT_DATE(s, l, v, h) \
141 { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \
142 parse_opt_approxidate_cb }
143 +#define OPT_EXPIRY_DATE(s, l, v, h) \
144 + { OPTION_CALLBACK, (s), (l), (v), N_("expiry date"),(h), 0, \
145 + parse_opt_expiry_date_cb }
146 #define OPT_CALLBACK(s, l, v, a, h, f) \
147 { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
148 #define OPT_NUMBER_CALLBACK(v, h, f) \
@@ -215,6 +218,7 @@ extern int parse_options_concat(struct option *dst, size_t, struct option *src);
218 /*----- some often used options -----*/
219 extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
220 extern int parse_opt_approxidate_cb(const struct option *, const char *, int);
221 +extern int parse_opt_expiry_date_cb(const struct option *, const char *, int);
222 extern int parse_opt_color_flag_cb(const struct option *, const char *, int);
223 extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
224 extern int parse_opt_with_commit(const struct option *, const char *, int);