Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]>
---
parse-options-cb.c | 8 ++++++++
parse-options.h | 4 ++++
revision.c | 10 ++++------
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/parse-options-cb.c b/parse-options-cb.c
index 6e2e8d6273..7cdbbf5f6d 100644
--- a/parse-options-cb.c
+++ b/parse-options-cb.c
@@ -39,6 +39,14 @@ int parse_opt_expiry_date_cb(const struct option *opt, const
char *arg,
return 0;
}
+int parse_opt_timestamp_cb(const struct option *opt,
+ const char *arg, int unset)
+{
+ BUG_ON_OPT_NEG(unset);
+ *(timestamp_t *)opt->value = atoi(arg);
+ return 0;
+}
+
int parse_opt_color_flag_cb(const struct option *opt, const char *arg,
int unset)
{
diff --git a/parse-options.h b/parse-options.h
index cc9230adac..7637864c41 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -168,6 +168,9 @@ struct option {
#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_TIMESTAMP(s, l, v, h) \
+ { OPTION_CALLBACK, (s), (l), (v), N_("timestamp"),(h), \
+ PARSE_OPT_NONEG, parse_opt_timestamp_cb }
#define OPT_CALLBACK(s, l, v, a, h, f) OPT_CALLBACK_F(s, l, v, a, h, 0, f)
#define OPT_NUMBER_CALLBACK(v, h, f) \
{ OPTION_NUMBER, 0, NULL, (v), NULL, (h), \
@@ -275,6 +278,7 @@ struct option *parse_options_concat(struct option *a,
struct option *b);
/*----- some often used options -----*/
int parse_opt_abbrev_cb(const struct option *, const char *, int);
int parse_opt_expiry_date_cb(const struct option *, const char *, int);
+int parse_opt_timestamp_cb(const struct option *, const char *, int);
int parse_opt_color_flag_cb(const struct option *, const char *, int);
int parse_opt_verbosity_cb(const struct option *, const char *, int);
int parse_opt_object_name(const struct option *, const char *, int);
diff --git a/revision.c b/revision.c
index 42d466cd08..0c28b67978 100644
--- a/revision.c
+++ b/revision.c
@@ -1999,6 +1999,10 @@ static void make_rev_options(struct rev_info *revs)
OPT_INTEGER_F(0, "skip", &revs->skip_count,
N_("skip a number of commits before starting to
show"),
PARSE_OPT_NONEG),
+ OPT_TIMESTAMP(0, "min-age", &revs->min_age,
+ N_("limit the commits output to a specified time
range")),
+ OPT_TIMESTAMP(0, "max-age", &revs->max_age,
+ N_("limit the commits output to a specified time
range")),
OPT_END(),
};
revs->options = parse_options_concat(options, revs->diffopt.parseopts);
@@ -2045,18 +2049,12 @@ static int handle_revision_opt(struct rev_info *revs,
int argc, const char **arg
revs->max_count < 0)
die("'%s': not a non-negative integer", arg + 1);
revs->no_walk = 0;
- } else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
- revs->max_age = atoi(optarg);
- return argcount;
} else if ((argcount = parse_long_opt("since", argv, &optarg))) {
revs->max_age = approxidate(optarg);
return argcount;
} else if ((argcount = parse_long_opt("after", argv, &optarg))) {
revs->max_age = approxidate(optarg);
return argcount;
- } else if ((argcount = parse_long_opt("min-age", argv, &optarg))) {
- revs->min_age = atoi(optarg);
- return argcount;
} else if ((argcount = parse_long_opt("before", argv, &optarg))) {
revs->min_age = approxidate(optarg);
return argcount;
--
2.21.0.1141.gd54ac2cb17