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

[PATCH v4 3/6] grep: add submodules as a grep source type

From
BWBrandon Williams <bmwill@google.com>
Date
Nov 18, 2016, 19:58 UTC
Message-ID
<1479499135-64269-4-git-send-email-bmwill@google.com>
In-Reply-To
<1479499135-64269-1-git-send-email-bmwill@google.com>

Add `GREP_SOURCE_SUBMODULE` as a grep_source type and cases for this new type in the various switch statements in grep.c.

When initializing a grep_source with type `GREP_SOURCE_SUBMODULE` the identifier can either be NULL (to indicate that the working tree will be used) or a SHA1 (the REV of the submodule to be grep'd). If the identifier is a SHA1 then we want to fall through to the `GREP_SOURCE_SHA1` case to handle the copying of the SHA1.

Signed-off-by: Brandon Williams <bmwill@google.com>
---
 grep.c | 16 +++++++++++++++-
 grep.h |  1 +
 2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/grep.c b/grep.c
index 1194d35..0dbdc1d 100644
--- a/grep.c
+++ b/grep.c
@@ -1735,12 +1735,23 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
 	case GREP_SOURCE_FILE:
 		gs->identifier = xstrdup(identifier);
 		break;
+	case GREP_SOURCE_SUBMODULE:
+		if (!identifier) {
+			gs->identifier = NULL;
+			break;
+		}
+		/*
+		 * FALL THROUGH
+		 * If the identifier is non-NULL (in the submodule case) it
+		 * will be a SHA1 that needs to be copied.
+		 */
 	case GREP_SOURCE_SHA1:
 		gs->identifier = xmalloc(20);
 		hashcpy(gs->identifier, identifier);
 		break;
 	case GREP_SOURCE_BUF:
 		gs->identifier = NULL;
+		break;
 	}
 }
 
@@ -1760,6 +1771,7 @@ void grep_source_clear_data(struct grep_source *gs)
 	switch (gs->type) {
 	case GREP_SOURCE_FILE:
 	case GREP_SOURCE_SHA1:
+	case GREP_SOURCE_SUBMODULE:
 		free(gs->buf);
 		gs->buf = NULL;
 		gs->size = 0;
@@ -1831,8 +1843,10 @@ static int grep_source_load(struct grep_source *gs)
 		return grep_source_load_sha1(gs);
 	case GREP_SOURCE_BUF:
 		return gs->buf ? 0 : -1;
+	case GREP_SOURCE_SUBMODULE:
+		break;
 	}
-	die("BUG: invalid grep_source type");
+	die("BUG: invalid grep_source type to load");
 }
 
 void grep_source_load_driver(struct grep_source *gs)
diff --git a/grep.h b/grep.h
index 5856a23..267534c 100644
--- a/grep.h
+++ b/grep.h
@@ -161,6 +161,7 @@ struct grep_source {
 		GREP_SOURCE_SHA1,
 		GREP_SOURCE_FILE,
 		GREP_SOURCE_BUF,
+		GREP_SOURCE_SUBMODULE,
 	} type;
 	void *identifier;
 
