git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>,
	David Turner <David.Turner@twosigma.com>,
	Brandon Williams <bmwill@google.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>
Subject: Re: [PATCHv2 4/5] ok_to_remove_submodule: absorb the submodule git dir
Date: Wed, 14 Dec 2016 10:52:07 -0800	[thread overview]
Message-ID: <CAGZ79kZ=PqTKt5xDobnR5oqwz84i10ZobmQb6QqeA3aSkbrd8Q@mail.gmail.com> (raw)
In-Reply-To: <xmqqbmwexs9x.fsf@gitster.mtv.corp.google.com>

On Wed, Dec 14, 2016 at 10:46 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> It is a major reason to say no, when deciding if a submodule can be
>> deleted, if the git directory of the submodule being contained in the
>> submodule's working directory.
>>
>> Migrate the git directory into the superproject instead of failing,
>> and proceed with the other checks.
>>
>> Signed-off-by: Stefan Beller <sbeller@google.com>
>> ---
>>  submodule.c | 15 +++++++++++++--
>>  1 file changed, 13 insertions(+), 2 deletions(-)
>>
>> diff --git a/submodule.c b/submodule.c
>> index 2d13744b06..e42efa2337 100644
>> --- a/submodule.c
>> +++ b/submodule.c
>> @@ -1026,11 +1026,22 @@ int ok_to_remove_submodule(const char *path, unsigned flags)
>>       struct strbuf buf = STRBUF_INIT;
>>       int ok_to_remove = 1;
>>
>> +     /* Is it there? */
>>       if (!file_exists(path) || is_empty_dir(path))
>>               return 1;
>>
>> -     if (!submodule_uses_gitfile(path))
>> -             return 0;
>> +     /* Does it have a .git directory? */
>> +     if (!submodule_uses_gitfile(path)) {
>> +             absorb_git_dir_into_superproject("", path,
>> +                     ABSORB_GITDIR_RECURSE_SUBMODULES);
>> +
>> +             /*
>> +              * We should be using a gitfile by now. Let's double
>> +              * check as losing the git dir would be fatal.
>> +              */
>> +             if (!submodule_uses_gitfile(path))
>> +                     return 0;
>> +     }
>
> It feels a bit funny for a function that answers yes/no question to
> actually have a side effect, but probably it is OK.  It feels dirty,
> but I dunno.

Another approach would be to return more than yes/no but the reason
why it is a no. And then the caller would call absorb_git_dir_into_superproject.

> A brief reading of the above makes us wonder what should happen if
> the absorb_git_dir_into_superproject() call fails, but a separate
> "submodule_uses_gitfile()" is needed to see if it failed?  Perhaps
> the function needs to tell the caller if it succeeded?

I don't know about the double check as I think we should really be sure before
deleting that repo, but absorb_git_dir_into_superproject would fail/die
if it would not actually absorb it, so maybe it is too much caution.

So I'd omit the double check in a reroll.

>
>>
>>       argv_array_pushl(&cp.args, "status", "--porcelain",
>>                                  "--ignore-submodules=none", NULL);

  reply	other threads:[~2016-12-14 18:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 20:56 [PATCHv2 0/5] git-rm absorbs submodule git directory before deletion Stefan Beller
2016-12-13 20:56 ` [PATCHv2 1/5] submodule.h: add extern keyword to functions Stefan Beller
2016-12-13 20:56 ` [PATCHv2 2/5] submodule: modernize ok_to_remove_submodule to use argv_array Stefan Beller
2016-12-14 18:39   ` Junio C Hamano
2016-12-13 20:56 ` [PATCHv2 3/5] submodule: add flags to ok_to_remove_submodule Stefan Beller
2016-12-13 20:56 ` [PATCHv2 4/5] ok_to_remove_submodule: absorb the submodule git dir Stefan Beller
2016-12-14 18:46   ` Junio C Hamano
2016-12-14 18:52     ` Stefan Beller [this message]
2016-12-13 20:56 ` [PATCHv2 5/5] rm: add absorb a submodules git dir before deletion Stefan Beller
2016-12-14 18:55   ` 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='CAGZ79kZ=PqTKt5xDobnR5oqwz84i10ZobmQb6QqeA3aSkbrd8Q@mail.gmail.com' \
    --to=sbeller@google.com \
    --cc=David.Turner@twosigma.com \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sandals@crustytoothpaste.net \
    /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).