git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC/PATCH 0/7] Rework git core for native submodules

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Apr 8, 2013, 19:03 UTC
Message-ID
<CALkWK0m4o=F=bh_mt9NGDfXKExgVtLhaZ7uxA_XFhpF5AN5-Fg@mail.gmail.com>
In-Reply-To
<7va9p8yjuf.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 11 quoted lines
> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>
>> 1. Having a toplevel .gitmodules means that any git-core command like
>> add/ rm/ mv will be burdened with looking for the .gitmodules at the
>> toplevel of the worktree and editing it appropriately along with
>> whatever it was built to do (ie. writing to the index and committing
>> it).
>
> Burdened is a subjective word.  What's bad about having a single place
> you know you can read and find out information about things?  You
> have to learn about them to do anything specific to them anyway.

"Burden" refers to the extra work of looking for a file in the worktree, when this is completely unnecessary if you use a link object.

>> This is highly unnatural.
>
> Unnatural is a subjective word, and there is no justification I see
> here in your message.

git's design follows along the lines of the UNIX philosophy: do one thing, do it well. git add/ rm/ mv have a very sharply defined task: they first lock the index file, read the_index using read_cache(), build a cache_entry struct using user-supplied data (this might involve worktree code from dir.c to recurse subdirectories, for example), write that cache_entry to the_index (removing existing entries with cache_tree_invalidate_path() if necessary), and finally write the_index to the index file, releasing the lock. Would you agree that any operation that doesn't follow along this line is unnatural? What then, does writing a special file in the worktree (aka .gitmodules) have to do with this entire process?

Does git diff/ commit/ add/ rm or any other command you can think of rely on a special file in the worktree (aka .gitmodules) to be checked out? Then why does git submodule require it? Isn't this a requirement that is inconsistent with the rest of git-core?

Show 6 quoted lines
>> Putting the information in link
>> objects means that we get a more natural UI + warts like
>> cd-to-toplevel disappear with no extra code.
>
> I do not see how "link objects" _means_ "natural UI", yet, without
> an explanation how one leads to the other.

I should've said "means an easy route to get the existing UI to work with little or no additional code". Making the submodule information available to git-core is precisely what leads to this. In index_path(), you can inject a case for S_IFDIR to write a link object to the database, writing the sha1 to the supplied argument. This is not unnatural in any way, because we're just following along the lines of the S_IFLNK codepath, which writes a blob object to the database. Now index_path() is called by add_to_index(), which is the master function for adding anything to the index. Therefore, git add just works. git rm is much simpler: it calls remove_file_from_index() which in turn calls cache_tree_invalidate() and remove_index_entry_at(). Once the entry is removed from the cache, our job is done. The link object will be cleaned up at gc-time. git mv is just a combination of git rm and git add: it invalidates an existing entry and adds a new one with a different name.

There is no special .gitmodules to take care of.
Show 8 quoted lines
> What does cd-to-toplevel have anything to do with it?  In case you
> did not notice, all the core commands internally cd-to-toplevel and
> carry the "prefix" information while doing so, and prepend the
> prefix to user-supplied paths to find which path the user is talking
> about.  So "cd to toplevel before starting to carry the operation out"
> is a natural pattern inside Git.  As many people already told you,
> "the user has to run 'git submodule' from the top-level of the
> submodule working tree" is a simple oversight of the implementation.

