Skip to content

Commit 27ec394

Browse files
committed
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 <[email protected]>
1 parent 8a09e6c commit 27ec394

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Documentation/technical/api-parse-options.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ There are some macros to easily define options:
176176
Introduce an option with date argument, see `approxidate()`.
177177
The timestamp is put into `int_var`.
178178

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+
179183
`OPT_CALLBACK(short, long, &var, arg_str, description, func_ptr)`::
180184
Introduce an option with argument.
181185
The argument will be fed into the function given by `func_ptr`

builtin/prune.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
132132
OPT__DRY_RUN(&show_only, N_("do not remove, show only")),
133133
OPT__VERBOSE(&verbose, N_("report pruned objects")),
134134
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>")),
137137
OPT_END()
138138
};
139139
char *s;

parse-options-cb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ int parse_opt_approxidate_cb(const struct option *opt, const char *arg,
3333
return 0;
3434
}
3535

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+
3642
int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
3743
int unset)
3844
{

parse-options.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ struct option {
140140
#define OPT_DATE(s, l, v, h) \
141141
{ OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \
142142
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 }
143146
#define OPT_CALLBACK(s, l, v, a, h, f) \
144147
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
145148
#define OPT_NUMBER_CALLBACK(v, h, f) \
@@ -215,6 +218,7 @@ extern int parse_options_concat(struct option *dst, size_t, struct option *src);
215218
/*----- some often used options -----*/
216219
extern int parse_opt_abbrev_cb(const struct option *, const char *, int);
217220
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);
218222
extern int parse_opt_color_flag_cb(const struct option *, const char *, int);
219223
extern int parse_opt_verbosity_cb(const struct option *, const char *, int);
220224
extern int parse_opt_with_commit(const struct option *, const char *, int);

0 commit comments

Comments
 (0)