Re: [PATCH 2/2] rm: re-use parse_pathspec's trailing-slash removal
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Sep 11, 2013, 07:48 UTC
- Message-ID
- <CACsJy8Dw+RJor-XfjFQC5U5Pt39TZ656fEnkFxpDnx=kTqvADQ@mail.gmail.com>
- In-Reply-To
- <b16901cdc3d433a8e0f7078475cb06f90b4590dd.1378840318.git.john@keeping.me.uk>
On Wed, Sep 11, 2013 at 2:13 AM, John Keeping <john@keeping.me.uk> wrote:
Show 36 quoted lines
> Instead of re-implementing the "remove trailing slashes" loop in
> builtin/rm.c just pass PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP to
> parse_pathspec.
>
> Signed-off-by: John Keeping <john@keeping.me.uk>
> ---
> builtin/rm.c | 20 ++++----------------
> 1 file changed, 4 insertions(+), 16 deletions(-)
>
> diff --git a/builtin/rm.c b/builtin/rm.c
> index 9b59ab3..3a0e0ea 100644
> --- a/builtin/rm.c
> +++ b/builtin/rm.c
> @@ -298,22 +298,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
> if (read_cache() < 0)
> die(_("index file corrupt"));
>
> - /*
> - * Drop trailing directory separators from directories so we'll find
> - * submodules in the index.
> - */
> - for (i = 0; i < argc; i++) {
> - size_t pathlen = strlen(argv[i]);
> - if (pathlen && is_dir_sep(argv[i][pathlen - 1]) &&
> - is_directory(argv[i])) {
> - do {
> - pathlen--;
> - } while (pathlen && is_dir_sep(argv[i][pathlen - 1]));
> - argv[i] = xmemdupz(argv[i], pathlen);
> - }
> - }
> -
> - parse_pathspec(&pathspec, 0, PATHSPEC_PREFER_CWD, prefix, argv);
> + parse_pathspec(&pathspec, 0,
> + PATHSPEC_PREFER_CWD |
> + PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,I notice that _CHEAP implementation and the removed code are not exactly the same. But I think they have the same purpose so it's probably ok even there are some subtle behavioral changes.
You may want to improve _CHEAP to remove consecutive trailing slashes (i.e. foo//// -> foo) too. And maybe is is_dir_sep() instead of explicit == '/' comparison in there.
> + prefix, argv); > refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL); > > seen = xcalloc(pathspec.nr, 1);
-- Duy