提交 27ec394a 编写于 作者: J Junio C Hamano

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: NJunio C Hamano <gitster@pobox.com>
上级 8a09e6c5
...@@ -176,6 +176,10 @@ There are some macros to easily define options: ...@@ -176,6 +176,10 @@ There are some macros to easily define options:
Introduce an option with date argument, see `approxidate()`. Introduce an option with date argument, see `approxidate()`.
The timestamp is put into `int_var`. The timestamp is put into `int_var`.
`OPT_EXPIRY_DATE(short, long, &int_var, description)`::
Introduce an option with expiry date argument, see `parse_expiry_date()`.
The timestamp is put into `int_var`.
`OPT_CALLBACK(short, long, &var, arg_str, description, func_ptr)`:: `OPT_CALLBACK(short, long, &var, arg_str, description, func_ptr)`::
Introduce an option with argument. Introduce an option with argument.
The argument will be fed into the function given by `func_ptr` The argument will be fed into the function given by `func_ptr`
......
...@@ -132,8 +132,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix) ...@@ -132,8 +132,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
OPT__DRY_RUN(&show_only, N_("do not remove, show only")), OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
OPT__VERBOSE(&verbose, N_("report pruned objects")), OPT__VERBOSE(&verbose, N_("report pruned objects")),
OPT_BOOL(0, "progress", &show_progress, N_("show progress")), OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
OPT_DATE(0, "expire", &expire, OPT_EXPIRY_DATE(0, "expire", &expire,
N_("expire objects older than <time>")), N_("expire objects older than <time>")),
OPT_END() OPT_END()
}; };
char *s; char *s;
......
...@@ -33,6 +33,12 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg, ...@@ -33,6 +33,12 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
return 0; return 0;
} }
int parse_opt_expiry_date_cb(const struct option *opt, const char *arg,
int unset)
{
return parse_expiry_date(arg, (unsigned long *)opt->value);
}
int parse_opt_color_flag_cb(const struct option *opt, const char *arg, int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
int unset) int unset)
{ {
......
...@@ -140,6 +140,9 @@ struct option { ...@@ -140,6 +140,9 @@ struct option {
#define OPT_DATE(s, l, v, h) \ #define OPT_DATE(s, l, v, h) \
{ OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \ { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \
parse_opt_approxidate_cb } parse_opt_approxidate_cb }
#define OPT_EXPIRY_DATE(s, l, v, h) \
{ OPTION_CALLBACK, (s), (l), (v), N_("expiry date"),(h), 0, \
parse_opt_expiry_date_cb }
#define OPT_CALLBACK(s, l, v, a, h, f) \ #define OPT_CALLBACK(s, l, v, a, h, f) \
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) } { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
#define OPT_NUMBER_CALLBACK(v, h, f) \ #define OPT_NUMBER_CALLBACK(v, h, f) \
...@@ -215,6 +218,7 @@ extern int parse_options_concat(struct option *dst, size_t, struct option *src); ...@@ -215,6 +218,7 @@ extern int parse_options_concat(struct option *dst, size_t, struct option *src);
/*----- some often used options -----*/ /*----- some often used options -----*/
extern int parse_opt_abbrev_cb(const struct option *, const char *, int); extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
extern int parse_opt_approxidate_cb(const struct option *, const char *, int); extern int parse_opt_approxidate_cb(const struct option *, const char *, int);
extern int parse_opt_expiry_date_cb(const struct option *, const char *, int);
extern int parse_opt_color_flag_cb(const struct option *, const char *, int); extern int parse_opt_color_flag_cb(const struct option *, const char *, int);
extern int parse_opt_verbosity_cb(const struct option *, const char *, int); extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
extern int parse_opt_with_commit(const struct option *, const char *, int); extern int parse_opt_with_commit(const struct option *, const char *, int);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册