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
@@ -92,6 +97,31 @@ static void print_helper_status(struct ref *ref)
92
97
strbuf_release (& buf );
93
98
}
94
99
100
+ static int send_pack_config (const char * k , const char * v , void * cb )
101
+ {
102
+ git_gpg_config (k , v , NULL );
103
+
104
+ if (!strcmp (k , "push.gpgsign" )) {
105
+ const char * value ;
106
+ if (!git_config_get_value ("push.gpgsign" , & value )) {
107
+ switch (git_config_maybe_bool ("push.gpgsign" , value )) {
108
+ case 0 :
109
+ args .push_cert = SEND_PACK_PUSH_CERT_NEVER ;
110
+ break ;
111
+ case 1 :
112
+ args .push_cert = SEND_PACK_PUSH_CERT_ALWAYS ;
113
+ break ;
114
+ default :
115
+ if (value && !strcasecmp (value , "if-asked" ))
116
+ args .push_cert = SEND_PACK_PUSH_CERT_IF_ASKED ;
117
+ else
118
+ return error ("Invalid value for '%s'" , k );
119
+ }
120
+ }
121
+ }
122
+ return 0 ;
123
+ }
124
+
95
125
int cmd_send_pack (int argc , const char * * argv , const char * prefix )
96
126
{
97
127
int i , nr_refspecs = 0 ;
@@ -107,116 +137,68 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
107
137
int ret ;
108
138
int helper_status = 0 ;
109
139
int send_all = 0 ;
140
+ int verbose = 0 ;
110
141
const char * receivepack = "git-receive-pack" ;
142
+ unsigned dry_run = 0 ;
143
+ unsigned send_mirror = 0 ;
144
+ unsigned force_update = 0 ;
145
+ unsigned quiet = 0 ;
146
+ int push_cert = 0 ;
147
+ unsigned use_thin_pack = 0 ;
148
+ unsigned atomic = 0 ;
149
+ unsigned stateless_rpc = 0 ;
111
150
int flags ;
112
151
unsigned int reject_reasons ;
113
152
int progress = -1 ;
114
153
int from_stdin = 0 ;
115
154
struct push_cas_option cas = {0 };
116
155
117
- git_config (git_gpg_config , NULL );
118
-
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 ;
156
+ struct option options [] = {
157
+ OPT__VERBOSITY (& verbose ),
158
+ OPT_STRING (0 , "receive-pack" , & receivepack , "receive-pack" , N_ ("receive pack program" )),
159
+ OPT_STRING (0 , "exec" , & receivepack , "receive-pack" , N_ ("receive pack program" )),
160
+ OPT_STRING (0 , "remote" , & remote_name , "remote" , N_ ("remote name" )),
161
+ OPT_BOOL (0 , "all" , & send_all , N_ ("push all refs" )),
162
+ OPT_BOOL ('n' , "dry-run" , & dry_run , N_ ("dry run" )),
163
+ OPT_BOOL (0 , "mirror" , & send_mirror , N_ ("mirror all refs" )),
164
+ OPT_BOOL ('f' , "force" , & force_update , N_ ("force updates" )),
165
+ { OPTION_CALLBACK ,
166
+ 0 , "signed" , & push_cert , "yes|no|if-asked" , N_ ("GPG sign the push" ),
167
+ PARSE_OPT_OPTARG , option_parse_push_signed },
168
+ OPT_BOOL (0 , "progress" , & progress , N_ ("force progress reporting" )),
169
+ OPT_BOOL (0 , "thin" , & use_thin_pack , N_ ("use thin pack" )),
170
+ OPT_BOOL (0 , "atomic" , & atomic , N_ ("request atomic transaction on remote side" )),
171
+ OPT_BOOL (0 , "stateless-rpc" , & stateless_rpc , N_ ("use stateless RPC protocol" )),
172
+ OPT_BOOL (0 , "stdin" , & from_stdin , N_ ("read refs from stdin" )),
173
+ OPT_BOOL (0 , "helper-status" , & helper_status , N_ ("print status from remote helper" )),
174
+ { OPTION_CALLBACK ,
175
+ 0 , CAS_OPT_NAME , & cas , N_ ("refname>:<expect" ),
176
+ N_ ("require old value of ref to be at this value" ),
177
+ PARSE_OPT_OPTARG , parseopt_push_cas_option },
178
+ OPT_END ()
179
+ };
180
+
181
+ git_config (send_pack_config , NULL );
182
+ argc = parse_options (argc , argv , prefix , options , send_pack_usage , 0 );
183
+ if (argc > 0 ) {
184
+ dest = argv [0 ];
185
+ refspecs = (const char * * )(argv + 1 );
186
+ nr_refspecs = argc - 1 ;
217
187
}
188
+
218
189
if (!dest )
219
- usage (send_pack_usage );
190
+ usage_with_options (send_pack_usage , options );
191
+
192
+ args .verbose = verbose ;
193
+ args .dry_run = dry_run ;
194
+ args .send_mirror = send_mirror ;
195
+ args .force_update = force_update ;
196
+ args .quiet = quiet ;
197
+ args .push_cert = push_cert ;
198
+ args .progress = progress ;
199
+ args .use_thin_pack = use_thin_pack ;
200
+ args .atomic = atomic ;
201
+ args .stateless_rpc = stateless_rpc ;
220
202
221
203
if (from_stdin ) {
222
204
struct argv_array all_refspecs = ARGV_ARRAY_INIT ;
@@ -245,7 +227,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
245
227
*/
246
228
if ((refspecs && (send_all || args .send_mirror )) ||
247
229
(send_all && args .send_mirror ))
248
- usage (send_pack_usage );
230
+ usage_with_options (send_pack_usage , options );
249
231
250
232
if (remote_name ) {
251
233
remote = remote_get (remote_name );
0 commit comments