From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
To: Shourya Shukla <shouryashukla.oo@gmail.com>
Cc: gitster@pobox.com, git@vger.kernel.org,
christian.couder@gmail.com, johannes.schindelin@gmx.de,
liu.denton@gmail.com
Subject: Re: [GSoC][PATCH] submodule: port submodule subcommand 'add' from shell to C
Date: Wed, 02 Sep 2020 02:05:22 +0530 [thread overview]
Message-ID: <31e40c63bbac03d261ac6f46a0d2f6ae90a21038.camel@gmail.com> (raw)
In-Reply-To: <20200831130448.GA119147@konoha>
On Mon, 2020-08-31 at 18:34 +0530, Shourya Shukla wrote:
> On 31/08 01:28, Kaartic Sivaraam wrote:
>
> This is what I have done finally:
> ---
> if (read_cache() < 0)
> die(_("index file corrupt"));
>
> if (!force) {
> if (cache_file_exists(path, strlen(path), ignore_case) ||
> cache_dir_exists(path, strlen(path)))
> die(_("'%s' already exists in the index"), path);
> } else {
> int cache_pos = cache_name_pos(path, strlen(path));
> struct cache_entry *ce = the_index.cache[cache_pos];
> if (cache_pos >= 0 && !S_ISGITLINK(ce->ce_mode))
> die(_("'%s' already exists in the index and is not a "
> "submodule"), path);
> }
> ---
>
> I did not put the 'cache_pos >= 0' at the start since I thought that it
> will unnecessarily increase an indentation level. Since we are using
> 'cache_{file,dir}_exists' in the first check and 'cache_name_pos()' in
> the second, the placement of check at another indentation level would be
> unnecessary. What do you think about this?
>
Interestingly. 'cache_dir_exists' seems to work as expected only when
the global ignore_case whose value seems to depend on core.ignorecase.
So, we can't just rely on 'cache_dir_exists to identify a directory
that has tracked contents. Apparently, the 'directory_exists_in_index'
in 'dir.c' seems to have the code that we want here (which is also the
only user of 'index_dir_exists'; the function for which
'cache_dir_exists' is a convenience wrapper.
The best idea I could think of is to expose that method and re-use it
here. Given that my kowledge about index and caching is primitive, I'm
not sure if there's a better approach. If others have a better idea for
handling this directory case, do enlighten us.
> > This is more close to what the shell version did but misses one case
> > which might or might not be covered by the test suite[1]. The case when
> > path is a directory that has tracked contents. In the shell version we
> > would get:
> >
> > $ git submodule add ../git-crypt/ builtin
> > 'builtin' already exists in the index
> > $ git submodule add --force ../git-crypt/ builtin
> > 'builtin' already exists in the index and is not a submodule
> >
> > In the C version with the above snippet we get:
> >
> > $ git submodule add --force ../git-crypt/ builtin
> > fatal: 'builtin' does not have a commit checked out
> > $ git submodule add ../git-crypt/ builtin
> > fatal: 'builtin' does not have a commit checked out
> >
> > That's not appropriate and should be fixed. I believe we could do
> > something with `cache_dir_exists` to fix this.
> >
> >
> > Footnote
> > ===
> >
> > [1]: If it's not covered already, it might be a good idea to add a test
> > for the above case.
>
> Like Junio said, we do not care if it is a file or a directory of any
> sorts, we will give the error if it already exists. Therefore, even if
> it is an untracked or a tracked one, it should not matter to us. Hence
> testing for it may not be necessary is what I feel. Why should we test
> it?
I'm guessing you misunderstood. A few things:
- We only care about tracked contents for the case in hand.
- Identifying whether a given path corresponds to a directory
which has tracked contents is tricky. Neither 'cache_name_pos'
nor 'cache_file_exists' handle this. 'cache_dir_exists' is also
not very useful as mentioned above.
So, we do have to take care when handling that case as Junio pointed
out.
--
Sivaraam
next prev parent reply other threads:[~2020-09-01 20: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
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 [this message]
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=31e40c63bbac03d261ac6f46a0d2f6ae90a21038.camel@gmail.com \
--to=kaartic.sivaraam@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=liu.denton@gmail.com \
--cc=shouryashukla.oo@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).