From: Jacob Keller <jacob.keller@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jacob Keller <jacob.e.keller@intel.com>,
Git mailing list <git@vger.kernel.org>,
Stefan Beller <stefanbeller@gmail.com>, Jeff King <peff@peff.net>,
Johannes Sixt <j6t@kdbg.org>
Subject: Re: [PATCH v8 4/8] submodule: allow add_submodule_odb to work even if path is not checked out
Date: Fri, 19 Aug 2016 13:32:27 -0700 [thread overview]
Message-ID: <CA+P7+xrFkCbLyvXKt1PKYsdFH2rCmjdMEyB27sDEScvGhxs7XA@mail.gmail.com> (raw)
In-Reply-To: <xmqqvayw1q1z.fsf@gitster.mtv.corp.google.com>
On Fri, Aug 19, 2016 at 1:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Jacob Keller <jacob.e.keller@intel.com> writes:
>
>> diff --git a/path.c b/path.c
>> index 17551c483476..0cb30123e988 100644
>> --- a/path.c
>> +++ b/path.c
>> @@ -482,6 +482,11 @@ static void do_submodule_path(struct strbuf *buf, const char *path,
>> strbuf_reset(buf);
>> strbuf_addstr(buf, git_dir);
>> }
>> + if (!is_git_directory(buf->buf)) {
>> + strbuf_reset(buf);
>> + strbuf_git_path(buf, "%s/%s", "modules", path);
>> + }
>> +
>> strbuf_addch(buf, '/');
>> strbuf_addbuf(&git_submodule_dir, buf);
>
> So, given submodule at $path, so far we have tried $path/.git and
> would have been happy if it was already a directory (i.e. an
> embedded repository in place), would have been happy if it was
> pointing at elsewhere (presumably at .git/modules/$name) that is a
> directory, and this is a fallback that covers the case where $path
> in the working tree of the superproject is missing.
>
> I _think_ "path" needs to be mapped to the "name" of the submodule
> that should be at the "path". Other than that, this hunk looks
> correct to me.
How do we do that? I tried to find a way to do that, couldn't, and
decided it was probably already normalized. It seems to be, based on
my tests, where I run git-log from within a subdirectory that has the
submodule. I think we already have the complete path. Or is the name
*not* equivalent to the path?
>
>> diff --git a/submodule.c b/submodule.c
>> index 1b5cdfb7e784..e1a51b7506ff 100644
>> --- a/submodule.c
>> +++ b/submodule.c
>> @@ -348,7 +348,7 @@ void show_submodule_summary(FILE *f, const char *path,
>> if (is_null_sha1(two))
>> message = "(submodule deleted)";
>> else if (add_submodule_odb(path))
>> - message = "(not checked out)";
>> + message = "(not initialized)";
>> else if (is_null_sha1(one))
>> message = "(new submodule)";
>> else if (!(left = lookup_commit_reference(one)) ||
>
> This is a change unrelated to the fix you made above, and should be
> done in its own separate patch, I would think.
>
It is the same change. The first hunk makes it so that "not checked
out" is no longer what occurs. We change the behavior of
add_submodule_odb into "work even if there is no check out, but only
fail when the submodule isn't initialized at all, either in path/.git
or ./git/modules/path/" so we need to change the message because we've
changed behavior.
>> diff --git a/t/t4059-diff-submodule-not-initialized.sh b/t/t4059-diff-submodule-not-initialized.sh
>> new file mode 100755
>> index 000000000000..cc787454033a
>> --- /dev/null
>> +++ b/t/t4059-diff-submodule-not-initialized.sh
>> @@ -0,0 +1,105 @@
>> +#!/bin/sh
>> +#
>> +# Copyright (c) 2016 Jacob Keller, based on t4041 by Jens Lehmann
>> +#
>> +
>> +test_description='Test for submodule diff on non-checked out submodule
>> +
>> +This test tries to verify that add_submodule_odb works when the submodule was
>> +initialized previously but the checkout has since been removed.
>> +'
>> +
>> +TEST_NO_CREATE_REPO=1
>> +. ./test-lib.sh
>> +
>> +# Tested non-UTF-8 encoding
>> +test_encoding="ISO8859-1"
>> +
>> +# String "added" in German (translated with Google Translate), encoded in UTF-8,
>> +# used in sample commit log messages in add_file() function below.
>> +added=$(printf "hinzugef\303\274gt")
>
> Have an empty line here?
>
Makes sense I suppose.
>> +add_file () {
>> + (
>> + cd "$1" &&
>> + shift &&
>> + for name
>> + do
>> + echo "$name" >"$name" &&
>> + git add "$name" &&
>> + test_tick &&
>> + # "git commit -m" would break MinGW, as Windows refuse to pass
>> + # $test_encoding encoded parameter to git.
>> + echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
>> + git -c "i18n.commitEncoding=$test_encoding" commit -F -
>> + done >/dev/null &&
>> + git rev-parse --short --verify HEAD
>> + )
>> +}
>
> Have an empty line here?
>
There was no empty line in the place I copied from.
>> +commit_file () {
>> + test_tick &&
>> + git commit "$@" -m "Commit $*" >/dev/null
>> +}
>
> Surround these ...
>
>> +test_create_repo sm1 &&
>> +test_create_repo sm2 &&
>> +add_file sm1 foo >/dev/null &&
>> +add_file sm2 foo1 foo2 >/dev/null &&
>> +smhead1=$(cd sm2; git rev-parse --short --verify HEAD) &&
>
> ... inside its own "test_expect_success setup"?
>
> None of the ">/dev/null" we see in the above helper functions (and
> use of these helper functions) are necessary or desired, I would
> think.
If we put them in test_expect_success setup they aren't. They were
because add_file returns the sha1 of the rev-parse on HEAD after
adding.
>
> The last one can become "$(git -C sm2 rev-parse ...)".
>
Yea.
>> +cd sm1
>
> I can sort of see the attraction of doing it this way, but we avoid
> chdir'ing around outside subshells, especially in a newly added test
> script. It is very easy to go down and forget to come back up, or
> worse yet, stop going down and forget to remove matching "cd .." and
> end up being outside the $TEST_DIRECTORY by mistake.
>
That would make a lot of tests problematic here.. but probably doable.
>> +test_expect_success 'setup - submodule directory' '
>> +...
>> +
>> +cd ..
>> +
>> +test_expect_success 'submodule not initialized in new clone' '
>> +...
>
> The tests themselves looked sensible. Thanks.
Thanks,
Jake
next prev parent reply other threads:[~2016-08-19 20:51 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-19 0:00 [PATCH v8 0/8] submodule show inline diff Jacob Keller
2016-08-19 0:00 ` [PATCH v8 1/8] diff.c: remove output_prefix_length field Jacob Keller
2016-08-19 0:00 ` [PATCH v8 2/8] graph: add support for --line-prefix on all graph-aware output Jacob Keller
2016-08-19 0:00 ` [PATCH v8 3/8] diff: prepare for additional submodule formats Jacob Keller
2016-08-19 19:49 ` Junio C Hamano
2016-08-19 0:00 ` [PATCH v8 4/8] submodule: allow add_submodule_odb to work even if path is not checked out Jacob Keller
2016-08-19 20:06 ` Junio C Hamano
2016-08-19 20:32 ` Jacob Keller [this message]
2016-08-19 21:11 ` Junio C Hamano
2016-08-19 22:00 ` Jacob Keller
2016-08-19 22:26 ` Junio C Hamano
2016-08-19 23:25 ` Jacob Keller
2016-08-19 0:00 ` [PATCH v8 5/8] submodule: convert show_submodule_summary to use struct object_id * Jacob Keller
2016-08-19 20:12 ` Junio C Hamano
2016-08-19 0:00 ` [PATCH v8 6/8] submodule: refactor show_submodule_summary with helper function Jacob Keller
2016-08-19 20:24 ` Junio C Hamano
2016-08-19 20:33 ` Jacob Keller
2016-08-19 0:00 ` [PATCH v8 7/8] cache: add empty_tree_oid object Jacob Keller
2016-08-19 20:31 ` Junio C Hamano
2016-08-19 20:35 ` Jacob Keller
2016-08-19 20:50 ` Junio C Hamano
2016-08-19 21:14 ` Junio C Hamano
2016-08-19 22:02 ` Jacob Keller
2016-08-19 20:58 ` Jeff King
2016-08-23 16:28 ` Junio C Hamano
2016-08-19 0:00 ` [PATCH v8 8/8] diff: teach diff to display submodule difference with an inline diff Jacob Keller
2016-08-19 21:52 ` Junio C Hamano
2016-08-19 22:03 ` Jacob Keller
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=CA+P7+xrFkCbLyvXKt1PKYsdFH2rCmjdMEyB27sDEScvGhxs7XA@mail.gmail.com \
--to=jacob.keller@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=jacob.e.keller@intel.com \
--cc=peff@peff.net \
--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).