From: Junio C Hamano <gitster@pobox.com>
To: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Cc: Shourya Shukla <shouryashukla.oo@gmail.com>,
git@vger.kernel.org, christian.couder@gmail.com,
johannes.schindelin@gmx.de, liu.denton@gmail.com,
Prathamesh Chavan <pc44800@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>,
Stefan Beller <stefanbeller@gmail.com>
Subject: Re: [GSoC][PATCH] submodule: port submodule subcommand 'add' from shell to C
Date: Mon, 24 Aug 2020 13:46:48 -0700 [thread overview]
Message-ID: <xmqq1rjv4vrb.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <43337924c09119d43c74fdad3f00d4dab76edb51.camel@gmail.com> (Kaartic Sivaraam's message of "Tue, 25 Aug 2020 02:00:16 +0530")
Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:
>> > else
>> > git ls-files -s "$sm_path" | sane_grep -v "^160000" > /dev/null 2>&1 &&
>> > die "$(eval_gettext "'\$sm_path' already exists in the index and is not a submodule")"
>> > fi
>>
>> Hmph. So,
>>
>> - if we are not being 'force'd, we see if there is anything in the
>> index for the path and error out, whether it is a gitlink or not.
>>
>
> Right.
>
>> - if there is 'force' option, we see what the given path is in the
>> index, and if it is already a gitlink, then die. That sort of
>> makes sense, as long as the remainder of the code deals with the
>> path that is not a submodule in a sensible way.
>>
>
> With `force, I think it's the opposite of what you describe. That is:
>
> - if there is 'force' option, we see what the given path is in the
> index, and if it is **not** already a gitlink, then die.
>
> Note the `-v` passed to sane_grep.
Thanks.
Yeah, "-v ^160000" passes (i.e. detects an error) if the path exists
and it is anything but gitlink, so missing path is OK (no input to
grep, and grep won't see a gitlink), a blob is not OK (grep sees
something that is not a gitlink), and a gitlink is not OK.
If $sm_path is a directory with tracked contents, ls-files would
give multiple entries, and some of which may or may not be a
gitlink, but most of them would not be, so it is likely that grep
would find one entry that is not gitlink and error out. Which is a
good thing to do.
>> > } else {
>> > int err;
>> > if (index_name_pos(&the_index, path, strlen(path)) >= 0 &&
>> > !is_submodule_populated_gently(path, &err))
>> > die(_("'%s' already exists in the index and is not a "
>> > "submodule"), path);
>>
>> Likewise. The above does much more than the original.
>>
>> The original was checking if the found cache entry has 160000 mode
>> bit, so the second test would not be is_submodule_populated_gently()
>> but more like !S_ISGITLINK(ce->ce_mode)
>
> Yeah, the C version does need a more proper check in both cases.
Especially, the case where $sm_path is a directory with tracked
contents in it would need a careful examination.
Thanks.
next prev parent reply other threads:[~2020-08-24 20:46 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-24 9:03 [GSoC][PATCH] submodule: port submodule subcommand 'add' from shell to C Shourya Shukla
2020-08-24 18:35 ` Junio C Hamano
2020-08-24 20:30 ` Kaartic Sivaraam
2020-08-24 20:46 ` Junio C Hamano [this message]
2020-08-26 9:27 ` Shourya Shukla
2020-08-26 10:54 ` Kaartic Sivaraam
2020-08-26 9:15 ` Shourya Shukla
2020-08-30 19:58 ` Kaartic Sivaraam
2020-08-31 13:04 ` Shourya Shukla
2020-09-01 20:35 ` Kaartic Sivaraam
2020-09-02 12:04 ` Shourya Shukla
2020-09-03 8:46 ` Kaartic Sivaraam
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=xmqq1rjv4vrb.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=kaartic.sivaraam@gmail.com \
--cc=liu.denton@gmail.com \
--cc=pc44800@gmail.com \
--cc=shouryashukla.oo@gmail.com \
--cc=stefanbeller@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.
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).