diff mbox series

[17/19] rev-parseopt: convert --max-count

Message ID 20190508111249.15262-18-pclouds@gmail.com (mailing list archive)
State New, archived
Headers show
Series Convert revision.c to parseopt part 1/4 | expand

Commit Message

Duy Nguyen May 8, 2019, 11:12 a.m. UTC
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 revision.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/revision.c b/revision.c
index f15aa3e62d..c53347d362 100644
--- a/revision.c
+++ b/revision.c
@@ -1976,12 +1976,26 @@  static int rev_opt_abbrev(const struct option *opt,
 	return 0;
 }
 
+static int rev_opt_max_count(const struct option *opt,
+			     const char *arg, int unset)
+{
+	struct rev_info *revs  = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	revs->max_count = atoi(arg);
+	revs->no_walk = 0;
+	return 0;
+}
+
 static void make_rev_options(struct rev_info *revs)
 {
 	struct option options[] = {
 		OPT_CALLBACK_F(0, "abbrev", revs, N_("n"),
 			       N_("show the given source prefix instead of \"a/\""),
 			       PARSE_OPT_OPTARG, rev_opt_abbrev),
+		OPT_REV('n', "max-count", N_("<n>"),
+			N_("limit the number of commis to stdout"),
+			rev_opt_max_count),
 		OPT_END(),
 	};
 	revs->options = parse_options_concat(options, revs->diffopt.parseopts);
@@ -2022,11 +2036,7 @@  static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 	if (argc)
 		return argc;
 
-	if ((argcount = parse_long_opt("max-count", argv, &optarg))) {
-		revs->max_count = atoi(optarg);
-		revs->no_walk = 0;
-		return argcount;
-	} else if ((argcount = parse_long_opt("skip", argv, &optarg))) {
+	if ((argcount = parse_long_opt("skip", argv, &optarg))) {
 		revs->skip_count = atoi(optarg);
 		return argcount;
 	} else if ((*arg == '-') && isdigit(arg[1])) {
@@ -2035,15 +2045,6 @@  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 (!strcmp(arg, "-n")) {
-		if (argc <= 1)
-			return error("-n requires an argument");
-		revs->max_count = atoi(argv[1]);
-		revs->no_walk = 0;
-		return 2;
-	} else if (skip_prefix(arg, "-n", &optarg)) {
-		revs->max_count = atoi(optarg);
-		revs->no_walk = 0;
 	} else if ((argcount = parse_long_opt("max-age", argv, &optarg))) {
 		revs->max_age = atoi(optarg);
 		return argcount;