|
12 | 12 | #include "version.h" |
13 | 13 | #include "sha1-array.h" |
14 | 14 | #include "gpg-interface.h" |
| 15 | +#include "gettext.h" |
15 | 16 |
|
16 | | -static const char send_pack_usage[] = |
17 | | -"git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [--atomic] [<host>:]<directory> [<ref>...]\n" |
18 | | -" --all and explicit <ref> specification are mutually exclusive."; |
| 17 | +static const char * const send_pack_usage[] = { |
| 18 | + N_("git send-pack [--all | --mirror] [--dry-run] [--force] " |
| 19 | + "[--receive-pack=<git-receive-pack>] [--verbose] [--thin] [--atomic] " |
| 20 | + "[<host>:]<directory> [<ref>...]\n" |
| 21 | + " --all and explicit <ref> specification are mutually exclusive."), |
| 22 | + NULL, |
| 23 | +}; |
19 | 24 |
|
20 | 25 | static struct send_pack_args args; |
21 | 26 |
|
@@ -107,116 +112,66 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) |
107 | 112 | int ret; |
108 | 113 | int helper_status = 0; |
109 | 114 | int send_all = 0; |
| 115 | + int verbose = 0; |
110 | 116 | const char *receivepack = "git-receive-pack"; |
| 117 | + unsigned dry_run = 0; |
| 118 | + unsigned send_mirror = 0; |
| 119 | + unsigned force_update = 0; |
| 120 | + unsigned quiet = 0; |
| 121 | + unsigned push_cert = 0; |
| 122 | + unsigned use_thin_pack = 0; |
| 123 | + unsigned atomic = 0; |
| 124 | + unsigned stateless_rpc = 0; |
111 | 125 | int flags; |
112 | 126 | unsigned int reject_reasons; |
113 | 127 | int progress = -1; |
114 | 128 | int from_stdin = 0; |
115 | 129 | struct push_cas_option cas = {0}; |
116 | 130 |
|
117 | | - git_config(git_gpg_config, NULL); |
| 131 | + struct option options[] = { |
| 132 | + OPT__VERBOSITY(&verbose), |
| 133 | + OPT_STRING(0, "receive-pack", &receivepack, "receive-pack", N_("receive pack program")), |
| 134 | + OPT_STRING(0, "exec", &receivepack, "receive-pack", N_("receive pack program")), |
| 135 | + OPT_STRING(0, "remote", &remote_name, "remote", N_("remote name")), |
| 136 | + OPT_BOOL(0, "all", &send_all, N_("push all refs")), |
| 137 | + OPT_BOOL('n' , "dry-run", &dry_run, N_("dry run")), |
| 138 | + OPT_BOOL(0, "mirror", &send_mirror, N_("mirror all refs")), |
| 139 | + OPT_BOOL('f', "force", &force_update, N_("force updates")), |
| 140 | + OPT_BOOL(0, "signed", &push_cert, N_("GPG sign the push")), |
| 141 | + OPT_BOOL(0, "progress", &progress, N_("force progress reporting")), |
| 142 | + OPT_BOOL(0, "thin", &use_thin_pack, N_("use thin pack")), |
| 143 | + OPT_BOOL(0, "atomic", &atomic, N_("request atomic transaction on remote side")), |
| 144 | + OPT_BOOL(0, "stateless-rpc", &stateless_rpc, N_("use stateless RPC protocol")), |
| 145 | + OPT_BOOL(0, "stdin", &from_stdin, N_("read refs from stdin")), |
| 146 | + OPT_BOOL(0, "helper-status", &helper_status, N_("print status from remote helper")), |
| 147 | + { OPTION_CALLBACK, |
| 148 | + 0, CAS_OPT_NAME, &cas, N_("refname>:<expect"), |
| 149 | + N_("require old value of ref to be at this value"), |
| 150 | + PARSE_OPT_OPTARG, parseopt_push_cas_option }, |
| 151 | + OPT_END() |
| 152 | + }; |
118 | 153 |
|
119 | | - argv++; |
120 | | - for (i = 1; i < argc; i++, argv++) { |
121 | | - const char *arg = *argv; |
122 | | - |
123 | | - if (*arg == '-') { |
124 | | - if (starts_with(arg, "--receive-pack=")) { |
125 | | - receivepack = arg + 15; |
126 | | - continue; |
127 | | - } |
128 | | - if (starts_with(arg, "--exec=")) { |
129 | | - receivepack = arg + 7; |
130 | | - continue; |
131 | | - } |
132 | | - if (starts_with(arg, "--remote=")) { |
133 | | - remote_name = arg + 9; |
134 | | - continue; |
135 | | - } |
136 | | - if (!strcmp(arg, "--all")) { |
137 | | - send_all = 1; |
138 | | - continue; |
139 | | - } |
140 | | - if (!strcmp(arg, "--dry-run")) { |
141 | | - args.dry_run = 1; |
142 | | - continue; |
143 | | - } |
144 | | - if (!strcmp(arg, "--mirror")) { |
145 | | - args.send_mirror = 1; |
146 | | - continue; |
147 | | - } |
148 | | - if (!strcmp(arg, "--force")) { |
149 | | - args.force_update = 1; |
150 | | - continue; |
151 | | - } |
152 | | - if (!strcmp(arg, "--quiet")) { |
153 | | - args.quiet = 1; |
154 | | - continue; |
155 | | - } |
156 | | - if (!strcmp(arg, "--verbose")) { |
157 | | - args.verbose = 1; |
158 | | - continue; |
159 | | - } |
160 | | - if (!strcmp(arg, "--signed")) { |
161 | | - args.push_cert = 1; |
162 | | - continue; |
163 | | - } |
164 | | - if (!strcmp(arg, "--progress")) { |
165 | | - progress = 1; |
166 | | - continue; |
167 | | - } |
168 | | - if (!strcmp(arg, "--no-progress")) { |
169 | | - progress = 0; |
170 | | - continue; |
171 | | - } |
172 | | - if (!strcmp(arg, "--thin")) { |
173 | | - args.use_thin_pack = 1; |
174 | | - continue; |
175 | | - } |
176 | | - if (!strcmp(arg, "--atomic")) { |
177 | | - args.atomic = 1; |
178 | | - continue; |
179 | | - } |
180 | | - if (!strcmp(arg, "--stateless-rpc")) { |
181 | | - args.stateless_rpc = 1; |
182 | | - continue; |
183 | | - } |
184 | | - if (!strcmp(arg, "--stdin")) { |
185 | | - from_stdin = 1; |
186 | | - continue; |
187 | | - } |
188 | | - if (!strcmp(arg, "--helper-status")) { |
189 | | - helper_status = 1; |
190 | | - continue; |
191 | | - } |
192 | | - if (!strcmp(arg, "--" CAS_OPT_NAME)) { |
193 | | - if (parse_push_cas_option(&cas, NULL, 0) < 0) |
194 | | - exit(1); |
195 | | - continue; |
196 | | - } |
197 | | - if (!strcmp(arg, "--no-" CAS_OPT_NAME)) { |
198 | | - if (parse_push_cas_option(&cas, NULL, 1) < 0) |
199 | | - exit(1); |
200 | | - continue; |
201 | | - } |
202 | | - if (starts_with(arg, "--" CAS_OPT_NAME "=")) { |
203 | | - if (parse_push_cas_option(&cas, |
204 | | - strchr(arg, '=') + 1, 0) < 0) |
205 | | - exit(1); |
206 | | - continue; |
207 | | - } |
208 | | - usage(send_pack_usage); |
209 | | - } |
210 | | - if (!dest) { |
211 | | - dest = arg; |
212 | | - continue; |
213 | | - } |
214 | | - refspecs = (const char **) argv; |
215 | | - nr_refspecs = argc - i; |
216 | | - break; |
| 154 | + git_config(git_gpg_config, NULL); |
| 155 | + argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0); |
| 156 | + if (argc > 0) { |
| 157 | + dest = argv[0]; |
| 158 | + refspecs = (const char **)(argv + 1); |
| 159 | + nr_refspecs = argc - 1; |
217 | 160 | } |
| 161 | + |
218 | 162 | if (!dest) |
219 | | - usage(send_pack_usage); |
| 163 | + usage_with_options(send_pack_usage, options); |
| 164 | + |
| 165 | + args.verbose = verbose; |
| 166 | + args.dry_run = dry_run; |
| 167 | + args.send_mirror = send_mirror; |
| 168 | + args.force_update = force_update; |
| 169 | + args.quiet = quiet; |
| 170 | + args.push_cert = push_cert; |
| 171 | + args.progress = progress; |
| 172 | + args.use_thin_pack = use_thin_pack; |
| 173 | + args.atomic = atomic; |
| 174 | + args.stateless_rpc = stateless_rpc; |
220 | 175 |
|
221 | 176 | if (from_stdin) { |
222 | 177 | struct argv_array all_refspecs = ARGV_ARRAY_INIT; |
@@ -245,7 +200,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) |
245 | 200 | */ |
246 | 201 | if ((refspecs && (send_all || args.send_mirror)) || |
247 | 202 | (send_all && args.send_mirror)) |
248 | | - usage(send_pack_usage); |
| 203 | + usage_with_options(send_pack_usage, options); |
249 | 204 |
|
250 | 205 | if (remote_name) { |
251 | 206 | remote = remote_get(remote_name); |
|
0 commit comments