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

[PATCH 10/13] cat-file: report an error on multiple --batch options

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

The options callback for --batch and --batch-check detects when the two mutually incompatible options are used. But it simply returns an error code to parse-options, meaning the program will quit without any kind of message to the user.

Instead, let's use error() to print something and return -1. Note that this flips the error return from 1 to -1, but negative values are more idiomatic here (and parse-options treats them the same).

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/cat-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 4a5289079c..0f6b692df6 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -596,7 +596,7 @@ static int batch_option_callback(const struct option *opt,
 	struct batch_options *bo = opt->value;
 
 	if (bo->enabled) {
-		return 1;
+		return error(_("only one batch option may be specified"));
 	}
 
 	bo->enabled = 1;
-- 
2.19.1.1505.g9cd28186cf
Previous: Jeff KingNext: Jeff King
Message 13 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.