{"thread":{"id":"20053","subject":"[PATCH 2/4] tag-verify: migrate to parse-options","startedAt":"2009-07-08T05:15:37Z","lastAt":"2009-07-09T16:05:45Z","messageCount":9,"participants":["Stephen Boyd","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"117605","messageId":"1247030141-11695-1-git-send-email-bebarino@gmail.com","threadId":"20053","inReplyTo":null,"subject":"[PATCH 0/4] Migrate simple builtins to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-08T05:15:37Z","receivedAt":"2009-07-08T05:15:37Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"These are builtins with options that are fairly simple and the number\nof options is small so code review will hopefully be easier.\n\nStephen Boyd (4):\n  write-tree: migrate to parse-options\n  tag-verify: migrate to parse-options\n  verify-pack: migrate to parse-options\n  prune-packed: migrate to parse-options\n\n Documentation/git-prune-packed.txt |    4 ++-\n Documentation/git-verify-pack.txt  |    3 +-\n builtin-prune-packed.c             |   29 ++++++++++---------------\n builtin-verify-pack.c              |   40 ++++++++++++++++-------------------\n builtin-verify-tag.c               |   21 ++++++++++--------\n builtin-write-tree.c               |   40 +++++++++++++++++------------------\n 6 files changed, 66 insertions(+), 71 deletions(-)\n"},{"id":"117604","messageId":"1247030141-11695-2-git-send-email-bebarino@gmail.com","threadId":"20053","inReplyTo":"1247030141-11695-1-git-send-email-bebarino@gmail.com","subject":"[PATCH 1/4] write-tree: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-08T05:15:38Z","receivedAt":"2009-07-08T05:15:38Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"A check for extra options has been dropped, it could never be triggered\nin the original code as the usage message would be printed instead.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nFor historical purposes (and those interested), the die() became dead\ncode in commit 6bd2035 (write-tree: --prefix=<path> 2006-04-26) when\nthe line if (argc == 2) was changed to a while loop.\n\n builtin-write-tree.c |   40 +++++++++++++++++++---------------------\n 1 files changed, 19 insertions(+), 21 deletions(-)\n\ndiff --git a/builtin-write-tree.c b/builtin-write-tree.c\nindex 3a24ce8..b223af4 100644\n--- a/builtin-write-tree.c\n+++ b/builtin-write-tree.c\n@@ -7,9 +7,12 @@\n #include \"cache.h\"\n #include \"tree.h\"\n #include \"cache-tree.h\"\n+#include \"parse-options.h\"\n \n-static const char write_tree_usage[] =\n-\"git write-tree [--missing-ok] [--prefix=<prefix>/]\";\n+static const char * const write_tree_usage[] = {\n+\t\"git write-tree [--missing-ok] [--prefix=<prefix>/]\",\n+\tNULL\n+};\n \n int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)\n {\n@@ -17,27 +20,22 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)\n \tconst char *prefix = NULL;\n \tunsigned char sha1[20];\n \tconst char *me = \"git-write-tree\";\n+\tstruct option write_tree_options[] = {\n+\t\tOPT_BIT(0, \"missing-ok\", &flags, \"allow missing objects\",\n+\t\t\tWRITE_TREE_MISSING_OK),\n+\t\t{ OPTION_STRING, 0, \"prefix\", &prefix, \"<prefix>/\",\n+\t\t  \"write tree object for a subdirectory <prefix>\" ,\n+\t\t  PARSE_OPT_LITERAL_ARGHELP },\n+\t\t{ OPTION_BIT, 0, \"ignore-cache-tree\", &flags, NULL,\n+\t\t  \"only useful for debugging\",\n+\t\t  PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,\n+\t\t  WRITE_TREE_IGNORE_CACHE_TREE },\n+\t\tOPT_END()\n+\t};\n \n \tgit_config(git_default_config, NULL);\n-\twhile (1 < argc) {\n-\t\tconst char *arg = argv[1];\n-\t\tif (!strcmp(arg, \"--missing-ok\"))\n-\t\t\tflags |= WRITE_TREE_MISSING_OK;\n-\t\telse if (!prefixcmp(arg, \"--prefix=\"))\n-\t\t\tprefix = arg + 9;\n-\t\telse if (!prefixcmp(arg, \"--ignore-cache-tree\"))\n-\t\t\t/*\n-\t\t\t * This is only useful for debugging, so I\n-\t\t\t * do not bother documenting it.\n-\t\t\t */\n-\t\t\tflags |= WRITE_TREE_IGNORE_CACHE_TREE;\n-\t\telse\n-\t\t\tusage(write_tree_usage);\n-\t\targc--; argv++;\n-\t}\n-\n-\tif (argc > 2)\n-\t\tdie(\"too many options\");\n+\targc = parse_options(argc, argv, unused_prefix, write_tree_options,\n+\t\t\t     write_tree_usage, 0);\n \n \tret = write_cache_as_tree(sha1, flags, prefix);\n \tswitch (ret) {\n-- \n1.6.3.3.385.g60647\n"},{"id":"117602","messageId":"1247030141-11695-3-git-send-email-bebarino@gmail.com","threadId":"20053","inReplyTo":"1247030141-11695-2-git-send-email-bebarino@gmail.com","subject":"[PATCH 2/4] tag-verify: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-08T05:15:39Z","receivedAt":"2009-07-08T05:15:39Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Signed-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n\nIt may be nicer to die with a message like \"Must give a tag to verify\"\nor something when a tag isn't given, but that could probably be a\nlater patch.\n\n builtin-verify-tag.c |   21 ++++++++++++---------\n 1 files changed, 12 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin-verify-tag.c b/builtin-verify-tag.c\nindex 7f7fda4..9f482c2 100644\n--- a/builtin-verify-tag.c\n+++ b/builtin-verify-tag.c\n@@ -10,9 +10,12 @@\n #include \"tag.h\"\n #include \"run-command.h\"\n #include <signal.h>\n+#include \"parse-options.h\"\n \n-static const char builtin_verify_tag_usage[] =\n-\t\t\"git verify-tag [-v|--verbose] <tag>...\";\n+static const char * const verify_tag_usage[] = {\n+\t\t\"git verify-tag [-v|--verbose] <tag>...\",\n+\t\tNULL\n+};\n \n #define PGP_SIGNATURE \"-----BEGIN PGP SIGNATURE-----\"\n \n@@ -89,17 +92,17 @@ static int verify_tag(const char *name, int verbose)\n int cmd_verify_tag(int argc, const char **argv, const char *prefix)\n {\n \tint i = 1, verbose = 0, had_error = 0;\n+\tconst struct option verify_tag_options[] = {\n+\t\tOPT__VERBOSE(&verbose),\n+\t\tOPT_END()\n+\t};\n \n \tgit_config(git_default_config, NULL);\n \n-\tif (argc > 1 &&\n-\t    (!strcmp(argv[i], \"-v\") || !strcmp(argv[i], \"--verbose\"))) {\n-\t\tverbose = 1;\n-\t\ti++;\n-\t}\n-\n+\targc = parse_options(argc, argv, prefix, verify_tag_options,\n+\t\t\t     verify_tag_usage, PARSE_OPT_KEEP_ARGV0);\n \tif (argc <= i)\n-\t\tusage(builtin_verify_tag_usage);\n+\t\tusage_with_options(verify_tag_usage, verify_tag_options);\n \n \t/* sometimes the program was terminated because this signal\n \t * was received in the process of writing the gpg input: */\n-- \n1.6.3.3.385.g60647\n"},{"id":"117603","messageId":"1247030141-11695-4-git-send-email-bebarino@gmail.com","threadId":"20053","inReplyTo":"1247030141-11695-3-git-send-email-bebarino@gmail.com","subject":"[PATCH 3/4] verify-pack: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-08T05:15:40Z","receivedAt":"2009-07-08T05:15:40Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"OPT__VERBOSE adds a --verbose option, so document the new addition.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n Documentation/git-verify-pack.txt |    3 +-\n builtin-verify-pack.c             |   40 ++++++++++++++++--------------------\n 2 files changed, 20 insertions(+), 23 deletions(-)\n\ndiff --git a/Documentation/git-verify-pack.txt b/Documentation/git-verify-pack.txt\nindex c861163..d791a80 100644\n--- a/Documentation/git-verify-pack.txt\n+++ b/Documentation/git-verify-pack.txt\n@@ -8,7 +8,7 @@ git-verify-pack - Validate packed git archive files\n \n SYNOPSIS\n --------\n-'git verify-pack' [-v] [--] <pack>.idx ...\n+'git verify-pack' [-v|--verbose] [--] <pack>.idx ...\n \n \n DESCRIPTION\n@@ -23,6 +23,7 @@ OPTIONS\n \tThe idx files to verify.\n \n -v::\n+--verbose::\n \tAfter verifying the pack, show list of objects contained\n \tin the pack.\n \\--::\ndiff --git a/builtin-verify-pack.c b/builtin-verify-pack.c\nindex 0ee0a9a..ebd6dff 100644\n--- a/builtin-verify-pack.c\n+++ b/builtin-verify-pack.c\n@@ -2,6 +2,7 @@\n #include \"cache.h\"\n #include \"pack.h\"\n #include \"pack-revindex.h\"\n+#include \"parse-options.h\"\n \n #define MAX_CHAIN 50\n \n@@ -107,36 +108,31 @@ static int verify_one_pack(const char *path, int verbose)\n \treturn err;\n }\n \n-static const char verify_pack_usage[] = \"git verify-pack [-v] <pack>...\";\n+static const char * const verify_pack_usage[] = {\n+\t\"git verify-pack [-v|--verbose] <pack>...\",\n+\tNULL\n+};\n \n int cmd_verify_pack(int argc, const char **argv, const char *prefix)\n {\n \tint err = 0;\n \tint verbose = 0;\n-\tint no_more_options = 0;\n-\tint nothing_done = 1;\n+\tint i;\n+\tconst struct option verify_pack_options[] = {\n+\t\tOPT__VERBOSE(&verbose),\n+\t\tOPT_END()\n+\t};\n \n \tgit_config(git_default_config, NULL);\n-\twhile (1 < argc) {\n-\t\tif (!no_more_options && argv[1][0] == '-') {\n-\t\t\tif (!strcmp(\"-v\", argv[1]))\n-\t\t\t\tverbose = 1;\n-\t\t\telse if (!strcmp(\"--\", argv[1]))\n-\t\t\t\tno_more_options = 1;\n-\t\t\telse\n-\t\t\t\tusage(verify_pack_usage);\n-\t\t}\n-\t\telse {\n-\t\t\tif (verify_one_pack(argv[1], verbose))\n-\t\t\t\terr = 1;\n-\t\t\tdiscard_revindex();\n-\t\t\tnothing_done = 0;\n-\t\t}\n-\t\targc--; argv++;\n+\targc = parse_options(argc, argv, prefix, verify_pack_options,\n+\t\t\t     verify_pack_usage, 0);\n+\tif (argc < 1)\n+\t\tusage_with_options(verify_pack_usage, verify_pack_options);\n+\tfor (i = 0; i < argc; i++) {\n+\t\tif (verify_one_pack(argv[i], verbose))\n+\t\t\terr = 1;\n+\t\tdiscard_revindex();\n \t}\n \n-\tif (nothing_done)\n-\t\tusage(verify_pack_usage);\n-\n \treturn err;\n }\n-- \n1.6.3.3.385.g60647\n"},{"id":"117606","messageId":"1247030141-11695-5-git-send-email-bebarino@gmail.com","threadId":"20053","inReplyTo":"1247030141-11695-4-git-send-email-bebarino@gmail.com","subject":"[PATCH 4/4] prune-packed: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-08T05:15:41Z","receivedAt":"2009-07-08T05:15:41Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Add --dry-run and --quiet to be more consistent with the rest of git.\n\nSigned-off-by: Stephen Boyd <bebarino@gmail.com>\n---\n Documentation/git-prune-packed.txt |    4 +++-\n builtin-prune-packed.c             |   29 ++++++++++++-----------------\n 2 files changed, 15 insertions(+), 18 deletions(-)\n\ndiff --git a/Documentation/git-prune-packed.txt b/Documentation/git-prune-packed.txt\nindex b5f26ce..abfc6b6 100644\n--- a/Documentation/git-prune-packed.txt\n+++ b/Documentation/git-prune-packed.txt\n@@ -8,7 +8,7 @@ git-prune-packed - Remove extra objects that are already in pack files\n \n SYNOPSIS\n --------\n-'git prune-packed' [-n] [-q]\n+'git prune-packed' [-n|--dry-run] [-q|--quiet]\n \n \n DESCRIPTION\n@@ -28,10 +28,12 @@ disk storage, etc.\n OPTIONS\n -------\n -n::\n+--dry-run::\n         Don't actually remove any objects, only show those that would have been\n         removed.\n \n -q::\n+--quiet::\n \tSquelch the progress indicator.\n \n Author\ndiff --git a/builtin-prune-packed.c b/builtin-prune-packed.c\nindex 00590b1..be99eb0 100644\n--- a/builtin-prune-packed.c\n+++ b/builtin-prune-packed.c\n@@ -1,9 +1,12 @@\n #include \"builtin.h\"\n #include \"cache.h\"\n #include \"progress.h\"\n+#include \"parse-options.h\"\n \n-static const char prune_packed_usage[] =\n-\"git prune-packed [-n] [-q]\";\n+static const char * const prune_packed_usage[] = {\n+\t\"git prune-packed [-n|--dry-run] [-q|--quiet]\",\n+\tNULL\n+};\n \n #define DRY_RUN 01\n #define VERBOSE 02\n@@ -68,24 +71,16 @@ void prune_packed_objects(int opts)\n \n int cmd_prune_packed(int argc, const char **argv, const char *prefix)\n {\n-\tint i;\n \tint opts = VERBOSE;\n+\tconst struct option prune_packed_options[] = {\n+\t\tOPT_BIT('n', \"dry-run\", &opts, \"dry run\", DRY_RUN),\n+\t\tOPT_NEGBIT('q', \"quiet\", &opts, \"be quiet\", VERBOSE),\n+\t\tOPT_END()\n+\t};\n \n-\tfor (i = 1; i < argc; i++) {\n-\t\tconst char *arg = argv[i];\n+\targc = parse_options(argc, argv, prefix, prune_packed_options,\n+\t\t\t     prune_packed_usage, 0);\n \n-\t\tif (*arg == '-') {\n-\t\t\tif (!strcmp(arg, \"-n\"))\n-\t\t\t\topts |= DRY_RUN;\n-\t\t\telse if (!strcmp(arg, \"-q\"))\n-\t\t\t\topts &= ~VERBOSE;\n-\t\t\telse\n-\t\t\t\tusage(prune_packed_usage);\n-\t\t\tcontinue;\n-\t\t}\n-\t\t/* Handle arguments here .. */\n-\t\tusage(prune_packed_usage);\n-\t}\n \tprune_packed_objects(opts);\n \treturn 0;\n }\n-- \n1.6.3.3.385.g60647\n"},{"id":"117680","messageId":"alpine.DEB.1.00.0907091250120.4339@intel-tinevez-2-302","threadId":"20053","inReplyTo":"1247030141-11695-5-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 4/4] prune-packed: migrate to parse-options","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-07-09T10:51:37Z","receivedAt":"2009-07-09T10:51:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nI reviewed all four patches, and like them.  Just a minor nit:\n\nOn Tue, 7 Jul 2009, Stephen Boyd wrote:\n\n> Add --dry-run and --quiet to be more consistent with the rest of git.\n\nYou should say here that you add the _long_ options (the short options \nwere supported already); I almost expected you to sneak in additional \nfeatures with the parseoptification.\n\nSame goes for 3/4, I guess.\n\nThanks,\nDscho\n"},{"id":"117699","messageId":"4A561306.9010908@gmail.com","threadId":"20053","inReplyTo":"alpine.DEB.1.00.0907091250120.4339@intel-tinevez-2-302","subject":"Re: [PATCH 4/4] prune-packed: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-09T15:55:50Z","receivedAt":"2009-07-09T15:55:50Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Johannes Schindelin wrote:\n> Hi,\n>\n> I reviewed all four patches, and like them.  Just a minor nit:\n>\n> On Tue, 7 Jul 2009, Stephen Boyd wrote:\n>   \n>> Add --dry-run and --quiet to be more consistent with the rest of git.\n>>     \n>\n> You should say here that you add the _long_ options (the short options \n> were supported already); I almost expected you to sneak in additional \n> features with the parseoptification.\n>\n> Same goes for 3/4, I guess.\n>   \n\n\nSure, this sounds reasonable. I'll send follow up commit message fixups.\n"},{"id":"117700","messageId":"4A561450.4000404@gmail.com","threadId":"20053","inReplyTo":"1247030141-11695-4-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 3/4] verify-pack: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-09T16:01:20Z","receivedAt":"2009-07-09T16:01:20Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Stephen Boyd wrote:\n> OPT__VERBOSE adds a --verbose option, so document the new addition.\n>   \n\nOPT__VERBOSE introduces the long option (--verbose) in addition to the\nalready present short option (-v),  so document this new addition.\n\n> Signed-off-by: Stephen Boyd <bebarino@gmail.com>\n>   \n"},{"id":"117701","messageId":"4A561559.3010100@gmail.com","threadId":"20053","inReplyTo":"1247030141-11695-5-git-send-email-bebarino@gmail.com","subject":"Re: [PATCH 4/4] prune-packed: migrate to parse-options","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-07-09T16:05:45Z","receivedAt":"2009-07-09T16:05:45Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"Stephen Boyd wrote:\n> Add --dry-run and --quiet to be more consistent with the rest of git.\n\nAdd long options for dry run and quiet to be more consistent with the\nrest of git.\n\n> Signed-off-by: Stephen Boyd <bebarino@gmail.com>\n"}]}