git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC][PATCH] submodule: port submodule subcommand 'add' from shell to C

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 24, 2020, 20:46 UTC
Message-ID
<xmqq1rjv4vrb.fsf@gitster.c.googlers.com>
In-Reply-To
<43337924c09119d43c74fdad3f00d4dab76edb51.camel@gmail.com>
Kaartic Sivaraam <kaartic.sivaraam@gmail.com> writes:
Show 25 quoted lines
>> > 	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.

Show 14 quoted lines
>> > 	} 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.
Previous: Kaartic SivaraamNext: Shourya Shukla
Message 4 of 12 in “submodule: port submodule subcommand 'add' from shell to C”
  1. Shourya ShuklaAug 24, 2020
  2. Junio C HamanoAug 24, 2020
  3. Kaartic SivaraamAug 24, 2020
  4. Junio C HamanoAug 24, 2020
  5. Shourya ShuklaAug 26, 2020
  6. Kaartic SivaraamAug 26, 2020
  7. Shourya ShuklaAug 26, 2020
  8. Kaartic SivaraamAug 30, 2020
  9. Shourya ShuklaAug 31, 2020
  10. Kaartic SivaraamSep 1, 2020
  11. Shourya ShuklaSep 2, 2020
  12. Kaartic SivaraamSep 3, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.