{"thread":{"id":"12505","subject":"[PATCH] Make builtin-reset.c use parse_options.","startedAt":"2008-03-04T22:11:34Z","lastAt":"2008-03-04T22:11:34Z","messageCount":1,"participants":["Carlos Rica"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"71004","messageId":"47CDC916.6010008@gmail.com","threadId":"12505","inReplyTo":null,"subject":"[PATCH] Make builtin-reset.c use parse_options.","fromName":"Carlos Rica","fromEmail":"jasampler@gmail.com","sentAt":"2008-03-04T22:11:34Z","receivedAt":"2008-03-04T22:11:34Z","isPatch":true,"sender":{"key":"jasampler@gmail.com","avatar":null},"body":"Signed-off-by: Carlos Rica <jasampler@gmail.com>\n---\n\n   Since builtin-reset.c changed in the recent last update,\n   this patch is built on top of it to make easier applying it.\n\n   The only change from previous version is the struct options, now const.\n\n   Note that --h ambiguity favoring --hard over --help is still here,\n   not a big problem because --help cannot be abbreviated in git.\n\n   I copied the SYNOPSIS from the documentation to enhance the\n   help message, splitting the old one-line message in two lines.\n   Now this usage is showed when you run \"git reset -h\" and\n   also when you includes an unknown option in command line.\n\n builtin-reset.c |   47 ++++++++++++++++++++---------------------------\n 1 files changed, 20 insertions(+), 27 deletions(-)\n\ndiff --git a/builtin-reset.c b/builtin-reset.c\nindex bb3e192..79424bb 100644\n--- a/builtin-reset.c\n+++ b/builtin-reset.c\n@@ -17,9 +17,13 @@\n #include \"diffcore.h\"\n #include \"tree.h\"\n #include \"branch.h\"\n+#include \"parse-options.h\"\n\n-static const char builtin_reset_usage[] =\n-\"git-reset [--mixed | --soft | --hard] [-q] [<commit-ish>] [ [--] <paths>...]\";\n+static const char * const git_reset_usage[] = {\n+\t\"git-reset [--mixed | --soft | --hard] [-q] [<commit>]\",\n+\t\"git-reset [--mixed] <commit> [--] <paths>...\",\n+\tNULL\n+};\n\n static char *args_to_str(const char **argv)\n {\n@@ -165,40 +169,31 @@ static const char *reset_type_names[] = { \"mixed\", \"soft\", \"hard\", NULL };\n\n int cmd_reset(int argc, const char **argv, const char *prefix)\n {\n-\tint i = 1, reset_type = NONE, update_ref_status = 0, quiet = 0;\n+\tint i = 0, reset_type = NONE, update_ref_status = 0, quiet = 0;\n \tconst char *rev = \"HEAD\";\n \tunsigned char sha1[20], *orig = NULL, sha1_orig[20],\n \t\t\t\t*old_orig = NULL, sha1_old_orig[20];\n \tstruct commit *commit;\n \tchar *reflog_action, msg[1024];\n+\tconst struct option options[] = {\n+\t\tOPT_SET_INT(0, \"mixed\", &reset_type,\n+\t\t\t\t\t\t\"reset HEAD and index\", MIXED),\n+\t\tOPT_SET_INT(0, \"soft\", &reset_type, \"reset only HEAD\", SOFT),\n+\t\tOPT_SET_INT(0, \"hard\", &reset_type,\n+\t\t\t\t\"reset HEAD, index and working tree\", HARD),\n+\t\tOPT_BOOLEAN('q', NULL, &quiet,\n+\t\t\t\t\"disable showing new HEAD in hard reset\"),\n+\t\tOPT_END()\n+\t};\n\n \tgit_config(git_default_config);\n\n+\targc = parse_options(argc, argv, options, git_reset_usage,\n+\t\t\t\t\t\tPARSE_OPT_KEEP_DASHDASH);\n \treflog_action = args_to_str(argv);\n \tsetenv(\"GIT_REFLOG_ACTION\", reflog_action, 0);\n\n-\twhile (i < argc) {\n-\t\tif (!strcmp(argv[i], \"--mixed\")) {\n-\t\t\treset_type = MIXED;\n-\t\t\ti++;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--soft\")) {\n-\t\t\treset_type = SOFT;\n-\t\t\ti++;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"--hard\")) {\n-\t\t\treset_type = HARD;\n-\t\t\ti++;\n-\t\t}\n-\t\telse if (!strcmp(argv[i], \"-q\")) {\n-\t\t\tquiet = 1;\n-\t\t\ti++;\n-\t\t}\n-\t\telse\n-\t\t\tbreak;\n-\t}\n"}]}