archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <>
To: Shourya Shukla <>
Cc:,,,,, Prathamesh Chavan <>,
	Christian Couder <>,
	Stefan Beller <>
Subject: Re: [GSoC][PATCH] submodule: port submodule subcommand 'add' from shell to C
Date: Mon, 24 Aug 2020 11:35:20 -0700	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <> (Shourya Shukla's message of "Mon, 24 Aug 2020 14:33:59 +0530")

Shourya Shukla <> writes:

> 	if test -z "$force"
> 	then
> 		git ls-files --error-unmatch "$sm_path" > /dev/null 2>&1 &&
> 		die "$(eval_gettext "'\$sm_path' already exists in the index")"
> 	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.

 - 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.

> This is what I have done in C:
> 	if (!force) {
> 		if (is_directory(path) && submodule_from_path(the_repository, &null_oid, path))
> 			die(_("'%s' already exists in the index"), path);

The shell version would error out with anything in the index, so I'd
expect that a faithful conversion would not call is_directory() nor
submodule_from_path() at all---it would just look path up in the_index
and complains if anything is found.  For example, the quoted part in
the original above is what gives the error message when I do

	$ git submodule add ./Makefile
	'Makefile' already exists in the index.

I think.  And the above code won't trigger the "already exists" at
all because 'path' is not a directory.

> 	} 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)

Now it is a different question if the original is correct to begin
with ;-).  

> 	}
> Is this part correct? I am not very sure about this. This particular
> part is not covered in any test or test script, so, I do not have a
> solid method of knowing the correctness of this segment.
> Feedback and reviews are appreciated.

  reply	other threads:[~2020-08-24 18:35 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 [this message]
2020-08-24 20:30   ` Kaartic Sivaraam
2020-08-24 20:46     ` Junio C Hamano
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:

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

  git send-email \ \ \ \ \ \ \ \ \ \ \ \

* 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).