Re: [PATCH 2/2] Add revision range support on "-" and "@{-1}"

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

 



Kenny Lee Sin Cheong <kenny.lee28@xxxxxxxxx> writes:

> diff --git a/revision.c b/revision.c
> index 7778bbd..a79b443 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -1490,6 +1490,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
>  		int symmetric = *next == '.';
>  		unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM);
>  		static const char head_by_default[] = "HEAD";
> +		static const char prev_rev[] = "@{-1}";
>  		unsigned int a_flags;
>  
>  		*dotdot = 0;
> @@ -1499,6 +1500,13 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
>  			next = head_by_default;
>  		if (dotdot == arg)
>  			this = head_by_default;
> +		/*  Allows -..<rev> and <rev>..- */
> +		if (!strcmp(this, "-")) {
> +			this = prev_rev;
> +		}
> +		if (!strcmp(next, "-")) {
> +			next = prev_rev;
> +		}

The above two hunks are disappointing.  "this" and "next" are passed
to get_sha1_committish() and the point of the [1/2] patch was to
allow "-" to be just as usable as "@{-1}" anywhere a branch name can
be used.

>  		if (this == head_by_default && next == head_by_default &&
>  		    !symmetric) {
>  			/*
> @@ -2198,7 +2206,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
>  	read_from_stdin = 0;
>  	for (left = i = 1; i < argc; i++) {
>  		const char *arg = argv[i];
> -		if (arg[0] == '-' && arg[1]) {
> +		if (arg[0] == '-' && !strstr(arg, "..")) {

Isn't this way too loose?  "--some-opt=I.wish..." would have ".."
in it, and we would want to leave room to add new options that may
take arbitrary string as an argument.

I would have expected it would be more like

		if (arg[0] == '-' && arg[1] && !starts_with(arg + 1, "..")) {

That is, "anything that begins with '-', if it is to be taken as an
option, must not begin with '-..'", which I think should be strict
enough.

> @@ -2220,6 +2228,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
>  				continue;
>  			}
>  
> +
>  			opts = handle_revision_opt(revs, argc - i, argv + i, &left, argv);
>  			if (opts > 0) {
>  				i += opts - 1;

Noise.

> @@ -2229,7 +2238,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
>  				exit(128);
>  			continue;
>  		}
> -
> +		if (strstr(arg, "..")) {
> +			handle_revision_arg(arg, revs, flags, revarg_opt);
> +			continue;
> +		}

What is this for?  We will call handle_revision_arg() whether arg
has ".." or not immediately after this one.

>  		if (handle_revision_arg(arg, revs, flags, revarg_opt)) {
>  			int j;
--
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]