From: John Keeping <john@keeping.me.uk>
To: Duy Nguyen <pclouds@gmail.com>
Cc: Johannes Sixt <j6t@kdbg.org>,
Git Mailing List <git@vger.kernel.org>,
Jens Lehmann <Jens.Lehmann@web.de>
Subject: Re: [PATCH 1/2] reset: handle submodule with trailing slash
Date: Wed, 11 Sep 2013 12:08:06 +0100 [thread overview]
Message-ID: <20130911110806.GT2582@serenity.lan> (raw)
In-Reply-To: <CACsJy8BgEM3eEDo8wOgkqYTL1fkh9azZNqbogxBubp9g5KRNbQ@mail.gmail.com>
On Wed, Sep 11, 2013 at 05:54:48PM +0700, Duy Nguyen wrote:
> On Wed, Sep 11, 2013 at 3:20 PM, John Keeping <john@keeping.me.uk> wrote:
> > On Wed, Sep 11, 2013 at 08:05:44AM +0200, Johannes Sixt wrote:
> >> Am 10.09.2013 21:13, schrieb John Keeping:
> >> > When using tab-completion, a directory path will often end with a
> >> > trailing slash which currently confuses "git rm" when dealing with
> >> > submodules. Now that we have parse_pathspec we can easily handle this
> >> > by simply adding the PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP flag.
> >> >
> >> > Signed-off-by: John Keeping <john@keeping.me.uk>
> >> > ---
> >> > builtin/reset.c | 5 +++++
> >> > t/t7400-submodule-basic.sh | 6 ++++--
> >> > 2 files changed, 9 insertions(+), 2 deletions(-)
> >> >
> >> > diff --git a/builtin/reset.c b/builtin/reset.c
> >> > index 5e4c551..9efac0f 100644
> >> > --- a/builtin/reset.c
> >> > +++ b/builtin/reset.c
> >> > @@ -220,8 +220,13 @@ static void parse_args(struct pathspec *pathspec,
> >> > }
> >> > }
> >> > *rev_ret = rev;
> >> > +
> >> > + if (read_cache() < 0)
> >> > + die(_("index file corrupt"));
> >>
> >> When the index is now read here, I would have expected hunk in this
> >> patch that removes a read_cache() invocation.
> >
> > I think that needs to look like this on top - there's also a
> > read_cache_unmerged() around line 68 but I don't think we can remove
> > that one.
> >
> > -- >8 --
> > diff --git a/builtin/reset.c b/builtin/reset.c
> > index 9efac0f..800117f 100644
> > --- a/builtin/reset.c
> > +++ b/builtin/reset.c
> > @@ -143,7 +143,6 @@ static int read_from_tree(const struct pathspec *pathspec,
> > opt.output_format = DIFF_FORMAT_CALLBACK;
> > opt.format_callback = update_index_from_diff;
> >
> > - read_cache();
> > if (do_diff_cache(tree_sha1, &opt))
> > return 1;
> > diffcore_std(&opt);
> > @@ -169,7 +168,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,
> >
> > static void die_if_unmerged_cache(int reset_type)
> > {
> > - if (is_merge() || read_cache() < 0 || unmerged_cache())
> > + if (is_merge() || unmerged_cache())
> > die(_("Cannot do a %s reset in the middle of a merge."),
> > _(reset_type_names[reset_type]));
>
> reset --soft does not go through these code paths (i.e. it does not
> need index at all). If we fail to load index index in "reset --soft" I
> think it's ok to die(). Corrupt index is fatal anyway. But "reset
> --soft" now has to pay the cost to load index, which could be slow
> when the index is big. Assuming nobody does "reset --soft" that often
> I think this is OK.
>
> Alternatively we could load index lazily in _CHEAP code only when we
> see trailing slashes, then replace these read_cache() with
> read_cache_unless_its_already_loaded_earlier() or something.
read_cache() already has an early return if the index is already loaded
so I don't think we need to worry about a special function for that.
I'm not sure it's worth optimizing this case too heavily, but it might
be a nice change to make parse_pathspec() not rely on the index being
loaded before it is called with certain flags.
next prev parent reply other threads:[~2013-09-11 11:08 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 [this message]
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
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=20130911110806.GT2582@serenity.lan \
--to=john@keeping.me.uk \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).