Re: git submodules implementation question

5 messages, 2 authors, 2016-08-29 · open the first message on its own page

Re: git submodules implementation question

From: Junio C Hamano <hidden>
Date: 2016-08-29 20:03:22

Uma Srinivasan [off-list ref] writes:
git_dir = read_gitfile(buf.buf);
if (!git_dir)

                git_dir = buf.buf;

Can anyone explain to me why we are replacing a failed reading of a
git file with the original sub directory name?
A top-level superproject can have a submodule bound at its "dir/"
directory, and "dir/.git" can either be a gitfile which you can read
with read_gitfile() and point into somewhere in ".git/modules/" of
the top-level superproject.  "dir/.git" can _ALSO_ be a fully valid
Git directory.  So at the top of a superproject, you could do

	git clone $URL ./dir2
        git add dir2

to clone an independent project into dir2 directory, and add it as a
new submodule.  The fallback is to support such a layout.

Re: git submodules implementation question

From: Junio C Hamano <hidden>
Date: 2016-08-29 21:09:57

On Mon, Aug 29, 2016 at 2:03 PM, Uma Srinivasan [off-list ref] wrote:
On Mon, Aug 29, 2016 at 1:03 PM, Junio C Hamano [off-list ref] wrote:
quoted
A top-level superproject can have a submodule bound at its "dir/"
directory, and "dir/.git" can either be a gitfile which you can read
with read_gitfile() and point into somewhere in ".git/modules/" of
the top-level superproject.  "dir/.git" can _ALSO_ be a fully valid
Git directory.  So at the top of a superproject, you could do

        git clone $URL ./dir2
        git add dir2

to clone an independent project into dir2 directory, and add it as a
new submodule.  The fallback is to support such a layout.
Thanks for the reply. However, in this case....

      git clone $URL ./dir2
      git add dir2

how will "dir2" get ever get registered as a submodule?
With a separate invocation of "git config -f .gitmodules", of course.
The layout to use gitfile to point into .git/modules/ is a more recent
invention than the submodule support itself that "git add" knows about.
The code needs to support both layout as well as it can, and that
is what the "can we read it as gitfile?  If not, that directory itself may
be a git repository" codepath you asked about is doing.

Re: git submodules implementation question

From: Uma Srinivasan <hidden>
Date: 2016-08-29 21:11:30

Thanks for the reply. However, in this case....

      git clone $URL ./dir2
      git add dir2

how will "dir2" get ever get registered as a submodule? I don't see
how one can reach the "is_submodule_modified" routine for the scenario
above.

My understanding is that a sub-directory can be registered as a
submodule only with the "git submodule add ...." command. In this case
only a gitlink file is created within the sub-directory and not a .git
subdirectory. Please correct me if I am wrong.

Thanks again,
Uma

On Mon, Aug 29, 2016 at 1:03 PM, Junio C Hamano [off-list ref] wrote:
Uma Srinivasan [off-list ref] writes:
quoted
git_dir = read_gitfile(buf.buf);
if (!git_dir)

                git_dir = buf.buf;

Can anyone explain to me why we are replacing a failed reading of a
git file with the original sub directory name?
A top-level superproject can have a submodule bound at its "dir/"
directory, and "dir/.git" can either be a gitfile which you can read
with read_gitfile() and point into somewhere in ".git/modules/" of
the top-level superproject.  "dir/.git" can _ALSO_ be a fully valid
Git directory.  So at the top of a superproject, you could do

        git clone $URL ./dir2
        git add dir2

to clone an independent project into dir2 directory, and add it as a
new submodule.  The fallback is to support such a layout.

Re: git submodules implementation question

From: Uma Srinivasan <hidden>
Date: 2016-08-29 21:13:53

Ok that makes sense. Thanks much.

Uma

On Mon, Aug 29, 2016 at 2:09 PM, Junio C Hamano [off-list ref] wrote:
On Mon, Aug 29, 2016 at 2:03 PM, Uma Srinivasan [off-list ref] wrote:
quoted
On Mon, Aug 29, 2016 at 1:03 PM, Junio C Hamano [off-list ref] wrote:
quoted
A top-level superproject can have a submodule bound at its "dir/"
directory, and "dir/.git" can either be a gitfile which you can read
with read_gitfile() and point into somewhere in ".git/modules/" of
the top-level superproject.  "dir/.git" can _ALSO_ be a fully valid
Git directory.  So at the top of a superproject, you could do

        git clone $URL ./dir2
        git add dir2

to clone an independent project into dir2 directory, and add it as a
new submodule.  The fallback is to support such a layout.
Thanks for the reply. However, in this case....

      git clone $URL ./dir2
      git add dir2

how will "dir2" get ever get registered as a submodule?
With a separate invocation of "git config -f .gitmodules", of course.
The layout to use gitfile to point into .git/modules/ is a more recent
invention than the submodule support itself that "git add" knows about.
The code needs to support both layout as well as it can, and that
is what the "can we read it as gitfile?  If not, that directory itself may
be a git repository" codepath you asked about is doing.

Re: git submodules implementation question

From: Uma Srinivasan <hidden>
Date: 2016-08-29 23:10:39

With respect to my original problem with a corrupted .git directory
under the submodule directory, I am thinking of adding the following 4
lines marked with ### to is_submodule_modified() to detect the
corrupted dir and die quickly instead of forking several child
processes:

               strbuf_addf(&buf, "%s/.git", path);
               git_dir = read_gitfile(buf.buf);
               if (!git_dir) {
                 ### strbuf_addf(&head_ref, "%s/HEAD",buf.buf);
                 ### if (strbuf_read_file(&temp_ref, head_ref.buf,0) < 0) {
                          ### die("Corrupted .git dir in submodule %s", path);
                 ###}
                         git_dir = buf.buf;
              }

This fixes my issue but what do you think? Is this the right way to
fix it? Is there a better way?

Thanks,
Uma

On Mon, Aug 29, 2016 at 2:13 PM, Uma Srinivasan [off-list ref] wrote:
Ok that makes sense. Thanks much.

Uma

On Mon, Aug 29, 2016 at 2:09 PM, Junio C Hamano [off-list ref] wrote:
quoted
On Mon, Aug 29, 2016 at 2:03 PM, Uma Srinivasan [off-list ref] wrote:
quoted
On Mon, Aug 29, 2016 at 1:03 PM, Junio C Hamano [off-list ref] wrote:
quoted
A top-level superproject can have a submodule bound at its "dir/"
directory, and "dir/.git" can either be a gitfile which you can read
with read_gitfile() and point into somewhere in ".git/modules/" of
the top-level superproject.  "dir/.git" can _ALSO_ be a fully valid
Git directory.  So at the top of a superproject, you could do

        git clone $URL ./dir2
        git add dir2

to clone an independent project into dir2 directory, and add it as a
new submodule.  The fallback is to support such a layout.
Thanks for the reply. However, in this case....

      git clone $URL ./dir2
      git add dir2

how will "dir2" get ever get registered as a submodule?
With a separate invocation of "git config -f .gitmodules", of course.
The layout to use gitfile to point into .git/modules/ is a more recent
invention than the submodule support itself that "git add" knows about.
The code needs to support both layout as well as it can, and that
is what the "can we read it as gitfile?  If not, that directory itself may
be a git repository" codepath you asked about is doing.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help