git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: cederp@opera.com, Jens.Lehmann@web.de, git@vger.kernel.org
Subject: Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
Date: Tue, 22 Mar 2016 11:53:23 -0700	[thread overview]
Message-ID: <xmqqy49agx98.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1458669579-32160-1-git-send-email-sbeller@google.com> (Stefan Beller's message of "Tue, 22 Mar 2016 10:59:39 -0700")

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.

  reply	other threads:[~2016-03-22 18:53 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 [this message]
2016-03-22 19:30   ` Stefan Beller
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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqy49agx98.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Jens.Lehmann@web.de \
    --cc=cederp@opera.com \
    --cc=git@vger.kernel.org \
    --cc=sbeller@google.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).