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

[PATCH 11/13] apply: return -1 from option callback instead of calling exit(1)

From
Jeff King <peff@peff.net>
Date
Nov 5, 2018, 06:43 UTC
Message-ID
<20181105064358.GK25864@sigill.intra.peff.net>
In-Reply-To
<20181105063718.GA24877@sigill.intra.peff.net>

The option callback for "apply --whitespace" exits with status "1" on error. It makes more sense for it to just return an error to parse-options. That code will exit, too, but it will use status "129" that is customary for option errors.

The exit() dates back to aaf6c447aa (builtin/apply: make parse_whitespace_option() return -1 instead of die()ing, 2016-08-08). That commit gives no reason why we'd prefer the current exit status (it looks like it was just bumping the "die" up a level in the callstack, but did not go as far as it could have).

Signed-off-by: Jeff King <peff@peff.net>
---
 apply.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apply.c b/apply.c
index d1ca6addeb..c4c9f849b1 100644
--- a/apply.c
+++ b/apply.c
@@ -4812,7 +4812,7 @@ static int apply_option_parse_whitespace(const struct option *opt,
 	struct apply_state *state = opt->value;
 	state->whitespace_option = arg;
 	if (parse_whitespace_option(state, arg))
-		exit(1);
+		return -1;
 	return 0;
 }
 
-- 
2.19.1.1505.g9cd28186cf
Previous: Jeff KingNext: Jeff King
Message 14 of 21 in “parseopt fixes from -Wunused-parameters”
  1. 0/13 parseopt fixes from -Wunused-parametersJeff King, Nov 5, 2018
  2. 01/13 apply: mark include/exclude options as NONEGJeff King, Nov 5, 2018
  3. Junio C HamanoNov 5, 2018
  4. 02/13 am: handle --no-patch-format optionJeff King, Nov 5, 2018
  5. Junio C HamanoNov 5, 2018
  6. 03/13 ls-files: mark exclude options as NONEGJeff King, Nov 5, 2018
  7. 04/13 pack-objects: mark index-version option as NONEGJeff King, Nov 5, 2018
  8. 05/13 cat-file: mark batch options with NONEGJeff King, Nov 5, 2018
  9. 06/13 status: mark --find-renames option with NONEGJeff King, Nov 5, 2018
  10. 07/13 format-patch: mark "--no-numbered" option with NONEGJeff King, Nov 5, 2018
  11. 08/13 show-branch: mark --reflog option as NONEGJeff King, Nov 5, 2018
  12. 09/13 tag: mark "--message" option with NONEGJeff King, Nov 5, 2018
  13. 10/13 cat-file: report an error on multiple --batch optionsJeff King, Nov 5, 2018
  14. 11/13 apply: return -1 from option callback instead of calling exit(1)Jeff King, Nov 5, 2018
  15. 12/13 parse-options: drop OPT_DATE()Jeff King, Nov 5, 2018
  16. parse-options: deprecate OPT_DATECarlo Marcelo Arenas Belón, Nov 5, 2018
  17. Jeff KingNov 5, 2018
  18. 13/13 assert NOARG/NONEG behavior of parse-options callbacksJeff King, Nov 5, 2018
  19. Duy NguyenNov 5, 2018
  20. Jeff KingNov 5, 2018
  21. Duy NguyenNov 5, 2018

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.