Make builtin-reset.c use parse_options.
Signed-off-by: Carlos Rica <jasampler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Carlos Rica committed
Mar 4, 2008 at 23:11 UTC
5eee6b28b5fc6be03a89dfa6b6ca502ec49dc2df
1 file changed
+20
-27
builtin-reset.c
+20
-27
@@ -17,9 +17,13 @@
17
#include "diffcore.h"
18
#include "tree.h"
19
#include "branch.h"
20
+#include "parse-options.h"
21
21
-static const char builtin_reset_usage[] =
22
-"git-reset [--mixed | --soft | --hard] [-q] [<commit-ish>] [ [--] <paths>...]";
22
+static const char * const git_reset_usage[] = {
23
+ "git-reset [--mixed | --soft | --hard] [-q] [<commit>]",
24
+ "git-reset [--mixed] <commit> [--] <paths>...",
25
+ NULL
26
+};
27
28
static char *args_to_str(const char **argv)
29
{
@@ -165,40 +169,31 @@ static const char *reset_type_names[] = { "mixed", "soft", "hard", NULL };
169
170
int cmd_reset(int argc, const char **argv, const char *prefix)
171
{
168
- int i = 1, reset_type = NONE, update_ref_status = 0, quiet = 0;
172
+ int i = 0, reset_type = NONE, update_ref_status = 0, quiet = 0;
173
const char *rev = "HEAD";
174
unsigned char sha1[20], *orig = NULL, sha1_orig[20],
175
*old_orig = NULL, sha1_old_orig[20];
176
struct commit *commit;
177
char *reflog_action, msg[1024];
178
+ const struct option options[] = {
179
+ OPT_SET_INT(0, "mixed", &reset_type,
180
+ "reset HEAD and index", MIXED),
181
+ OPT_SET_INT(0, "soft", &reset_type, "reset only HEAD", SOFT),
182
+ OPT_SET_INT(0, "hard", &reset_type,
183
+ "reset HEAD, index and working tree", HARD),
184
+ OPT_BOOLEAN('q', NULL, &quiet,
185
+ "disable showing new HEAD in hard reset"),
186
+ OPT_END()
187
+ };
188
189
git_config(git_default_config);
190
191
+ argc = parse_options(argc, argv, options, git_reset_usage,
192
+ PARSE_OPT_KEEP_DASHDASH);
193
reflog_action = args_to_str(argv);
194
setenv("GIT_REFLOG_ACTION", reflog_action, 0);
195
180
- while (i < argc) {
181
- if (!strcmp(argv[i], "--mixed")) {
182
- reset_type = MIXED;
183
- i++;
184
- }
185
- else if (!strcmp(argv[i], "--soft")) {
186
- reset_type = SOFT;
187
- i++;
188
- }
189
- else if (!strcmp(argv[i], "--hard")) {
190
- reset_type = HARD;
191
- i++;
192
- }
193
- else if (!strcmp(argv[i], "-q")) {
194
- quiet = 1;
195
- i++;
196
- }
197
- else
198
- break;
199
- }
200
-
201
- if (i < argc && argv[i][0] != '-')
196
+ if (i < argc && strcmp(argv[i], "--"))
197
rev = argv[i++];
198
199
if (get_sha1(rev, sha1))
@@ -211,8 +206,6 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
206
207
if (i < argc && !strcmp(argv[i], "--"))
208
i++;
214
- else if (i < argc && argv[i][0] == '-')
215
- usage(builtin_reset_usage);
209
210
/* git reset tree [--] paths... can be used to
211
* load chosen paths from the tree into the index without