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

[PATCH 11/12] grep: do not return early in cmd_grep() if there is no error

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 7, 2010, 12:09 UTC
Message-ID
<1267963785-473-12-git-send-email-pclouds@gmail.com>
In-Reply-To
<1267963785-473-1-git-send-email-pclouds@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/grep.c |   39 +++++++++++++++++----------------------
 1 files changed, 17 insertions(+), 22 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 40b9a93..b8a1d5c 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -568,7 +568,6 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
 		if (hit && opt->status_only)
 			break;
 	}
-	free_grep_patterns(opt);
 	return hit;
 }
 
@@ -969,7 +968,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	}
 
 	if (!use_index) {
-		int hit;
 		if (cached)
 			die("--cached cannot be used with --no-index.");
 		if (list.nr)
@@ -977,35 +975,32 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 		hit = grep_directory(&opt, paths);
 		if (use_threads)
 			hit |= wait_all();
-		return !hit;
 	}
-
-	if (!list.nr) {
-		int hit;
+	else if (!list.nr) {
 		if (!cached)
 			setup_work_tree();
-
 		hit = grep_cache(&opt, paths, cached);
 		if (use_threads)
 			hit |= wait_all();
-		return !hit;
+		free_grep_patterns(&opt);
 	}
-
-	if (cached)
-		die("both --cached and trees are given.");
-
-	for (i = 0; i < list.nr; i++) {
-		struct object *real_obj;
-		real_obj = deref_tag(list.objects[i].item, NULL, 0);
-		if (grep_object(&opt, paths, real_obj, list.objects[i].name)) {
-			hit = 1;
-			if (opt.status_only)
-				break;
+	else {
+		if (cached)
+			die("both --cached and trees are given.");
+
+		for (i = 0; i < list.nr; i++) {
+			struct object *real_obj;
+			real_obj = deref_tag(list.objects[i].item, NULL, 0);
+			if (grep_object(&opt, paths, real_obj, list.objects[i].name)) {
+				hit = 1;
+				if (opt.status_only)
+					break;
+			}
 		}
+		if (use_threads)
+			hit |= wait_all();
+		free_grep_patterns(&opt);
 	}
 
-	if (use_threads)
-		hit |= wait_all();
-	free_grep_patterns(&opt);
 	return !hit;
 }
-- 
1.7.0.1.370.gd3c5
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 12 of 24 in “Support columinized output in tag/branch/ls-files/grep”
  1. 00/12 Support columinized output in tag/branch/ls-files/grepNguyễn Thái Ngọc Duy, Mar 7, 2010
  2. 01/12 Move term_columns() to pager.cNguyễn Thái Ngọc Duy, Mar 7, 2010
  3. 02/12 setup_pager(): save terminal width before redirecting stdoutNguyễn Thái Ngọc Duy, Mar 7, 2010
  4. 03/12 Add columnizerNguyễn Thái Ngọc Duy, Mar 7, 2010
  5. 04/12 help: use columnizerNguyễn Thái Ngọc Duy, Mar 7, 2010
  6. 05/12 Add builtin command "column"Nguyễn Thái Ngọc Duy, Mar 7, 2010
  7. 06/12 Add helpers to redirect stdout to "git column"Nguyễn Thái Ngọc Duy, Mar 7, 2010
  8. 07/12 add core.columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  9. 08/12 tag: support column output with --columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  10. 09/12 branch: support column output with --columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  11. 10/12 ls-files: support column output with --columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  12. 11/12 grep: do not return early in cmd_grep() if there is no errorNguyễn Thái Ngọc Duy, Mar 7, 2010
  13. 12/12 grep: support column output with --columnsNguyễn Thái Ngọc Duy, Mar 7, 2010
  14. René ScharfeMar 8, 2010
  15. Nguyen Thai Ngoc DuyMar 8, 2010
  16. René ScharfeMar 9, 2010
  17. Nguyen Thai Ngoc DuyMar 10, 2010
  18. Johannes SixtMar 10, 2010
  19. Nguyen Thai Ngoc DuyMar 10, 2010
  20. René ScharfeMar 11, 2010
  21. Nguyen Thai Ngoc DuyMar 12, 2010
  22. Junio C HamanoMar 8, 2010
  23. Nguyen Thai Ngoc DuyMar 9, 2010
  24. Junio C HamanoMar 9, 2010

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.