From: Stephen Boyd <bebarino@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/4] write-tree: migrate to parse-options
Date: Tue, 7 Jul 2009 22:15:38 -0700 [thread overview]
Message-ID: <1247030141-11695-2-git-send-email-bebarino@gmail.com> (raw)
In-Reply-To: <1247030141-11695-1-git-send-email-bebarino@gmail.com>
A check for extra options has been dropped, it could never be triggered
in the original code as the usage message would be printed instead.
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
---
For historical purposes (and those interested), the die() became dead
code in commit 6bd2035 (write-tree: --prefix=<path> 2006-04-26) when
the line if (argc == 2) was changed to a while loop.
builtin-write-tree.c | 40 +++++++++++++++++++---------------------
1 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/builtin-write-tree.c b/builtin-write-tree.c
index 3a24ce8..b223af4 100644
--- a/builtin-write-tree.c
+++ b/builtin-write-tree.c
@@ -7,9 +7,12 @@
#include "cache.h"
#include "tree.h"
#include "cache-tree.h"
+#include "parse-options.h"
-static const char write_tree_usage[] =
-"git write-tree [--missing-ok] [--prefix=<prefix>/]";
+static const char * const write_tree_usage[] = {
+ "git write-tree [--missing-ok] [--prefix=<prefix>/]",
+ NULL
+};
int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
{
@@ -17,27 +20,22 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
const char *prefix = NULL;
unsigned char sha1[20];
const char *me = "git-write-tree";
+ struct option write_tree_options[] = {
+ OPT_BIT(0, "missing-ok", &flags, "allow missing objects",
+ WRITE_TREE_MISSING_OK),
+ { OPTION_STRING, 0, "prefix", &prefix, "<prefix>/",
+ "write tree object for a subdirectory <prefix>" ,
+ PARSE_OPT_LITERAL_ARGHELP },
+ { OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
+ "only useful for debugging",
+ PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
+ WRITE_TREE_IGNORE_CACHE_TREE },
+ OPT_END()
+ };
git_config(git_default_config, NULL);
- while (1 < argc) {
- const char *arg = argv[1];
- if (!strcmp(arg, "--missing-ok"))
- flags |= WRITE_TREE_MISSING_OK;
- else if (!prefixcmp(arg, "--prefix="))
- prefix = arg + 9;
- else if (!prefixcmp(arg, "--ignore-cache-tree"))
- /*
- * This is only useful for debugging, so I
- * do not bother documenting it.
- */
- flags |= WRITE_TREE_IGNORE_CACHE_TREE;
- else
- usage(write_tree_usage);
- argc--; argv++;
- }
-
- if (argc > 2)
- die("too many options");
+ argc = parse_options(argc, argv, unused_prefix, write_tree_options,
+ write_tree_usage, 0);
ret = write_cache_as_tree(sha1, flags, prefix);
switch (ret) {
--
1.6.3.3.385.g60647
next prev parent reply other threads:[~2009-07-08 5:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-08 5:15 [PATCH 0/4] Migrate simple builtins to parse-options Stephen Boyd
2009-07-08 5:15 ` Stephen Boyd [this message]
2009-07-08 5:15 ` [PATCH 2/4] tag-verify: migrate " Stephen Boyd
2009-07-08 5:15 ` [PATCH 3/4] verify-pack: " Stephen Boyd
2009-07-08 5:15 ` [PATCH 4/4] prune-packed: " Stephen Boyd
2009-07-09 10:51 ` Johannes Schindelin
2009-07-09 15:55 ` Stephen Boyd
2009-07-09 16:05 ` Stephen Boyd
2009-07-09 16:01 ` [PATCH 3/4] verify-pack: " Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1247030141-11695-2-git-send-email-bebarino@gmail.com \
--to=bebarino@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).