[PATCH 14/19] rev-parseopt: convert --no-walk and --do-walk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 revision.c | 47 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 30 insertions(+), 17 deletions(-)

diff --git a/revision.c b/revision.c
index b02cb4660b..f04eb7f140 100644
--- a/revision.c
+++ b/revision.c
@@ -2464,6 +2464,29 @@ static int rev_opt_glob(const struct option *opt,
 	return 0;
 }
 
+static int rev_opt_no_walk(const struct option *opt,
+			   const char *arg, int unset)
+{
+	struct rev_info *revs  = opt->value;
+
+	BUG_ON_OPT_NEG(unset);
+	if (!arg) {
+		revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
+	} else {
+		/*
+		 * Detached form ("--no-walk X" as opposed to "--no-walk=X")
+		 * not allowed, since the argument is optional.
+		 */
+		if (!strcmp(arg, "sorted"))
+			revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
+		else if (!strcmp(arg, "unsorted"))
+			revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED;
+		else
+			return error(_("invalid argument to --no-walk"));
+	}
+	return 0;
+}
+
 static int rev_opt_not(const struct option *opt,
 		       const char *arg, int unset)
 {
@@ -2572,6 +2595,12 @@ static void make_pseudo_options(struct rev_info *revs)
 		OPT_REV_NOARG(0, "not",
 			      N_("reverse the meaning of '^' for all following revisions"),
 			      rev_opt_not),
+		OPT_REV_OPTARG(0, "no-walk", N_("(sorted|unsorted)"),
+			       N_("only show given commits but do not traverse their ancestors"),
+			       rev_opt_no_walk),
+		OPT_SET_INT_F(0, "do-walk", &revs->no_walk,
+			      N_("override a previous --no-walk"),
+			      0, PARSE_OPT_NONEG),
 		OPT_END()
 	};
 	ALLOC_ARRAY(revs->pseudo_options, ARRAY_SIZE(options));
@@ -2583,7 +2612,6 @@ static int handle_revision_pseudo_opt(const char *submodule,
 				int argc, const char **argv, int *flags)
 {
 	const char *arg = argv[0];
-	const char *optarg;
 	struct ref_store *refs;
 
 	if (submodule) {
@@ -2611,22 +2639,7 @@ static int handle_revision_pseudo_opt(const char *submodule,
 	if (argc)
 		return argc;
 
-	if (!strcmp(arg, "--no-walk")) {
-		revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
-	} else if (skip_prefix(arg, "--no-walk=", &optarg)) {
-		/*
-		 * Detached form ("--no-walk X" as opposed to "--no-walk=X")
-		 * not allowed, since the argument is optional.
-		 */
-		if (!strcmp(optarg, "sorted"))
-			revs->no_walk = REVISION_WALK_NO_WALK_SORTED;
-		else if (!strcmp(optarg, "unsorted"))
-			revs->no_walk = REVISION_WALK_NO_WALK_UNSORTED;
-		else
-			return error("invalid argument to --no-walk");
-	} else if (!strcmp(arg, "--do-walk")) {
-		revs->no_walk = 0;
-	} else if (!strcmp(arg, "--single-worktree")) {
+	if (!strcmp(arg, "--single-worktree")) {
 		revs->single_worktree = 1;
 	} else {
 		return 0;
-- 
2.21.0.1141.gd54ac2cb17




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux