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

Re: [PATCH 0/6] Initial subproject support (RFC?)

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Apr 10, 2007, 04:46 UTC
Message-ID
<Pine.LNX.4.64.0704092133550.6730@woody.linux-foundation.org>
In-Reply-To
<Pine.LNX.4.64.0704092100110.6730@woody.linux-foundation.org>
On Mon, 9 Apr 2007, Linus Torvalds wrote:
Show 6 quoted lines
> 
> NOTE! This series of six patches does not actually contain everything you 
> need to do that - in particular, this series will not actually connect up 
> the magic to make "git add" (and thus "git commit") actually create the 
> gitlink entries for subprojects. That's another (quite small) patch, but I 
> haven't cleaned it up enough to be submittable yet.

Here is, for your enjoyment, the last patch I used to actually test this all. I do *not* submit it as a patch for actual inclusion - the other patches in the series are, I think, ready to actually be merged. This one is not.

It's broken for a few reasons:
 - it allows you to do "git add subproject" to add the subproject to the 
   index (and then use "git commit" to commit it), but even something as 
   simple as "git commit -a" doesn't work right, because the sequence that 
   "git commit -a" uses to update the index doesn't work with the current 
   state of the plumbing (ie the
	git-diff-files --name-only -z |
		git-update-index --remove -z --stdin
   thing doesn't work right.
 - even for "git add", the logic isn't really right. It should take the 
   old index state into account to decide if it wants to add it as a 
   subproject. 

so this patch really isn't very good, but it allows people who are interested to perhaps actually test something. For example, my test repo was actually created with this:

	[torvalds@woody superproject]$ git log --raw
	commit 649ad968bdd79cb3b0f50feb819b7e9b134d3a1a
	Author: Linus Torvalds <torvalds@woody.linux-foundation.org>
	Date:   Mon Apr 9 21:36:53 2007 -0700
	
	    This commits the modification to sub-project B
	
	:160000 160000 5813084832d3c680a3436b0253639c94ed55445d 17d246a35f27a46762328281eb6e9d4558f91e9d M      sub-B
	commit f3c55ffcc000a8c0fecc6801e8909d084e3d419e
	Author: Linus Torvalds <torvalds@woody.linux-foundation.org>
	Date:   Mon Apr 9 16:12:29 2007 -0700
	
	    Superproject with two subprojects
	
	:000000 160000 0000000... c0daf4c85d48879ab450a6a887bbb241eb0de00a A    sub-A
	:000000 160000 0000000... 5813084832d3c680a3436b0253639c94ed55445d A    sub-B
	commit 45eb14edb43b10e3d3ac7a495a1ec861e85dc36f
	Author: Linus Torvalds <torvalds@woody.linux-foundation.org>
	Date:   Mon Apr 9 15:36:24 2007 -0700
	
	    Add top-level Makefile for super-project
	
	:000000 100644 0000000... 57e8394... A  Makefile

so you can see how things look at a low level (ie a "gitlink" is just a tree entry with mode 0160000, and the SHA1 is just the SHA1 of the HEAD commit in the subproject)

		Linus
---
diff --git a/dir.c b/dir.c
index 4f5a224..ef284a2 100644
--- a/dir.c
+++ b/dir.c
@@ -378,6 +378,14 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co
 					continue;
 				/* fallthrough */
 			case DT_DIR:
+				/* Does it have a git directory? If so, it's a DIRLNK */
+				if (!dir->no_dirlinks) {
+					memcpy(fullname + baselen + len, "/.git/", 7);
+					if (!stat(fullname, &st)) {
+						if (S_ISDIR(st.st_mode))
+							break;
+					}
+				}
 				memcpy(fullname + baselen + len, "/", 2);
 				len++;
 				if (dir->show_other_directories &&
diff --git a/dir.h b/dir.h
index 33c31f2..1931609 100644
--- a/dir.h
+++ b/dir.h
@@ -33,7 +33,8 @@ struct dir_struct {
 	int nr, alloc;
 	unsigned int show_ignored:1,
 		     show_other_directories:1,
-		     hide_empty_directories:1;
+		     hide_empty_directories:1,
+		     no_dirlinks;
 	struct dir_entry **entries;
 
 	/* Exclude info */
Previous: Josef WeidendorferNext: Alex Riesen
Message 80 of 98 in “Initial subproject support (RFC?)”
  1. 0/6 Initial subproject support (RFC?)Linus Torvalds, Apr 10, 2007
  2. 1/6 diff-lib: use ce_mode_from_stat() rather than messing with modes manuallyLinus Torvalds, Apr 10, 2007
  3. 2/6 Avoid overflowing name buffer in deep directory structuresLinus Torvalds, Apr 10, 2007
  4. 3/6 Add 'resolve_gitlink_ref()' helper functionLinus Torvalds, Apr 10, 2007
  5. Alex RiesenApr 10, 2007
  6. Linus TorvaldsApr 10, 2007
  7. Alex RiesenApr 10, 2007
  8. Linus TorvaldsApr 10, 2007
  9. Alex RiesenApr 10, 2007
  10. Linus TorvaldsApr 10, 2007
  11. Josef WeidendorferApr 10, 2007
  12. 4/6 Add "S_IFDIRLNK" file mode infrastructure for git linksLinus Torvalds, Apr 10, 2007
  13. 5/6 Teach "fsck" not to follow subproject linksLinus Torvalds, Apr 10, 2007
  14. Sam VilainApr 11, 2007
  15. Linus TorvaldsApr 11, 2007
  16. Sam VilainApr 11, 2007
  17. Linus TorvaldsApr 11, 2007
  18. David LangApr 11, 2007
  19. Linus TorvaldsApr 11, 2007
  20. David LangApr 11, 2007
  21. Linus TorvaldsApr 12, 2007
  22. Junio C HamanoApr 12, 2007
  23. David LangApr 12, 2007
  24. Dana HowApr 12, 2007
  25. Linus TorvaldsApr 12, 2007
  26. Rogan DawesApr 13, 2007
  27. Linus TorvaldsApr 13, 2007
  28. Dana HowApr 15, 2007
  29. Dana HowApr 12, 2007
  30. Sam VilainApr 12, 2007
  31. Junio C HamanoApr 12, 2007
  32. Linus TorvaldsApr 12, 2007
  33. Junio C HamanoApr 12, 2007
  34. Junio C HamanoApr 12, 2007
  35. Linus TorvaldsApr 12, 2007
  36. Dana HowApr 11, 2007
  37. 6/6 Teach core object handling functions about gitlinksLinus Torvalds, Apr 10, 2007
  38. Frank LichtenheldApr 10, 2007
  39. Alex RiesenApr 10, 2007
  40. Linus TorvaldsApr 10, 2007
  41. Josef WeidendorferApr 10, 2007
  42. Alex RiesenApr 10, 2007
  43. Josef WeidendorferApr 10, 2007
  44. Linus TorvaldsApr 10, 2007
  45. Andy ParkinsApr 10, 2007
  46. Linus TorvaldsApr 10, 2007
  47. Junio C HamanoApr 10, 2007
  48. Linus TorvaldsApr 10, 2007
  49. Sam VilainApr 12, 2007
  50. Martin WaitzApr 12, 2007
  51. Linus TorvaldsApr 12, 2007
  52. Sam VilainApr 12, 2007
  53. David LangApr 10, 2007
  54. Junio C HamanoApr 10, 2007
  55. Josef WeidendorferApr 10, 2007
  56. Linus TorvaldsApr 10, 2007
  57. Sam VilainApr 11, 2007
  58. Linus TorvaldsApr 12, 2007
  59. Torgil SvenssonApr 12, 2007
  60. Martin WaitzApr 12, 2007
  61. Torgil SvenssonApr 12, 2007
  62. Sam VilainApr 11, 2007
  63. Martin WaitzApr 11, 2007
  64. Alex RiesenApr 11, 2007
  65. Martin WaitzApr 11, 2007
  66. Alex RiesenApr 11, 2007
  67. Martin WaitzApr 11, 2007
  68. Junio C HamanoApr 11, 2007
  69. Martin WaitzApr 11, 2007
  70. Junio C HamanoApr 11, 2007
  71. Martin WaitzApr 11, 2007
  72. Linus TorvaldsApr 11, 2007
  73. Andy ParkinsApr 11, 2007
  74. Martin WaitzApr 11, 2007
  75. Linus TorvaldsApr 11, 2007
  76. Sam VilainApr 11, 2007
  77. Martin WaitzApr 11, 2007
  78. Brian GernhardtApr 12, 2007
  79. Josef WeidendorferApr 12, 2007
  80. Linus TorvaldsApr 10, 2007
  81. Alex RiesenApr 10, 2007
  82. Linus TorvaldsApr 10, 2007
  83. Alex RiesenApr 10, 2007
  84. Linus TorvaldsApr 10, 2007
  85. Alex RiesenApr 10, 2007
  86. Junio C HamanoApr 10, 2007
  87. Linus TorvaldsApr 10, 2007
  88. Junio C HamanoApr 10, 2007
  89. Sam RavnborgApr 10, 2007
  90. Junio C HamanoApr 10, 2007
  91. Nicolas PitreApr 10, 2007
  92. J. Bruce FieldsApr 15, 2007
  93. David KågedalApr 11, 2007
  94. Junio C HamanoApr 11, 2007
  95. J. Bruce FieldsApr 15, 2007
  96. Martin WaitzApr 11, 2007
  97. Alex RiesenApr 11, 2007
  98. Martin WaitzApr 11, 2007

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.