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

[PATCH 2/6] mktree: use parse-options

From
Junio C Hamano <gitster@pobox.com>
Date
May 10, 2009, 18:49 UTC
Message-ID
<1241981391-19639-3-git-send-email-gitster@pobox.com>
In-Reply-To
<1241981391-19639-2-git-send-email-gitster@pobox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-mktree.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/builtin-mktree.c b/builtin-mktree.c
index 3d05427..2b3145b 100644
--- a/builtin-mktree.c
+++ b/builtin-mktree.c
@@ -6,6 +6,7 @@
 #include "builtin.h"
 #include "quote.h"
 #include "tree.h"
+#include "parse-options.h"
 
 static struct treeent {
 	unsigned mode;
@@ -61,7 +62,10 @@ static void write_tree(unsigned char *sha1)
 	write_sha1_file(buf.buf, buf.len, tree_type, sha1);
 }
 
-static const char mktree_usage[] = "git mktree [-z]";
+static const char *mktree_usage[] = {
+	"git mktree [-z]",
+	NULL
+};
 
 int cmd_mktree(int ac, const char **av, const char *prefix)
 {
@@ -69,16 +73,12 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
 	struct strbuf p_uq = STRBUF_INIT;
 	unsigned char sha1[20];
 	int line_termination = '\n';
+	const struct option option[] = {
+		OPT_SET_INT('z', NULL, &line_termination, "input is NUL terminated", '\0'),
+		OPT_END()
+	};
 
-	while ((1 < ac) && av[1][0] == '-') {
-		const char *arg = av[1];
-		if (!strcmp("-z", arg))
-			line_termination = 0;
-		else
-			usage(mktree_usage);
-		ac--;
-		av++;
-	}
+	ac = parse_options(ac, av, option, mktree_usage, 0);
 
 	while (strbuf_getline(&sb, stdin, line_termination) != EOF) {
 		char *ptr, *ntr;
-- 
1.6.3.9.g6345d
Previous: Junio C HamanoNext: Junio C Hamano
Message 9 of 16 in “questions about git-mktree”
  1. Jon SeymourMay 10, 2009
  2. Uwe Kleine-KönigMay 10, 2009
  3. A Large Angry SCMMay 10, 2009
  4. Jakub NarebskiMay 10, 2009
  5. Junio C HamanoMay 10, 2009
  6. Junio C HamanoMay 10, 2009
  7. 0/6 Modernize mktree somewhatJunio C Hamano, May 10, 2009
  8. 1/6 build-in git-mktreeJunio C Hamano, May 10, 2009
  9. 2/6 mktree: use parse-optionsJunio C Hamano, May 10, 2009
  10. 3/6 builtin-mktree.c: use a helper function to handle one line of inputJunio C Hamano, May 10, 2009
  11. 4/6 mktree: do not barf on a submodule commitJunio C Hamano, May 10, 2009
  12. 5/6 t1010: add mktree testJunio C Hamano, May 10, 2009
  13. 6/6 mktree --missing: allow missing objectsJunio C Hamano, May 10, 2009
  14. René ScharfeMay 10, 2009
  15. Junio C HamanoMay 11, 2009
  16. Josh MicichMay 10, 2009

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.