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

[PATCH 1/5] grep: perform some minor code and comment cleanups

From
DSDragan Simic <dsimic@manjaro.org>
Date
Mar 18, 2024, 17:03 UTC
Message-ID
<96b81f3573d3f29bb97e77d623be0d53cf8085b0.1710781235.git.dsimic@manjaro.org>
In-Reply-To
<cover.1710781235.git.dsimic@manjaro.org>

Move some variable definitions around, and reflow one comment block, to make the code a bit neater after spotting those slightly unpolished areas. There are no functional changes to the source code.

Signed-off-by: Dragan Simic <dsimic@manjaro.org>
---
 builtin/grep.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 982bcfc4b1df..af89c8b5cb19 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -623,13 +623,13 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
 		     struct tree_desc *tree, struct strbuf *base, int tn_len,
 		     int check_attr)
 {
-	struct repository *repo = opt->repo;
-	int hit = 0;
+	int hit = 0, name_base_len = 0;
+	int old_baselen = base->len;
 	enum interesting match = entry_not_interesting;
+	struct repository *repo = opt->repo;
 	struct name_entry entry;
-	int old_baselen = base->len;
 	struct strbuf name = STRBUF_INIT;
-	int name_base_len = 0;
+
 	if (repo->submodule_prefix) {
 		strbuf_addstr(&name, repo->submodule_prefix);
 		name_base_len = name.len;
@@ -890,19 +890,15 @@ static int pattern_callback(const struct option *opt, const char *arg,
 
 int cmd_grep(int argc, const char **argv, const char *prefix)
 {
-	int hit = 0;
+	int hit = 0, seen_dashdash = 0, use_index = 1;
 	int cached = 0, untracked = 0, opt_exclude = -1;
-	int seen_dashdash = 0;
 	int external_grep_allowed__ignored;
+	int i, dummy, allow_revs;
 	const char *show_in_pager = NULL, *default_pager = "dummy";
 	struct grep_opt opt;
 	struct object_array list = OBJECT_ARRAY_INIT;
 	struct pathspec pathspec;
 	struct string_list path_list = STRING_LIST_INIT_DUP;
-	int i;
-	int dummy;
-	int use_index = 1;
-	int allow_revs;
 
 	struct option options[] = {
 		OPT_BOOL(0, "cached", &cached,
@@ -1059,9 +1055,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		recurse_submodules = 0;
 
 	/*
-	 * skip a -- separator; we know it cannot be
-	 * separating revisions from pathnames if
-	 * we haven't even had any patterns yet
+	 * skip a -- separator; we know it cannot be separating revisions
+	 * from pathnames if we haven't even had any patterns yet
 	 */
 	if (argc > 0 && !opt.pattern_list && !strcmp(argv[0], "--")) {
 		argv++;
Previous: Dragan SimicNext: Eric Sunshine
Message 13 of 22 in “New config option for git-grep to include untracked files”
  1. 0/5 New config option for git-grep to include untracked filesDragan Simic, Mar 18, 2024
  2. 3/5 grep docs: describe --no-index furtherDragan Simic, Mar 18, 2024
  3. Junio C HamanoMar 19, 2024
  4. Dragan SimicMar 19, 2024
  5. 4/5 grep: introduce new config option to include untracked filesDragan Simic, Mar 18, 2024
  6. Junio C HamanoMar 19, 2024
  7. Dragan SimicMar 19, 2024
  8. Junio C HamanoMar 19, 2024
  9. Dragan SimicMar 19, 2024
  10. 2/5 grep docs: describe --recurse-submodules further and improve formatting a bitDragan Simic, Mar 18, 2024
  11. Eric SunshineMar 18, 2024
  12. Dragan SimicMar 18, 2024
  13. 1/5 grep: perform some minor code and comment cleanupsDragan Simic, Mar 18, 2024
  14. Eric SunshineMar 18, 2024
  15. Dragan SimicMar 18, 2024
  16. Junio C HamanoMar 19, 2024
  17. Dragan SimicMar 19, 2024
  18. 5/5 grep docs: describe new config option to include untracked filesDragan Simic, Mar 18, 2024
  19. Junio C HamanoMar 19, 2024
  20. Dragan SimicMar 19, 2024
  21. Junio C HamanoMar 19, 2024
  22. Dragan SimicMar 19, 2024

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.