[PATCH v3 14/18] parse_branchname_arg(): simplify argument eating

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

 



From: Alexandr Miloslavskiy <alexandr.miloslavskiy@xxxxxxxxxxx>

This patch abolishes two pieces of obfuscated code.

First is `if (argc)` condition, which in fact means "more then one arg"
due to `argc++` above.

Second is by far harder to grasp:
    if (!arg0_cant_be_pathspec) {...} else if (opts->accept_pathspec)
that is,
	if (opts->accept_pathspec && arg0_cant_be_pathspec)
which (quite unexpectedly) actually means
    if (opts->accept_pathspec && dash_dash_pos == 1)
and aims to "eat" that `--`.

Make both pieces easier to read by rewriting obfuscated conditions.

With both solved, I could keep argcount++/argv++/argc-- in the very end
of the function, but that was obviously useless code in this case, so I
deleted them as well.

This patch is not expected to change behavior in any way.

Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@xxxxxxxxxxx>
---
 builtin/checkout.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 9144770b21..63f4bb4da6 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1152,7 +1152,6 @@ static int parse_branchname_arg(int argc, const char **argv,
 				struct object_id *rev)
 {
 	const char **new_branch = &opts->new_branch;
-	int argcount = 0;
 	const char *arg;
 	int dash_dash_pos;
 	int arg0_cant_be_pathspec = 0;
@@ -1272,15 +1271,10 @@ static int parse_branchname_arg(int argc, const char **argv,
 		if (!recover_with_dwim) {
 			if (arg0_cant_be_pathspec)
 				die(_("invalid reference: %s"), arg);
-			return argcount;
+			return 0;
 		}
 	}
 
-	/* we can't end up being in (2) anymore, eat the argument */
-	argcount++;
-	argv++;
-	argc--;
-
 	setup_new_branch_info_and_source_tree(new_branch_info, opts, rev, arg);
 
 	if (!opts->source_tree)                   /* case (1): want a tree */
@@ -1293,15 +1287,11 @@ static int parse_branchname_arg(int argc, const char **argv,
 		 * even if there happen to be a file called 'branch';
 		 * it would be extremely annoying.
 		 */
-		if (argc)
+		if (argc > 1)
 			verify_non_filename(opts->prefix, arg);
-	} else if (opts->accept_pathspec) {
-		argcount++;
-		argv++;
-		argc--;
 	}
 
-	return argcount;
+	return (opts->accept_pathspec && dash_dash_pos == 1) ? 2 : 1;
 }
 
 static int switch_unborn_to_new_branch(const struct checkout_opts *opts)
-- 
gitgitgadget




[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