Re: [PATCH 1/5] parse_branchname_arg(): fix dash_dash_pos, drop argcount

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

 



"Alexandr Miloslavskiy via GitGitGadget" <gitgitgadget@xxxxxxxxx>
writes:

> From: Alexandr Miloslavskiy <alexandr.miloslavskiy@xxxxxxxxxxx>
>
> `dash_dash_pos` was only calculated under `opts->accept_pathspec`. This
> is unexpected to readers and made it harder to reason about the code.
> Fix this by restoring the expected meaning.

Perhaps.  I think the original reasoning was to compute only where
dash_dash_pos will be needed, but the code changes over time, and
places that need the value of dash_dash_pos would change over time,
so from that point of view, I think it makes sense to make sure it
gets always computed like this patch does.

> Simplify the code by dropping `argcount` and useless `argc` / `argv`
> manipulations.

I am not sure if this is a good change, though.  It goes against the
reasoning that makes the above "dash-dash-pos" change is a good one,
doesn't it?  When the code changes over time, wouldn't it make the
code more clear to keep track of the count of args it saw in a
separate variable, than relying on the invariant that currently
happens to hold which is "if dash-dash is after the first argument,
return 2 and otherwise return 1"?

> @@ -1121,7 +1121,6 @@ static int parse_branchname_arg(int argc, const char **argv,
>  				int *dwim_remotes_matched)
>  {
>  	const char **new_branch = &opts->new_branch;
> -	int argcount = 0;
>  	const char *arg;
>  	int dash_dash_pos;
>  	int has_dash_dash = 0;
> @@ -1180,17 +1179,21 @@ static int parse_branchname_arg(int argc, const char **argv,
>  	arg = argv[0];
>  	dash_dash_pos = -1;
>  	for (i = 0; i < argc; i++) {
> -		if (opts->accept_pathspec && !strcmp(argv[i], "--")) {
> +		if (!strcmp(argv[i], "--")) {
>  			dash_dash_pos = i;
>  			break;
>  		}
>  	}
> -	if (dash_dash_pos == 0)
> -		return 1; /* case (2) */
> -	else if (dash_dash_pos == 1)
> -		has_dash_dash = 1; /* case (3) or (1) */
> -	else if (dash_dash_pos >= 2)
> -		die(_("only one reference expected, %d given."), dash_dash_pos);
> +
> +	if (opts->accept_pathspec) {
> +	    if (dash_dash_pos == 0)
> +		    return 1; /* case (2) */
> +	    else if (dash_dash_pos == 1)
> +		    has_dash_dash = 1; /* case (3) or (1) */
> +	    else if (dash_dash_pos >= 2)
> +		    die(_("only one reference expected, %d given."), dash_dash_pos);

Non-standard indentation?  In our code, a level of indent is another
horizontal tab.

> +	}



[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