]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/send-pack.c
config: drop cf validity check in get_next_char()
[thirdparty/git.git] / builtin / send-pack.c
CommitLineData
c2e86add 1#include "builtin.h"
2a9c3fe8 2#include "commit.h"
584c6cc9 3#include "refs.h"
f3a3214e 4#include "pkt-line.h"
de1a2fdd 5#include "sideband.h"
38b1c662 6#include "run-command.h"
6b62816c 7#include "remote.h"
96249c04 8#include "send-pack.h"
de1a2fdd 9#include "quote.h"
f1863d0d 10#include "transport.h"
ff5effdf 11#include "version.h"
61221472 12
2a245013 13static const char send_pack_usage[] =
1b1dd23f 14"git send-pack [--all | --mirror] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
18bd8821 15" --all and explicit <ref> specification are mutually exclusive.";
96249c04 16
6828f72f 17static struct send_pack_args args;
61221472 18
de1a2fdd
SP
19static void print_helper_status(struct ref *ref)
20{
21 struct strbuf buf = STRBUF_INIT;
22
23 for (; ref; ref = ref->next) {
24 const char *msg = NULL;
25 const char *res;
26
27 switch(ref->status) {
28 case REF_STATUS_NONE:
29 res = "error";
30 msg = "no match";
31 break;
32
33 case REF_STATUS_OK:
34 res = "ok";
35 break;
36
37 case REF_STATUS_UPTODATE:
38 res = "ok";
39 msg = "up to date";
40 break;
41
42 case REF_STATUS_REJECT_NONFASTFORWARD:
43 res = "error";
44 msg = "non-fast forward";
dbfeddb1
CR
45 break;
46
75e5c0dc
JH
47 case REF_STATUS_REJECT_FETCH_FIRST:
48 res = "error";
49 msg = "fetch first";
50 break;
51
52 case REF_STATUS_REJECT_NEEDS_FORCE:
53 res = "error";
54 msg = "needs force";
55 break;
56
dbfeddb1
CR
57 case REF_STATUS_REJECT_ALREADY_EXISTS:
58 res = "error";
59 msg = "already exists";
de1a2fdd
SP
60 break;
61
62 case REF_STATUS_REJECT_NODELETE:
63 case REF_STATUS_REMOTE_REJECT:
64 res = "error";
65 break;
66
67 case REF_STATUS_EXPECTING_REPORT:
68 default:
69 continue;
70 }
71
72 strbuf_reset(&buf);
73 strbuf_addf(&buf, "%s %s", res, ref->name);
74 if (ref->remote_status)
75 msg = ref->remote_status;
76 if (msg) {
77 strbuf_addch(&buf, ' ');
78 quote_two_c_style(&buf, "", msg, 0);
79 }
80 strbuf_addch(&buf, '\n');
81
cdf4fb8e 82 write_or_die(1, buf.buf, buf.len);
de1a2fdd
SP
83 }
84 strbuf_release(&buf);
85}
86
96249c04 87int cmd_send_pack(int argc, const char **argv, const char *prefix)
61221472 88{
64fcef2d
DB
89 int i, nr_refspecs = 0;
90 const char **refspecs = NULL;
96249c04 91 const char *remote_name = NULL;
b516968f 92 struct remote *remote = NULL;
96249c04 93 const char *dest = NULL;
64fcef2d
DB
94 int fd[2];
95 struct child_process *conn;
96 struct extra_have_objects extra_have;
6d2bf96e 97 struct ref *remote_refs, *local_refs;
64fcef2d 98 int ret;
de1a2fdd 99 int helper_status = 0;
64fcef2d
DB
100 int send_all = 0;
101 const char *receivepack = "git-receive-pack";
102 int flags;
10643d4e 103 unsigned int reject_reasons;
391b1f20 104 int progress = -1;
84a9b58c 105
61221472 106 argv++;
d089391c 107 for (i = 1; i < argc; i++, argv++) {
96249c04 108 const char *arg = *argv;
61221472
LT
109
110 if (*arg == '-') {
cc44c765 111 if (!prefixcmp(arg, "--receive-pack=")) {
64fcef2d 112 receivepack = arg + 15;
d23842fd
UKK
113 continue;
114 }
cc44c765 115 if (!prefixcmp(arg, "--exec=")) {
64fcef2d 116 receivepack = arg + 7;
61221472
LT
117 continue;
118 }
b516968f
DB
119 if (!prefixcmp(arg, "--remote=")) {
120 remote_name = arg + 9;
121 continue;
122 }
d089391c 123 if (!strcmp(arg, "--all")) {
64fcef2d 124 send_all = 1;
d089391c
LT
125 continue;
126 }
a63103ae 127 if (!strcmp(arg, "--dry-run")) {
96249c04 128 args.dry_run = 1;
a63103ae
BE
129 continue;
130 }
28b9d6e5
AW
131 if (!strcmp(arg, "--mirror")) {
132 args.send_mirror = 1;
133 continue;
134 }
2a9c3fe8 135 if (!strcmp(arg, "--force")) {
96249c04 136 args.force_update = 1;
2a9c3fe8
LT
137 continue;
138 }
c207e34f
CB
139 if (!strcmp(arg, "--quiet")) {
140 args.quiet = 1;
141 continue;
142 }
41f93a2c 143 if (!strcmp(arg, "--verbose")) {
96249c04 144 args.verbose = 1;
41f93a2c
LT
145 continue;
146 }
391b1f20
JK
147 if (!strcmp(arg, "--progress")) {
148 progress = 1;
149 continue;
150 }
151 if (!strcmp(arg, "--no-progress")) {
152 progress = 0;
153 continue;
154 }
2245be3e 155 if (!strcmp(arg, "--thin")) {
96249c04 156 args.use_thin_pack = 1;
2245be3e
JH
157 continue;
158 }
de1a2fdd
SP
159 if (!strcmp(arg, "--stateless-rpc")) {
160 args.stateless_rpc = 1;
161 continue;
162 }
163 if (!strcmp(arg, "--helper-status")) {
164 helper_status = 1;
165 continue;
166 }
61221472
LT
167 usage(send_pack_usage);
168 }
d089391c
LT
169 if (!dest) {
170 dest = arg;
171 continue;
172 }
64fcef2d
DB
173 refspecs = (const char **) argv;
174 nr_refspecs = argc - i;
61221472
LT
175 break;
176 }
177 if (!dest)
178 usage(send_pack_usage);
28b9d6e5
AW
179 /*
180 * --all and --mirror are incompatible; neither makes sense
181 * with any refspecs.
182 */
64fcef2d
DB
183 if ((refspecs && (send_all || args.send_mirror)) ||
184 (send_all && args.send_mirror))
0bc3cdfc 185 usage(send_pack_usage);
37adac76 186
b516968f
DB
187 if (remote_name) {
188 remote = remote_get(remote_name);
28b91f8a 189 if (!remote_has_url(remote, dest)) {
b516968f
DB
190 die("Destination %s is not a uri for %s",
191 dest, remote_name);
192 }
193 }
194
391b1f20
JK
195 if (progress == -1)
196 progress = !args.quiet && isatty(2);
197 args.progress = progress;
8d32e60d 198
de1a2fdd
SP
199 if (args.stateless_rpc) {
200 conn = NULL;
201 fd[0] = 0;
202 fd[1] = 1;
203 } else {
5a277f3f 204 conn = git_connect(fd, dest, receivepack,
de1a2fdd
SP
205 args.verbose ? CONNECT_VERBOSE : 0);
206 }
96249c04 207
64fcef2d
DB
208 memset(&extra_have, 0, sizeof(extra_have));
209
85edf4f5 210 get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, &extra_have);
64fcef2d 211
f1863d0d 212 transport_verify_remote_names(nr_refspecs, refspecs);
64fcef2d
DB
213
214 local_refs = get_local_heads();
96249c04 215
64fcef2d
DB
216 flags = MATCH_REFS_NONE;
217
218 if (send_all)
219 flags |= MATCH_REFS_ALL;
220 if (args.send_mirror)
221 flags |= MATCH_REFS_MIRROR;
222
223 /* match them up */
29753cdd 224 if (match_push_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags))
64fcef2d 225 return -1;
96249c04 226
20e8b465
TRC
227 set_ref_status_for_push(remote_refs, args.send_mirror,
228 args.force_update);
229
64fcef2d 230 ret = send_pack(&args, fd, conn, remote_refs, &extra_have);
96249c04 231
de1a2fdd
SP
232 if (helper_status)
233 print_helper_status(remote_refs);
234
64fcef2d 235 close(fd[1]);
7f8e9828 236 close(fd[0]);
64fcef2d 237
98158e9c 238 ret |= finish_connect(conn);
64fcef2d 239
de1a2fdd 240 if (!helper_status)
10643d4e 241 transport_print_push_status(dest, remote_refs, args.verbose, 0, &reject_reasons);
64fcef2d
DB
242
243 if (!args.dry_run && remote) {
244 struct ref *ref;
245 for (ref = remote_refs; ref; ref = ref->next)
f1863d0d 246 transport_update_tracking_ref(remote, ref, args.verbose);
64fcef2d
DB
247 }
248
f1863d0d 249 if (!ret && !transport_refs_pushed(remote_refs))
64fcef2d
DB
250 fprintf(stderr, "Everything up-to-date\n");
251
252 return ret;
61221472 253}