All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Keeping <john@keeping.me.uk>
To: Duy Nguyen <pclouds@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
	Jens Lehmann <Jens.Lehmann@web.de>
Subject: Re: [PATCH 2/2] rm: re-use parse_pathspec's trailing-slash removal
Date: Wed, 11 Sep 2013 09:24:41 +0100	[thread overview]
Message-ID: <20130911082441.GS2582@serenity.lan> (raw)
In-Reply-To: <CACsJy8Dw+RJor-XfjFQC5U5Pt39TZ656fEnkFxpDnx=kTqvADQ@mail.gmail.com>

On Wed, Sep 11, 2013 at 02:48:51PM +0700, Duy Nguyen wrote:
> On Wed, Sep 11, 2013 at 2:13 AM, John Keeping <john@keeping.me.uk> wrote:
> > 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.

Providing that there's only one trailing slash, the user-visible effect
should be the same since the only case affected by that is submodules.
In fact _CHEAP does better in the case where the submodule does not
exist in the working tree.

> 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.

Sounds good, I'll try to look at that tonight.

> > +                      prefix, argv);
> >         refresh_index(&the_index, REFRESH_QUIET, &pathspec, NULL, NULL);
> >
> >         seen = xcalloc(pathspec.nr, 1);

  reply	other threads:[~2013-09-11  8:24 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10 19:13 [PATCH 0/2] reset: handle submodule with trailing slash John Keeping
2013-09-10 19:13 ` [PATCH 1/2] " John Keeping
2013-09-10 19:37   ` Jens Lehmann
2013-09-10 19:46     ` John Keeping
2013-09-11  6:05   ` Johannes Sixt
2013-09-11  8:20     ` John Keeping
2013-09-11 10:54       ` Duy Nguyen
2013-09-11 11:08         ` John Keeping
2013-09-11 11:20           ` Duy Nguyen
2013-09-11 17:08         ` Junio C Hamano
2013-09-11 17:27           ` John Keeping
2013-09-11 18:14             ` Junio C Hamano
2013-09-11 18:22               ` John Keeping
2013-09-11 18:45                 ` Junio C Hamano
2013-09-10 19:13 ` [PATCH 2/2] rm: re-use parse_pathspec's trailing-slash removal John Keeping
2013-09-11  7:48   ` Duy Nguyen
2013-09-11  8:24     ` John Keeping [this message]
2013-09-12 19:24 ` [PATCH v2 0/4] submodule trailing slash improvements John Keeping
2013-09-12 19:24   ` [PATCH v2 1/4] pathspec: use is_dir_sep() to check for trailing slashes John Keeping
2013-09-12 20:17     ` Johannes Sixt
2013-09-12 19:24   ` [PATCH v2 2/4] pathspec: strip multiple trailing slashes from submodules John Keeping
2013-09-12 19:48     ` Junio C Hamano
2013-09-12 20:21       ` John Keeping
2013-09-13  1:28         ` Duy Nguyen
2013-09-13  8:48           ` John Keeping
2013-09-12 19:25   ` [PATCH v2 3/4] rm: re-use parse_pathspec's trailing-slash removal John Keeping
2013-09-12 19:25   ` [PATCH v2 4/4] reset: handle submodule with trailing slash John Keeping

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130911082441.GS2582@serenity.lan \
    --to=john@keeping.me.uk \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.