Use parseopts in builtin-push
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Daniel Barkalow committed
Nov 4, 2007 at 22:35 UTC
378c4832ef7271a389913f5533611a06415ac5a6
1 file changed
+36
-52
builtin-push.c
+36
-52
@@ -7,8 +7,12 @@
7
#include "builtin.h"
8
#include "remote.h"
9
#include "transport.h"
10
+#include "parse-options.h"
11
11
-static const char push_usage[] = "git-push [--all] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]";
12
+static const char * const push_usage[] = {
13
+ "git-push [--all] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]",
14
+ NULL,
15
+};
16
17
static int thin, verbose;
18
static const char *receivepack;
@@ -85,63 +89,43 @@ static int do_push(const char *repo, int flags)
89
90
int cmd_push(int argc, const char **argv, const char *prefix)
91
{
88
- int i;
92
int flags = 0;
93
+ int all = 0;
94
+ int dry_run = 0;
95
+ int force = 0;
96
+ int tags = 0;
97
const char *repo = NULL; /* default repository */
98
92
- for (i = 1; i < argc; i++) {
93
- const char *arg = argv[i];
99
+ struct option options[] = {
100
+ OPT__VERBOSE(&verbose),
101
+ OPT_STRING( 0 , "repo", &repo, "repository", "repository"),
102
+ OPT_BOOLEAN( 0 , "all", &all, "push all refs"),
103
+ OPT_BOOLEAN( 0 , "tags", &tags, "push tags"),
104
+ OPT_BOOLEAN( 0 , "dry-run", &dry_run, "dry run"),
105
+ OPT_BOOLEAN('f', "force", &force, "force updates"),
106
+ OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
107
+ OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
108
+ OPT_STRING( 0 , "exec", &receivepack, "receive-pack", "receive pack program"),
109
+ OPT_END()
110
+ };
111
95
- if (arg[0] != '-') {
96
- repo = arg;
97
- i++;
98
- break;
99
- }
100
- if (!strcmp(arg, "-v")) {
101
- verbose=1;
102
- continue;
103
- }
104
- if (!prefixcmp(arg, "--repo=")) {
105
- repo = arg+7;
106
- continue;
107
- }
108
- if (!strcmp(arg, "--all")) {
109
- flags |= TRANSPORT_PUSH_ALL;
110
- continue;
111
- }
112
- if (!strcmp(arg, "--dry-run")) {
113
- flags |= TRANSPORT_PUSH_DRY_RUN;
114
- continue;
115
- }
116
- if (!strcmp(arg, "--tags")) {
117
- add_refspec("refs/tags/*");
118
- continue;
119
- }
120
- if (!strcmp(arg, "--force") || !strcmp(arg, "-f")) {
121
- flags |= TRANSPORT_PUSH_FORCE;
122
- continue;
123
- }
124
- if (!strcmp(arg, "--thin")) {
125
- thin = 1;
126
- continue;
127
- }
128
- if (!strcmp(arg, "--no-thin")) {
129
- thin = 0;
130
- continue;
131
- }
132
- if (!prefixcmp(arg, "--receive-pack=")) {
133
- receivepack = arg + 15;
134
- continue;
135
- }
136
- if (!prefixcmp(arg, "--exec=")) {
137
- receivepack = arg + 7;
138
- continue;
139
- }
140
- usage(push_usage);
112
+ argc = parse_options(argc, argv, options, push_usage, 0);
113
+
114
+ if (force)
115
+ flags |= TRANSPORT_PUSH_FORCE;
116
+ if (dry_run)
117
+ flags |= TRANSPORT_PUSH_DRY_RUN;
118
+ if (tags)
119
+ add_refspec("refs/tags/*");
120
+ if (all)
121
+ flags |= TRANSPORT_PUSH_ALL;
122
+
123
+ if (argc > 0) {
124
+ repo = argv[0];
125
+ set_refspecs(argv + 1, argc - 1);
126
}
142
- set_refspecs(argv + i, argc - i);
127
if ((flags & TRANSPORT_PUSH_ALL) && refspec)
144
- usage(push_usage);
128
+ usage_with_options(push_usage, options);
129
130
return do_push(repo, flags);
131
}