[PATCH 05/11] revert: Catch incompatible command-line options early

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

 



Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx>
---
 builtin/revert.c |   36 +++++++++++++++++++++++++-----------
 1 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/builtin/revert.c b/builtin/revert.c
index 9381541..facae24 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -77,6 +77,24 @@ static int option_parse_x(const struct option *opt,
 	return 0;
 }
 
+static void die_opt_incompatible(const char *me, const char *base_opt,
+				int nargs, int opt_bitarray[], ...)
+{
+	const char *this_opt = NULL;
+	va_list ap;
+	int i;
+
+	va_start(ap, opt_bitarray);
+	for (i = 0; i < nargs; i ++) {
+		this_opt = va_arg(ap, const char *);
+		if (opt_bitarray[i]) {
+			die(_("%s: %s cannot be used with %s"),
+				me, this_opt, base_opt);
+		}
+	}
+	va_end(ap);
+}
+
 static void parse_args(int argc, const char **argv)
 {
 	const char * const * usage_str = revert_or_cherry_pick_usage();
@@ -112,6 +130,13 @@ static void parse_args(int argc, const char **argv)
 	if (cmd_opts.commit_argc < 2)
 		usage_with_options(usage_str, options);
 
+	if (cmd_opts.allow_ff) {
+		int opt_bitarray[] = {cmd_opts.signoff, cmd_opts.no_commit,
+				      cmd_opts.no_replay, cmd_opts.edit};
+		die_opt_incompatible(me, "--ff", 4, opt_bitarray, "--signoff",
+				"--no-commit", "-x", "--edit");
+	}
+
 	cmd_opts.commit_argv = argv;
 }
 
@@ -584,17 +609,6 @@ static int pick_commits(void)
 	struct commit *commit;
 	int res;
 
-	if (cmd_opts.allow_ff) {
-		if (cmd_opts.signoff)
-			die(_("cherry-pick --ff cannot be used with --signoff"));
-		if (cmd_opts.no_commit)
-			die(_("cherry-pick --ff cannot be used with --no-commit"));
-		if (cmd_opts.no_replay)
-			die(_("cherry-pick --ff cannot be used with -x"));
-		if (cmd_opts.edit)
-			die(_("cherry-pick --ff cannot be used with --edit"));
-	}
-
 	if ((res = read_and_refresh_cache()) ||
 		(res = prepare_revs(&revs)))
 		return res;
-- 
1.7.4.rc1.7.g2cf08.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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]