git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Per Cederqvist <cederp@opera.com>,
	Jens Lehmann <Jens.Lehmann@web.de>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
Date: Tue, 22 Mar 2016 12:30:13 -0700	[thread overview]
Message-ID: <CAGZ79kaMa3CyJ-Y9Xn9QShzTUGythos+pmKZXQ7m-2c0bF0u9A@mail.gmail.com> (raw)
In-Reply-To: <xmqqy49agx98.fsf@gitster.mtv.corp.google.com>

On Tue, Mar 22, 2016 at 11:53 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> In 74703a1e4d (2015-09-02, submodule: rewrite `module_list` shell
>> function in C), "submodule deinit ." was broken.
>>
>> The original module_list accepted '.' as a pathspec just fine, as it
>> was using
>>
>>   git ls-files -z --error-unmatch --stage -- "$@" || { custom filtering}
>>
>> and git ls-files doesn't make a difference between "." and no arguments
>> there. When using the parse_pathspec function in C, this is a difference
>> however, when no path matches.
>
> Is that an accurate description of the issue?
>
> The original (above) errors out if there is a pathspec that does not
> match any path in the index.  The C rewrite however instead does
> this:
>
>                 if (!S_ISGITLINK(ce->ce_mode) ||
>                     !match_pathspec(pathspec, ce->name, ce_namelen(ce),
>                                     0, ps_matched, 1))
>                         continue;
>
> to error out if there is a pathspec that does not match any
> submodule path.  That is the root cause of the difference in
> behaviour.
>
> So if we were to aim for a faithful rewrite, perhaps swapping the
> order of the check, i.e.
>
>                 if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
>                                     0, ps_matched, 1) ||
>                     !S_ISGITLINK(ce->ce_mode))
>                         continue;
>
> Now, arguably, the behaviour of C rewrite makes more sense in that
> it would diagnose a pathspec that does not match a submodule as an
> error, e.g.
>
>         $ git submodule--helper list 'COPYIN*'
>         error: pathspec 'COPYIN*' did not match any file(s) known to git.
>         #unmatched
>
> The error message _is_ wrong, but the end result is more helpful to
> the user---the user thought there was a submodule that would match
> that pathspec, and there isn't, so we suspect there was a typo and
> cautiously error out.
>
> "submodule deinit ." may have "worked" in the sense that you would
> have at least one path in your tree and avoided this "nothing
> matches" most of the time.  It would have still failed with the
> exactly same error if run in an empty repository, i.e.
>
>         $ E=/var/tmp/x/empty && rm -fr "$E" && mkdir -p "$E" && cd "$E"
>         $ git init
>         $ rungit v2.6.6 submodule deinit .
>         error: pathspec '.' did not match any file(s) known to git.
>         Did you forget to 'git add'?
>         $ >file && git add file
>         $ rungit v2.6.6 submodule deinit .
>         $ echo $?
>         0
>
> In other words, "Use '.' if you really want to" is a faulty
> suggestion.  There is no guarantee that it would match anything in
> the old world order, and certainly there is no guarantee that it
> would match any submodule in the new world order.
>
> When another person who is not Per Cederqvist realizes that the
> logic that issues the faulty suggestion is because the command wants
> some pathspec, she may try
>
>     $ git submodule deinit '*'
>
> and complain that it used to work but it no longer, even with the
> band-aid patch under discussion that special cases '.'.
>
> So I dunno.  This is not only "deinit", but also the post rewrite
> version catches
>
>         $ git submodule init -- 'COPYIN*'
>
> as an error, which we probably would want to keep, so I am reluctant
> to suggest swapping the order of the check to do pathspec first and
> then gitlink-ness (it has performance implications but correctness
> is a more important issue), but if we want to keep the backward
> compatibility, that would be the best bug-to-bug compatible fix in
> the shorter term.

So I have 2 goals in mind:
* Git suggested to use '.' explicitly, so it should just work --even
for a completely
  empty repository (see the test for it)
* Eventually -- not in this patch, but a later patch targeted at
master -- we want to
  remove the recommendation to use '.', and allow no arguments or a
different argument
  for "all submodules". git add uses '.' for it though, so '.' seems
right and valid.
  git add '*' is also valid.

Maybe combine the second idea with a slight refactoring of
parse_pathspec, such that you
can pass a callback function to parse_pathspec which can decided on
each file if it is
a file to inspect. (i.e. for our usecase we'd check for ce_mode to be
GITLINK, another
hypothetical use case would be using parse_pathspec for finding all
files with a certain
property, e.g. finding all files ending in .c or files written in all
capital letters or such)

Then you could do a conditional parse_pathspec over the partial
repository which matched
the additional filtering function.


Maybe we can also special case the "force" argument only here for
Cedars use case.
("git submodule deinit ." complains because there are no further
submodules, but -f solves
the complaint?)

  reply	other threads:[~2016-03-22 19:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22 17:59 [PATCH] submodule helper: accept '.' for repositories with no submodules Stefan Beller
2016-03-22 18:53 ` Junio C Hamano
2016-03-22 19:30   ` Stefan Beller [this message]
2016-03-22 20:06     ` Junio C Hamano
2016-03-22 21:16       ` Stefan Beller
2016-03-22 21:38         ` Junio C Hamano
2016-03-22 21:47           ` Stefan Beller
2016-03-22 22:04             ` Junio C Hamano
2016-03-22 22:10               ` Stefan Beller
2016-03-22 22:50                 ` Junio C Hamano

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=CAGZ79kaMa3CyJ-Y9Xn9QShzTUGythos+pmKZXQ7m-2c0bF0u9A@mail.gmail.com \
    --to=sbeller@google.com \
    --cc=Jens.Lehmann@web.de \
    --cc=cederp@opera.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).