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

[PATCH] grep: use OPT_INTEGER_F for --max-depth

From
René Scharfe <l.s.r@web.de>
Date
Sep 2, 2023, 18:54 UTC
Message-ID
<4d2eb736-4f34-18f8-2eb7-20e7f7b8c2f8@web.de>

a91f453f64 (grep: Add --max-depth option., 2009-07-22) added the option --max-depth, defining it using a positional struct option initializer of type OPTION_INTEGER. It also sets defval to 1 for some reason, but that value would only be used if the flag PARSE_OPT_OPTARG was given.

Use the macro OPT_INTEGER_F instead to standardize the definition and specify only the necessary values. This also normalizes argh to N_("n") as a side-effect, which is OK.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/grep.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 50e712a184..f5f5f6dbe1 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -924,9 +924,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			 N_("process binary files with textconv filters")),
 		OPT_SET_INT('r', "recursive", &opt.max_depth,
 			    N_("search in subdirectories (default)"), -1),
-		{ OPTION_INTEGER, 0, "max-depth", &opt.max_depth, N_("depth"),
-			N_("descend at most <depth> levels"), PARSE_OPT_NONEG,
-			NULL, 1 },
+		OPT_INTEGER_F(0, "max-depth", &opt.max_depth,
+			N_("descend at most <n> levels"), PARSE_OPT_NONEG),
 		OPT_GROUP(""),
 		OPT_SET_INT('E', "extended-regexp", &opt.pattern_type_option,
 			    N_("use extended POSIX regular expressions"),
--
2.42.0
Next: Jeff King
Message 1 of 7 in “grep: use OPT_INTEGER_F for --max-depth”
  1. grep: use OPT_INTEGER_F for --max-depthRené Scharfe, Sep 2, 2023
  2. Jeff KingSep 5, 2023
  3. René ScharfeSep 7, 2023
  4. Jeff KingSep 7, 2023
  5. René ScharfeSep 8, 2023
  6. René ScharfeSep 9, 2023
  7. Jeff KingSep 12, 2023

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.