Yes, I am aware. I'm piggy-banking on the mature parts of git-core to get functionality that I would otherwise have to write by hand. The current implementation needs to hand-code this, and hasn't done it yet (presumably because it's non-trivial).

Show 11 quoted lines
>> 2. If we want to make git-submodule a part of git-core (which I think
>> everyone agrees with), we will need to make the information in
>> .gitmodules available more easily to the rest of git-core.
>
> Care to define "more easily" which is another subjective word?  The
> .gitmodules file uses the bog-standard configuration format that can
> be easily read with the config.c infrastructure.  It is a separate
> matter that git_config() API is cumbersome to use, but improving it
> would help not just .gitmodules but also the regular non-submodule
> users of Git.  There is a topic in the works to read data in that
> format from core Heiko is working on.
This goes both ways: the information is both easier to read and write.
 I can easily create a link object from anywhere: index_path() or
cmd_edit_link().  To do this, I just have to call write_sha1_file()
with the buffer filled out and with the parameter link_type (which is
already defined).  To access the data in a link, I have to fill out a
tree_desc with "HEAD", an unpack_tree_opts with a custom callback, and
pass it to unpack_trees().  An example of a custom callback:
cmd_cat_link() which simply calls get_stat_data() to fill in the
SHA-1, and read_sha1_file() to read that object into a buffer.

I don't have to rely on a worktree with toplevel .gitmodules checked out. The information is easily readable/ writeable by default when I'm working with git, irrespective of my the state of my worktree.

Why must we use the git_config() API when it was never designed to do this? Why not leverage the mature part of git that was intended for this, where our new object fits in snugly?

Can you now present a counter-argument about why .gitmodules is _better_ suited for the task of managing submodules? (Hint: No, you can't; because it isn't). Can you give me an example of one thing that will become more complex if we were to follow my approach (I've already acknowledged foreach, so that's out)? Do you have any concrete objections to the new design, apart from the fact that it breaks what already "works"? Do you acknowledge that the new design will remove a lot of existing complexity (if "complex" is too subjective for you: result in a significant negative overall diffstat)?

Previous: Junio C HamanoNext: Junio C Hamano
Message 106 of 138 in “Rework git core for native submodules”
  1. 0/7 Rework git core for native submodulesRamkumar Ramachandra, Apr 4, 2013
  2. 1/7 link.c, link.h: introduce fifth object typeRamkumar Ramachandra, Apr 4, 2013
  3. 2/7 sha1_file, link: write link objects to the databaseRamkumar Ramachandra, Apr 4, 2013
  4. Ramkumar RamachandraApr 5, 2013
  5. Ramkumar RamachandraApr 5, 2013
  6. 3/7 teach ce_compare_gitlink() about OBJ_LINKRamkumar Ramachandra, Apr 4, 2013
  7. 4/7 builtin/log: teach show about OBJ_LINKRamkumar Ramachandra, Apr 4, 2013
  8. 5/7 edit-link: add new builtinRamkumar Ramachandra, Apr 4, 2013
  9. 6/7 clone: introduce clone.submodulegitdirRamkumar Ramachandra, Apr 4, 2013
  10. Ramkumar RamachandraApr 5, 2013
  11. 7/7 sha1_file: write ref_name to link objectRamkumar Ramachandra, Apr 4, 2013
  12. Ramkumar RamachandraApr 5, 2013
  13. Linus TorvaldsApr 4, 2013
  14. Ramkumar RamachandraApr 4, 2013
  15. Linus TorvaldsApr 4, 2013
  16. Junio C HamanoApr 4, 2013
  17. Ramkumar RamachandraApr 4, 2013
  18. Jens LehmannApr 4, 2013
  19. Ramkumar RamachandraApr 4, 2013
  20. Linus TorvaldsApr 4, 2013
  21. Ramkumar RamachandraApr 4, 2013
  22. Ramkumar RamachandraApr 4, 2013
  23. Ramkumar RamachandraApr 4, 2013
  24. Ramkumar RamachandraApr 4, 2013
  25. Jens LehmannApr 4, 2013
  26. Ramkumar RamachandraApr 4, 2013
  27. Junio C HamanoApr 4, 2013
  28. Ramkumar RamachandraApr 4, 2013
  29. Junio C HamanoApr 4, 2013
  30. Ramkumar RamachandraApr 4, 2013
  31. Junio C HamanoApr 4, 2013
  32. Ramkumar RamachandraApr 4, 2013
  33. Junio C HamanoApr 5, 2013
  34. Ramkumar RamachandraApr 5, 2013
  35. Ramkumar RamachandraApr 5, 2013
  36. Jonathan NiederApr 4, 2013
  37. Jonathan NiederApr 4, 2013
  38. Jonathan NiederApr 4, 2013
  39. Duy NguyenApr 8, 2013
  40. t3700 (add): add failing test for add with submodulesRamkumar Ramachandra, Apr 8, 2013
  41. Duy NguyenApr 8, 2013
  42. Junio C HamanoApr 8, 2013
  43. Jeff KingApr 8, 2013
  44. Junio C HamanoApr 8, 2013
  45. Jeff KingApr 8, 2013
  46. Ramkumar RamachandraApr 9, 2013
  47. 0/2 Fix git add with submodulesRamkumar Ramachandra, Apr 9, 2013
  48. 1/2 t3700 (add): add two tests for testing add with submodulesRamkumar Ramachandra, Apr 9, 2013
  49. 2/2 add: refuse to add paths beyond repository boundariesRamkumar Ramachandra, Apr 9, 2013
  50. Jeff KingApr 9, 2013
  51. Junio C HamanoApr 9, 2013
  52. Junio C HamanoApr 9, 2013
  53. Ramkumar RamachandraApr 9, 2013
  54. Junio C HamanoApr 9, 2013
  55. Ramkumar RamachandraApr 9, 2013
  56. Junio C HamanoApr 9, 2013
  57. Junio C HamanoApr 9, 2013
  58. Junio C HamanoApr 9, 2013
  59. Ramkumar RamachandraApr 10, 2013
  60. Junio C HamanoApr 10, 2013
  61. Junio C HamanoApr 9, 2013
  62. Ramkumar RamachandraApr 9, 2013
  63. Junio C HamanoApr 9, 2013
  64. Ramkumar RamachandraApr 10, 2013
  65. Jakub NarębskiApr 9, 2013
  66. Junio C HamanoApr 9, 2013
  67. Jakub NarębskiApr 9, 2013
  68. Junio C HamanoApr 9, 2013
  69. Jeff KingApr 9, 2013
  70. Jakub NarębskiApr 9, 2013
  71. Ramkumar RamachandraApr 9, 2013
  72. Jakub NarębskiApr 9, 2013
  73. Ramkumar RamachandraApr 6, 2013
  74. Junio C HamanoApr 7, 2013
  75. Ramkumar RamachandraApr 7, 2013
  76. Junio C HamanoApr 7, 2013
  77. Ramkumar RamachandraApr 7, 2013
  78. Ramkumar RamachandraApr 7, 2013
  79. John KeepingApr 7, 2013
  80. Ramkumar RamachandraApr 7, 2013
  81. John KeepingApr 7, 2013
  82. Ramkumar RamachandraApr 7, 2013
  83. John KeepingApr 7, 2013
  84. Ramkumar RamachandraApr 7, 2013
  85. John KeepingApr 7, 2013
  86. Jens LehmannApr 7, 2013
  87. Ramkumar RamachandraApr 7, 2013
  88. Jens LehmannApr 7, 2013
  89. Ramkumar RamachandraApr 7, 2013
  90. John KeepingApr 7, 2013
  91. Ramkumar RamachandraApr 7, 2013
  92. Ramkumar RamachandraApr 7, 2013
  93. Jonathan NiederApr 7, 2013
  94. Ramkumar RamachandraApr 7, 2013
  95. Jens LehmannApr 8, 2013
  96. Ramkumar RamachandraApr 8, 2013
  97. Jonathan NiederApr 8, 2013
  98. Ramkumar RamachandraApr 8, 2013
  99. Duy NguyenApr 8, 2013
  100. Ramkumar RamachandraApr 8, 2013
  101. Duy NguyenApr 8, 2013
  102. Ramkumar RamachandraApr 8, 2013
  103. Junio C HamanoApr 8, 2013
  104. Ramkumar RamachandraApr 8, 2013
  105. Junio C HamanoApr 8, 2013
  106. Ramkumar RamachandraApr 8, 2013
  107. Junio C HamanoApr 8, 2013
  108. Ramkumar RamachandraApr 8, 2013
  109. Junio C HamanoApr 8, 2013
  110. Ramkumar RamachandraApr 8, 2013
  111. Philip OakleyApr 10, 2013
  112. Ramkumar RamachandraApr 8, 2013
  113. Jakub NarębskiApr 9, 2013
  114. Ramkumar RamachandraApr 8, 2013
  115. Jonathan NiederApr 8, 2013
  116. Ramkumar RamachandraApr 8, 2013
  117. Junio C HamanoApr 8, 2013
  118. Junio C HamanoApr 8, 2013
  119. Duy NguyenApr 17, 2013
  120. Ramkumar RamachandraApr 17, 2013
  121. Duy NguyenApr 17, 2013
  122. Ramkumar RamachandraApr 17, 2013
  123. Duy NguyenApr 17, 2013
  124. Ramkumar RamachandraApr 17, 2013
  125. Philip OakleyApr 17, 2013
  126. Ramkumar RamachandraApr 18, 2013
  127. Jens LehmannApr 19, 2013
  128. Junio C HamanoApr 17, 2013
  129. Jens LehmannApr 8, 2013
  130. Jeff KingApr 8, 2013
  131. John KeepingApr 7, 2013
  132. Ramkumar RamachandraApr 7, 2013
  133. Ramkumar RamachandraApr 7, 2013
  134. Ramkumar RamachandraApr 7, 2013
  135. Ramkumar RamachandraApr 7, 2013
  136. Ramkumar RamachandraApr 7, 2013
  137. Ramkumar RamachandraApr 7, 2013
  138. Ramkumar RamachandraApr 8, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.