Re: [PATCH v9 19/21] stash: convert `stash--helper.c` into `stash.c`

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

 



On 09/26, Paul-Sebastian Ungureanu wrote:
> The old shell script `git-stash.sh`  was removed and replaced
> entirely by `builtin/stash.c`. In order to do that, `create` and
> `push` were adapted to work without `stash.sh`. For example, before
> this commit, `git stash create` called `git stash--helper create
> --message "$*"`. If it called `git stash--helper create "$@"`, then
> some of these changes wouldn't have been necessary.
> 
> This commit also removes the word `helper` since now stash is
> called directly and not by a shell script.
> 
> Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@xxxxxxxxx>
> ---
>  .gitignore                           |   1 -
>  Makefile                             |   3 +-
>  builtin.h                            |   2 +-
>  builtin/{stash--helper.c => stash.c} | 162 ++++++++++++++++-----------
>  git-stash.sh                         | 153 -------------------------
>  git.c                                |   2 +-
>  6 files changed, 98 insertions(+), 225 deletions(-)
>  rename builtin/{stash--helper.c => stash.c} (90%)
>  delete mode 100755 git-stash.sh
>
> [...]
>
> @@ -1571,7 +1562,44 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
>  		return !!push_stash(argc, argv, prefix);
>  	else if (!strcmp(argv[0], "save"))
>  		return !!save_stash(argc, argv, prefix);
> +	else if (*argv[0] != '-')
> +		usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
> +			      git_stash_usage, options);
> +
> +	if (strcmp(argv[0], "-p")) {
> +		while (++i < argc && strcmp(argv[i], "--")) {
> +			/*
> +			 * `akpqu` is a string which contains all short options,
> +			 * except `-m` which is verified separately.
> +			 */
> +			if ((strlen(argv[i]) == 2) && *argv[i] == '-' &&
> +			    strchr("akpqu", argv[i][1]))
> +				continue;
> +
> +			if (!strcmp(argv[i], "--all") ||
> +			    !strcmp(argv[i], "--keep-index") ||
> +			    !strcmp(argv[i], "--no-keep-index") ||
> +			    !strcmp(argv[i], "--patch") ||
> +			    !strcmp(argv[i], "--quiet") ||
> +			    !strcmp(argv[i], "--include-untracked"))
> +				continue;
> +
> +			/*
> +			 * `-m` and `--message=` are verified separately because
> +			 * they need to be immediately followed by a string
> +			 * (i.e.`-m"foobar"` or `--message="foobar"`).
> +			 */
> +			if ((strlen(argv[i]) > 2 &&
> +			     !strncmp(argv[i], "-m", 2)) ||
> +			    (strlen(argv[i]) > 10 &&
> +			     !strncmp(argv[i], "--message=", 10)))

These 'strlen && !strncmp' calls could be replaced with
'starts_with()'.

> +				continue;
> +
> +			usage_with_options(git_stash_usage, options);
> +		}
> +	}

This is a bit more complex than what we used to have, which was just
"if it starts with a "-" it's an option", but I don't think it hurts
being more explicit here either.

>  
> -	usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
> -		      git_stash_helper_usage, options);
> +	argv_array_push(&args, "push");
> +	argv_array_pushv(&args, argv);
> +	return !!push_stash(args.argc, args.argv, prefix);
>  }



[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