-- 
2.8.0.rc3.226.g39d4020
Previous: Brandon WilliamsNext: Junio C Hamano
Message 59 of 126 in “recursively grep across submodules”
  1. 0/5 recursively grep across submodulesBrandon Williams, Oct 27, 2016
  2. 1/5 submodules: add helper functions to determine presence of submodulesBrandon Williams, Oct 27, 2016
  3. 3/5 grep: add submodules as a grep source typeBrandon Williams, Oct 27, 2016
  4. 2/5 submodules: load gitmodules file from commit sha1Brandon Williams, Oct 27, 2016
  5. 4/5 grep: optionally recurse into submodulesBrandon Williams, Oct 27, 2016
  6. Jonathan TanNov 5, 2016
  7. 5/5 grep: enable recurse-submodules to work on <tree> objectsBrandon Williams, Oct 27, 2016
  8. Brandon WilliamsOct 28, 2016
  9. Junio C HamanoOct 27, 2016
  10. Stefan BellerOct 28, 2016
  11. Junio C HamanoOct 28, 2016
  12. Stefan BellerOct 28, 2016
  13. Philip OakleyOct 28, 2016
  14. Brandon WilliamsOct 28, 2016
  15. Junio C HamanoOct 28, 2016
  16. 0/6 recursively grep across submodulesBrandon Williams, Oct 31, 2016
  17. 1/6 submodules: add helper functions to determine presence of submodulesBrandon Williams, Oct 31, 2016
  18. Stefan BellerOct 31, 2016
  19. Junio C HamanoNov 1, 2016
  20. Brandon WilliamsNov 1, 2016
  21. Stefan BellerNov 1, 2016
  22. Jacob KellerNov 6, 2016
  23. Brandon WilliamsNov 1, 2016
  24. Jonathan TanNov 5, 2016
  25. 2/6 submodules: load gitmodules file from commit sha1Brandon Williams, Oct 31, 2016
  26. Stefan BellerNov 1, 2016
  27. 3/6 grep: add submodules as a grep source typeBrandon Williams, Oct 31, 2016
  28. Stefan BellerNov 1, 2016
  29. Junio C HamanoNov 1, 2016
  30. 4/6 grep: optionally recurse into submodulesBrandon Williams, Oct 31, 2016
  31. Stefan BellerNov 1, 2016
  32. Brandon WilliamsNov 1, 2016
  33. 6/6 grep: search history of moved submodulesBrandon Williams, Oct 31, 2016
  34. 5/6 grep: enable recurse-submodules to work on <tree> objectsBrandon Williams, Oct 31, 2016
  35. Jonathan TanNov 11, 2016
  36. 0/6 recursively grep across submodulesBrandon Williams, Nov 11, 2016
  37. 2/6 submodules: load gitmodules file from commit sha1Brandon Williams, Nov 11, 2016
  38. Stefan BellerNov 12, 2016
  39. 5/6 grep: enable recurse-submodules to work on <tree> objectsBrandon Williams, Nov 11, 2016
  40. Junio C HamanoNov 14, 2016
  41. Jonathan TanNov 14, 2016
  42. Junio C HamanoNov 14, 2016
  43. Jonathan TanNov 14, 2016
  44. Brandon WilliamsNov 14, 2016
  45. Stefan BellerNov 16, 2016
  46. Brandon WilliamsNov 17, 2016
  47. 1/6 submodules: add helper functions to determine presence of submodulesBrandon Williams, Nov 11, 2016
  48. Stefan BellerNov 15, 2016
  49. 6/6 grep: search history of moved submodulesBrandon Williams, Nov 11, 2016
  50. Stefan BellerNov 12, 2016
  51. Brandon WilliamsNov 14, 2016
  52. 4/6 grep: optionally recurse into submodulesBrandon Williams, Nov 11, 2016
  53. Stefan BellerNov 16, 2016
  54. Brandon WilliamsNov 17, 2016
  55. 3/6 grep: add submodules as a grep source typeBrandon Williams, Nov 11, 2016
  56. Stefan BellerNov 15, 2016
  57. 0/6 recursively grep across submodulesBrandon Williams, Nov 18, 2016
  58. 1/6 submodules: add helper functions to determine presence of submodulesBrandon Williams, Nov 18, 2016
  59. 3/6 grep: add submodules as a grep source typeBrandon Williams, Nov 18, 2016
  60. Junio C HamanoNov 18, 2016
  61. Brandon WilliamsNov 18, 2016
  62. 2/6 submodules: load gitmodules file from commit sha1Brandon Williams, Nov 18, 2016
  63. 5/6 grep: enable recurse-submodules to work on <tree> objectsBrandon Williams, Nov 18, 2016
  64. Junio C HamanoNov 18, 2016
  65. Brandon WilliamsNov 18, 2016
  66. Brandon WilliamsNov 21, 2016
  67. 6/6 grep: search history of moved submodulesBrandon Williams, Nov 18, 2016
  68. 4/6 grep: optionally recurse into submodulesBrandon Williams, Nov 18, 2016
  69. Junio C HamanoNov 18, 2016
  70. Junio C HamanoNov 18, 2016
  71. Junio C HamanoNov 18, 2016
  72. Brandon WilliamsNov 18, 2016
  73. Stefan BellerNov 18, 2016
  74. 0/6 recursively grep across submodulesBrandon Williams, Nov 22, 2016
  75. 3/6 grep: add submodules as a grep source typeBrandon Williams, Nov 22, 2016
  76. 1/6 submodules: add helper functions to determine presence of submodulesBrandon Williams, Nov 22, 2016
  77. 5/6 grep: enable recurse-submodules to work on <tree> objectsBrandon Williams, Nov 22, 2016
  78. Junio C HamanoNov 22, 2016
  79. Brandon WilliamsNov 22, 2016
  80. Brandon WilliamsNov 22, 2016
  81. Junio C HamanoNov 22, 2016
  82. Brandon WilliamsNov 22, 2016
  83. 6/6 grep: search history of moved submodulesBrandon Williams, Nov 22, 2016
  84. 2/6 submodules: load gitmodules file from commit sha1Brandon Williams, Nov 22, 2016
  85. 4/6 grep: optionally recurse into submodulesBrandon Williams, Nov 22, 2016
  86. 0/6 recursively grep across submodulesBrandon Williams, Dec 1, 2016
  87. 1/6 submodules: add helper functions to determine presence of submodulesBrandon Williams, Dec 1, 2016
  88. Jeff KingDec 1, 2016
  89. Stefan BellerDec 1, 2016
  90. Junio C HamanoDec 1, 2016
  91. Jeff KingDec 1, 2016
  92. Brandon WilliamsDec 1, 2016
  93. Brandon WilliamsDec 1, 2016
  94. Jeff KingDec 1, 2016
  95. Stefan BellerDec 1, 2016
  96. Jeff KingDec 1, 2016
  97. Brandon WilliamsDec 2, 2016
  98. Jacob KellerDec 2, 2016
  99. Brandon WilliamsDec 2, 2016
  100. Jacob KellerDec 2, 2016
  101. Stefan BellerDec 2, 2016
  102. Jacob KellerDec 2, 2016
  103. Brandon WilliamsDec 2, 2016
  104. Jeff KingDec 2, 2016
  105. Brandon WilliamsDec 3, 2016
  106. 6/6 grep: search history of moved submodulesBrandon Williams, Dec 1, 2016
  107. 2/6 submodules: load gitmodules file from commit sha1Brandon Williams, Dec 1, 2016
  108. 3/6 grep: add submodules as a grep source typeBrandon Williams, Dec 1, 2016
  109. 4/6 grep: optionally recurse into submodulesBrandon Williams, Dec 1, 2016
  110. 5/6 grep: enable recurse-submodules to work on <tree> objectsBrandon Williams, Dec 1, 2016
  111. Johannes SixtDec 1, 2016
  112. Brandon WilliamsDec 1, 2016
  113. Junio C HamanoDec 1, 2016
  114. Jeff KingDec 1, 2016
  115. Jeff KingDec 1, 2016
  116. Brandon WilliamsDec 1, 2016
  117. Jeff KingDec 1, 2016
  118. 0/7 recursively grep across submodulesBrandon Williams, Dec 16, 2016
  119. 1/7 submodules: add helper to determine if a submodule is populatedBrandon Williams, Dec 16, 2016
  120. 3/7 submodules: load gitmodules file from commit sha1Brandon Williams, Dec 16, 2016
  121. 2/7 submodules: add helper to determine if a submodule is initializedBrandon Williams, Dec 16, 2016
  122. 5/7 grep: optionally recurse into submodulesBrandon Williams, Dec 16, 2016
  123. 6/7 grep: enable recurse-submodules to work on <tree> objectsBrandon Williams, Dec 16, 2016
  124. 4/7 grep: add submodules as a grep source typeBrandon Williams, Dec 16, 2016
  125. 7/7 grep: search history of moved submodulesBrandon Williams, Dec 16, 2016
  126. Junio C HamanoDec 16, 2016

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.