fetch-pack: move code to report unmatched refs to a function
[git/git.git] / transport.c
CommitLineData
9b288516
DB
1#include "cache.h"
2#include "transport.h"
3#include "run-command.h"
c29727d5
DB
4#include "pkt-line.h"
5#include "fetch-pack.h"
47a59185
JH
6#include "remote.h"
7#include "connect.h"
40cb4fab 8#include "send-pack.h"
c29727d5 9#include "walker.h"
c7a8a162 10#include "bundle.h"
cd547b48
JS
11#include "dir.h"
12#include "refs.h"
e9fcd1e2 13#include "branch.h"
638794cd 14#include "url.h"
d2b17b32 15#include "submodule.h"
a762e51e 16#include "string-list.h"
13eb4626 17#include "sha1-array.h"
af65f68c 18#include "sigchain.h"
cd547b48 19
e9fcd1e2
IL
20static void set_upstreams(struct transport *transport, struct ref *refs,
21 int pretend)
22{
23 struct ref *ref;
24 for (ref = refs; ref; ref = ref->next) {
25 const char *localname;
26 const char *tmp;
27 const char *remotename;
28 unsigned char sha[20];
29 int flag = 0;
30 /*
31 * Check suitability for tracking. Must be successful /
32 * already up-to-date ref create/modify (not delete).
33 */
34 if (ref->status != REF_STATUS_OK &&
35 ref->status != REF_STATUS_UPTODATE)
36 continue;
37 if (!ref->peer_ref)
38 continue;
f4e54d02 39 if (is_null_oid(&ref->new_oid))
e9fcd1e2
IL
40 continue;
41
42 /* Follow symbolic refs (mainly for HEAD). */
43 localname = ref->peer_ref->name;
44 remotename = ref->name;
7695d118
RS
45 tmp = resolve_ref_unsafe(localname, RESOLVE_REF_READING,
46 sha, &flag);
e9fcd1e2 47 if (tmp && flag & REF_ISSYMREF &&
59556548 48 starts_with(tmp, "refs/heads/"))
e9fcd1e2
IL
49 localname = tmp;
50
51 /* Both source and destination must be local branches. */
59556548 52 if (!localname || !starts_with(localname, "refs/heads/"))
e9fcd1e2 53 continue;
59556548 54 if (!remotename || !starts_with(remotename, "refs/heads/"))
e9fcd1e2
IL
55 continue;
56
57 if (!pretend)
58 install_branch_config(BRANCH_CONFIG_VERBOSE,
59 localname + 11, transport->remote->name,
60 remotename);
61 else
7ab1d44f 62 printf(_("Would set upstream of '%s' to '%s' of '%s'\n"),
e9fcd1e2
IL
63 localname + 11, remotename + 11,
64 transport->remote->name);
65 }
66}
67
c7a8a162
JS
68struct bundle_transport_data {
69 int fd;
70 struct bundle_header header;
71};
72
64fcef2d 73static struct ref *get_refs_from_bundle(struct transport *transport, int for_push)
c7a8a162
JS
74{
75 struct bundle_transport_data *data = transport->data;
76 struct ref *result = NULL;
77 int i;
78
64fcef2d
DB
79 if (for_push)
80 return NULL;
81
c7a8a162
JS
82 if (data->fd > 0)
83 close(data->fd);
84 data->fd = read_bundle_header(transport->url, &data->header);
85 if (data->fd < 0)
86 die ("Could not read bundle '%s'.", transport->url);
87 for (i = 0; i < data->header.references.nr; i++) {
88 struct ref_list_entry *e = data->header.references.list + i;
59c69c0c 89 struct ref *ref = alloc_ref(e->name);
f4e54d02 90 hashcpy(ref->old_oid.hash, e->sha1);
c7a8a162
JS
91 ref->next = result;
92 result = ref;
93 }
94 return result;
95}
96
1788c39c 97static int fetch_refs_from_bundle(struct transport *transport,
37148311 98 int nr_heads, struct ref **to_fetch)
c7a8a162
JS
99{
100 struct bundle_transport_data *data = transport->data;
be042aff
JH
101 return unbundle(&data->header, data->fd,
102 transport->progress ? BUNDLE_VERBOSE : 0);
c7a8a162
JS
103}
104
105static int close_bundle(struct transport *transport)
106{
107 struct bundle_transport_data *data = transport->data;
108 if (data->fd > 0)
109 close(data->fd);
f4e95765 110 free(data);
c7a8a162
JS
111 return 0;
112}
113
9b288516 114struct git_transport_data {
aa5af974 115 struct git_transport_options options;
ba227857
DB
116 struct child_process *conn;
117 int fd[2];
61b075bd 118 unsigned got_remote_heads : 1;
13eb4626 119 struct sha1_array extra_have;
beea4152 120 struct sha1_array shallow;
9b288516
DB
121};
122
aa5af974 123static int set_git_option(struct git_transport_options *opts,
9b288516
DB
124 const char *name, const char *value)
125{
c29727d5 126 if (!strcmp(name, TRANS_OPT_UPLOADPACK)) {
aa5af974 127 opts->uploadpack = value;
c29727d5
DB
128 return 0;
129 } else if (!strcmp(name, TRANS_OPT_RECEIVEPACK)) {
aa5af974 130 opts->receivepack = value;
9b288516
DB
131 return 0;
132 } else if (!strcmp(name, TRANS_OPT_THIN)) {
aa5af974 133 opts->thin = !!value;
9b288516 134 return 0;
41fa7d2e 135 } else if (!strcmp(name, TRANS_OPT_FOLLOWTAGS)) {
aa5af974 136 opts->followtags = !!value;
41fa7d2e 137 return 0;
c29727d5 138 } else if (!strcmp(name, TRANS_OPT_KEEP)) {
aa5af974 139 opts->keep = !!value;
c29727d5 140 return 0;
48d25cae
NTND
141 } else if (!strcmp(name, TRANS_OPT_UPDATE_SHALLOW)) {
142 opts->update_shallow = !!value;
143 return 0;
c29727d5
DB
144 } else if (!strcmp(name, TRANS_OPT_DEPTH)) {
145 if (!value)
aa5af974 146 opts->depth = 0;
e7622ce8
NTND
147 else {
148 char *end;
149 opts->depth = strtol(value, &end, 0);
150 if (*end)
7ab1d44f 151 die(_("transport: invalid depth option '%s'"), value);
e7622ce8 152 }
c29727d5 153 return 0;
508ea882
NTND
154 } else if (!strcmp(name, TRANS_OPT_DEEPEN_SINCE)) {
155 opts->deepen_since = value;
156 return 0;
a45a2600
NTND
157 } else if (!strcmp(name, TRANS_OPT_DEEPEN_NOT)) {
158 opts->deepen_not = (const struct string_list *)value;
159 return 0;
cccf74e2
NTND
160 } else if (!strcmp(name, TRANS_OPT_DEEPEN_RELATIVE)) {
161 opts->deepen_relative = !!value;
162 return 0;
9b288516
DB
163 }
164 return 1;
165}
166
f3ee9ca5 167static int connect_setup(struct transport *transport, int for_push)
ba227857
DB
168{
169 struct git_transport_data *data = transport->data;
f3ee9ca5 170 int flags = transport->verbose > 0 ? CONNECT_VERBOSE : 0;
61b075bd
IL
171
172 if (data->conn)
173 return 0;
174
c915f11e
EW
175 switch (transport->family) {
176 case TRANSPORT_FAMILY_ALL: break;
177 case TRANSPORT_FAMILY_IPV4: flags |= CONNECT_IPV4; break;
178 case TRANSPORT_FAMILY_IPV6: flags |= CONNECT_IPV6; break;
179 }
180
5a277f3f
JH
181 data->conn = git_connect(data->fd, transport->url,
182 for_push ? data->options.receivepack :
183 data->options.uploadpack,
f3ee9ca5 184 flags);
61b075bd 185
ba227857
DB
186 return 0;
187}
188
64fcef2d 189static struct ref *get_refs_via_connect(struct transport *transport, int for_push)
c29727d5
DB
190{
191 struct git_transport_data *data = transport->data;
192 struct ref *refs;
c29727d5 193
f3ee9ca5 194 connect_setup(transport, for_push);
85edf4f5 195 get_remote_heads(data->fd[0], NULL, 0, &refs,
beea4152
NTND
196 for_push ? REF_NORMAL : 0,
197 &data->extra_have,
4820a33b 198 &data->shallow);
61b075bd 199 data->got_remote_heads = 1;
c29727d5
DB
200
201 return refs;
202}
203
1788c39c 204static int fetch_refs_via_pack(struct transport *transport,
37148311 205 int nr_heads, struct ref **to_fetch)
c29727d5
DB
206{
207 struct git_transport_data *data = transport->data;
626df76e 208 struct ref *refs;
c29727d5
DB
209 char *dest = xstrdup(transport->url);
210 struct fetch_pack_args args;
00183cbb 211 struct ref *refs_tmp = NULL;
c29727d5 212
fa740529 213 memset(&args, 0, sizeof(args));
aa5af974
IL
214 args.uploadpack = data->options.uploadpack;
215 args.keep_pack = data->options.keep;
fa740529 216 args.lock_pack = 1;
aa5af974
IL
217 args.use_thin_pack = data->options.thin;
218 args.include_tag = data->options.followtags;
bd2c86ef 219 args.verbose = (transport->verbose > 1);
fe8aa148 220 args.quiet = (transport->verbose < 0);
d01b3c02 221 args.no_progress = !transport->progress;
aa5af974 222 args.depth = data->options.depth;
508ea882 223 args.deepen_since = data->options.deepen_since;
a45a2600 224 args.deepen_not = data->options.deepen_not;
cccf74e2 225 args.deepen_relative = data->options.deepen_relative;
c6807a40
NTND
226 args.check_self_contained_and_connected =
227 data->options.check_self_contained_and_connected;
beea4152 228 args.cloning = transport->cloning;
48d25cae 229 args.update_shallow = data->options.update_shallow;
c29727d5 230
61b075bd 231 if (!data->got_remote_heads) {
f3ee9ca5 232 connect_setup(transport, 0);
b06dcd7d 233 get_remote_heads(data->fd[0], NULL, 0, &refs_tmp, 0,
4820a33b 234 NULL, &data->shallow);
61b075bd 235 data->got_remote_heads = 1;
ba227857
DB
236 }
237
00183cbb
DB
238 refs = fetch_pack(&args, data->fd, data->conn,
239 refs_tmp ? refs_tmp : transport->remote_refs,
beea4152 240 dest, to_fetch, nr_heads, &data->shallow,
f2db854d 241 &transport->pack_lockfile);
ba227857
DB
242 close(data->fd[0]);
243 close(data->fd[1]);
626df76e
JK
244 if (finish_connect(data->conn)) {
245 free_refs(refs);
ba227857 246 refs = NULL;
626df76e 247 }
ba227857 248 data->conn = NULL;
61b075bd 249 data->got_remote_heads = 0;
c6807a40
NTND
250 data->options.self_contained_and_connected =
251 args.self_contained_and_connected;
c29727d5 252
00183cbb 253 free_refs(refs_tmp);
626df76e 254 free_refs(refs);
c29727d5 255 free(dest);
c6bc4005 256 return (refs ? 0 : -1);
c29727d5
DB
257}
258
481c7a6d
JK
259static int push_had_errors(struct ref *ref)
260{
261 for (; ref; ref = ref->next) {
262 switch (ref->status) {
263 case REF_STATUS_NONE:
264 case REF_STATUS_UPTODATE:
265 case REF_STATUS_OK:
266 break;
267 default:
268 return 1;
269 }
270 }
271 return 0;
272}
273
f1863d0d 274int transport_refs_pushed(struct ref *ref)
64fcef2d
DB
275{
276 for (; ref; ref = ref->next) {
277 switch(ref->status) {
278 case REF_STATUS_NONE:
279 case REF_STATUS_UPTODATE:
280 break;
281 default:
282 return 1;
283 }
284 }
285 return 0;
286}
287
f1863d0d 288void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
64fcef2d
DB
289{
290 struct refspec rs;
291
292 if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
293 return;
294
295 rs.src = ref->name;
296 rs.dst = NULL;
297
298 if (!remote_find_tracking(remote, &rs)) {
299 if (verbose)
300 fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
301 if (ref->deletion) {
302 delete_ref(rs.dst, NULL, 0);
303 } else
304 update_ref("update by push", rs.dst,
f4e54d02 305 ref->new_oid.hash, NULL, 0, 0);
64fcef2d
DB
306 free(rs.dst);
307 }
308}
309
7101e10c
JH
310static void print_ref_status(char flag, const char *summary,
311 struct ref *to, struct ref *from, const char *msg,
312 int porcelain, int summary_width)
64fcef2d 313{
1965ff74
LA
314 if (porcelain) {
315 if (from)
316 fprintf(stdout, "%c\t%s:%s\t", flag, from->name, to->name);
317 else
318 fprintf(stdout, "%c\t:%s\t", flag, to->name);
319 if (msg)
320 fprintf(stdout, "%s (%s)\n", summary, msg);
321 else
322 fprintf(stdout, "%s\n", summary);
323 } else {
7101e10c 324 fprintf(stderr, " %c %-*s ", flag, summary_width, summary);
1965ff74
LA
325 if (from)
326 fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name));
327 else
328 fputs(prettify_refname(to->name), stderr);
329 if (msg) {
330 fputs(" (", stderr);
331 fputs(msg, stderr);
332 fputc(')', stderr);
333 }
334 fputc('\n', stderr);
64fcef2d 335 }
64fcef2d
DB
336}
337
7101e10c 338static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_width)
64fcef2d
DB
339{
340 if (ref->deletion)
7101e10c
JH
341 print_ref_status('-', "[deleted]", ref, NULL, NULL,
342 porcelain, summary_width);
f4e54d02 343 else if (is_null_oid(&ref->old_oid))
64fcef2d 344 print_ref_status('*',
59556548 345 (starts_with(ref->name, "refs/tags/") ? "[new tag]" :
1965ff74 346 "[new branch]"),
7101e10c 347 ref, ref->peer_ref, NULL, porcelain, summary_width);
64fcef2d 348 else {
bd22d4ff 349 struct strbuf quickref = STRBUF_INIT;
64fcef2d
DB
350 char type;
351 const char *msg;
352
1eb47f16
RS
353 strbuf_add_unique_abbrev(&quickref, ref->old_oid.hash,
354 DEFAULT_ABBREV);
5ece083f 355 if (ref->forced_update) {
bd22d4ff 356 strbuf_addstr(&quickref, "...");
64fcef2d
DB
357 type = '+';
358 msg = "forced update";
359 } else {
bd22d4ff 360 strbuf_addstr(&quickref, "..");
64fcef2d
DB
361 type = ' ';
362 msg = NULL;
363 }
1eb47f16
RS
364 strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,
365 DEFAULT_ABBREV);
64fcef2d 366
7101e10c
JH
367 print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg,
368 porcelain, summary_width);
bd22d4ff 369 strbuf_release(&quickref);
64fcef2d
DB
370 }
371}
372
7101e10c
JH
373static int print_one_push_status(struct ref *ref, const char *dest, int count,
374 int porcelain, int summary_width)
64fcef2d 375{
882d49ca
JK
376 if (!count) {
377 char *url = transport_anonymize_url(dest);
378 fprintf(porcelain ? stdout : stderr, "To %s\n", url);
379 free(url);
380 }
64fcef2d
DB
381
382 switch(ref->status) {
383 case REF_STATUS_NONE:
7101e10c
JH
384 print_ref_status('X', "[no match]", ref, NULL, NULL,
385 porcelain, summary_width);
64fcef2d
DB
386 break;
387 case REF_STATUS_REJECT_NODELETE:
388 print_ref_status('!', "[rejected]", ref, NULL,
7101e10c
JH
389 "remote does not support deleting refs",
390 porcelain, summary_width);
64fcef2d
DB
391 break;
392 case REF_STATUS_UPTODATE:
393 print_ref_status('=', "[up to date]", ref,
7101e10c 394 ref->peer_ref, NULL, porcelain, summary_width);
64fcef2d
DB
395 break;
396 case REF_STATUS_REJECT_NONFASTFORWARD:
397 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
7101e10c 398 "non-fast-forward", porcelain, summary_width);
64fcef2d 399 break;
dbfeddb1
CR
400 case REF_STATUS_REJECT_ALREADY_EXISTS:
401 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
7101e10c 402 "already exists", porcelain, summary_width);
dbfeddb1 403 break;
75e5c0dc
JH
404 case REF_STATUS_REJECT_FETCH_FIRST:
405 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
7101e10c 406 "fetch first", porcelain, summary_width);
75e5c0dc
JH
407 break;
408 case REF_STATUS_REJECT_NEEDS_FORCE:
409 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
7101e10c 410 "needs force", porcelain, summary_width);
75e5c0dc 411 break;
631b5ef2
JH
412 case REF_STATUS_REJECT_STALE:
413 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
7101e10c 414 "stale info", porcelain, summary_width);
631b5ef2 415 break;
4820a33b
NTND
416 case REF_STATUS_REJECT_SHALLOW:
417 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
7101e10c
JH
418 "new shallow roots not allowed",
419 porcelain, summary_width);
4820a33b 420 break;
64fcef2d
DB
421 case REF_STATUS_REMOTE_REJECT:
422 print_ref_status('!', "[remote rejected]", ref,
7101e10c
JH
423 ref->deletion ? NULL : ref->peer_ref,
424 ref->remote_status, porcelain, summary_width);
64fcef2d
DB
425 break;
426 case REF_STATUS_EXPECTING_REPORT:
427 print_ref_status('!', "[remote failure]", ref,
7101e10c
JH
428 ref->deletion ? NULL : ref->peer_ref,
429 "remote failed to report status",
430 porcelain, summary_width);
64fcef2d 431 break;
4ff17f10
RS
432 case REF_STATUS_ATOMIC_PUSH_FAILED:
433 print_ref_status('!', "[rejected]", ref, ref->peer_ref,
7101e10c 434 "atomic push failed", porcelain, summary_width);
4ff17f10 435 break;
64fcef2d 436 case REF_STATUS_OK:
7101e10c 437 print_ok_ref_status(ref, porcelain, summary_width);
64fcef2d
DB
438 break;
439 }
440
441 return 1;
442}
443
db98d9ba
JH
444static int measure_abbrev(const struct object_id *oid, int sofar)
445{
446 char hex[GIT_SHA1_HEXSZ + 1];
447 int w = find_unique_abbrev_r(hex, oid->hash, DEFAULT_ABBREV);
448
449 return (w < sofar) ? sofar : w;
450}
451
11fd66de
JH
452int transport_summary_width(const struct ref *refs)
453{
db98d9ba
JH
454 int maxw = -1;
455
456 for (; refs; refs = refs->next) {
457 maxw = measure_abbrev(&refs->old_oid, maxw);
458 maxw = measure_abbrev(&refs->new_oid, maxw);
459 }
460 if (maxw < 0)
461 maxw = FALLBACK_DEFAULT_ABBREV;
462 return (2 * maxw + 3);
11fd66de
JH
463}
464
f1863d0d 465void transport_print_push_status(const char *dest, struct ref *refs,
10643d4e 466 int verbose, int porcelain, unsigned int *reject_reasons)
64fcef2d
DB
467{
468 struct ref *ref;
469 int n = 0;
f25950f3
CT
470 unsigned char head_sha1[20];
471 char *head;
11fd66de 472 int summary_width = transport_summary_width(refs);
f25950f3 473
7695d118 474 head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL);
64fcef2d
DB
475
476 if (verbose) {
477 for (ref = refs; ref; ref = ref->next)
478 if (ref->status == REF_STATUS_UPTODATE)
7101e10c
JH
479 n += print_one_push_status(ref, dest, n,
480 porcelain, summary_width);
64fcef2d
DB
481 }
482
483 for (ref = refs; ref; ref = ref->next)
484 if (ref->status == REF_STATUS_OK)
7101e10c
JH
485 n += print_one_push_status(ref, dest, n,
486 porcelain, summary_width);
64fcef2d 487
10643d4e 488 *reject_reasons = 0;
64fcef2d
DB
489 for (ref = refs; ref; ref = ref->next) {
490 if (ref->status != REF_STATUS_NONE &&
491 ref->status != REF_STATUS_UPTODATE &&
492 ref->status != REF_STATUS_OK)
7101e10c
JH
493 n += print_one_push_status(ref, dest, n,
494 porcelain, summary_width);
10643d4e 495 if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) {
1d2c14df 496 if (head != NULL && !strcmp(head, ref->name))
10643d4e 497 *reject_reasons |= REJECT_NON_FF_HEAD;
f25950f3 498 else
10643d4e 499 *reject_reasons |= REJECT_NON_FF_OTHER;
dbfeddb1
CR
500 } else if (ref->status == REF_STATUS_REJECT_ALREADY_EXISTS) {
501 *reject_reasons |= REJECT_ALREADY_EXISTS;
75e5c0dc
JH
502 } else if (ref->status == REF_STATUS_REJECT_FETCH_FIRST) {
503 *reject_reasons |= REJECT_FETCH_FIRST;
504 } else if (ref->status == REF_STATUS_REJECT_NEEDS_FORCE) {
505 *reject_reasons |= REJECT_NEEDS_FORCE;
f25950f3 506 }
64fcef2d 507 }
dc76c7f7 508 free(head);
64fcef2d
DB
509}
510
f1863d0d 511void transport_verify_remote_names(int nr_heads, const char **heads)
64fcef2d
DB
512{
513 int i;
514
515 for (i = 0; i < nr_heads; i++) {
516 const char *local = heads[i];
517 const char *remote = strrchr(heads[i], ':');
518
519 if (*local == '+')
520 local++;
521
522 /* A matching refspec is okay. */
523 if (remote == local && remote[1] == '\0')
524 continue;
525
526 remote = remote ? (remote + 1) : local;
8d9c5010
MH
527 if (check_refname_format(remote,
528 REFNAME_ALLOW_ONELEVEL|REFNAME_REFSPEC_PATTERN))
529 die("remote part of refspec is not a valid name in %s",
530 heads[i]);
64fcef2d
DB
531 }
532}
533
534static int git_transport_push(struct transport *transport, struct ref *remote_refs, int flags)
f3fa1838 535{
9b288516 536 struct git_transport_data *data = transport->data;
40cb4fab 537 struct send_pack_args args;
64fcef2d
DB
538 int ret;
539
61b075bd 540 if (!data->got_remote_heads) {
64fcef2d 541 struct ref *tmp_refs;
f3ee9ca5 542 connect_setup(transport, 1);
64fcef2d 543
b016918b
NTND
544 get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL,
545 NULL, &data->shallow);
61b075bd 546 data->got_remote_heads = 1;
64fcef2d 547 }
9b288516 548
de1a2fdd 549 memset(&args, 0, sizeof(args));
94c89ba6 550 args.send_mirror = !!(flags & TRANSPORT_PUSH_MIRROR);
40cb4fab 551 args.force_update = !!(flags & TRANSPORT_PUSH_FORCE);
aa5af974 552 args.use_thin_pack = data->options.thin;
8afd8dc0
TRC
553 args.verbose = (transport->verbose > 0);
554 args.quiet = (transport->verbose < 0);
d7c411b7 555 args.progress = transport->progress;
40cb4fab 556 args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN);
77555854 557 args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN);
d0e8e09c 558 args.atomic = !!(flags & TRANSPORT_PUSH_ATOMIC);
f6a4e61f 559 args.push_options = transport->push_options;
9be89160 560 args.url = transport->url;
40cb4fab 561
30261094
DB
562 if (flags & TRANSPORT_PUSH_CERT_ALWAYS)
563 args.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
564 else if (flags & TRANSPORT_PUSH_CERT_IF_ASKED)
565 args.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED;
566 else
567 args.push_cert = SEND_PACK_PUSH_CERT_NEVER;
568
64fcef2d
DB
569 ret = send_pack(&args, data->fd, data->conn, remote_refs,
570 &data->extra_have);
571
572 close(data->fd[1]);
573 close(data->fd[0]);
574 ret |= finish_connect(data->conn);
575 data->conn = NULL;
61b075bd 576 data->got_remote_heads = 0;
64fcef2d
DB
577
578 return ret;
9b288516
DB
579}
580
b236752a
IL
581static int connect_git(struct transport *transport, const char *name,
582 const char *executable, int fd[2])
583{
584 struct git_transport_data *data = transport->data;
585 data->conn = git_connect(data->fd, transport->url,
586 executable, 0);
587 fd[0] = data->fd[0];
588 fd[1] = data->fd[1];
589 return 0;
590}
591
f4e95765
SP
592static int disconnect_git(struct transport *transport)
593{
ba227857
DB
594 struct git_transport_data *data = transport->data;
595 if (data->conn) {
61b075bd
IL
596 if (data->got_remote_heads)
597 packet_flush(data->fd[1]);
ba227857
DB
598 close(data->fd[0]);
599 close(data->fd[1]);
600 finish_connect(data->conn);
601 }
602
603 free(data);
f4e95765
SP
604 return 0;
605}
606
61b075bd
IL
607void transport_take_over(struct transport *transport,
608 struct child_process *child)
609{
610 struct git_transport_data *data;
611
612 if (!transport->smart_options)
ef1177d1 613 die("BUG: taking over transport requires non-NULL "
61b075bd
IL
614 "smart_options field.");
615
616 data = xcalloc(1, sizeof(*data));
617 data->options = *transport->smart_options;
618 data->conn = child;
619 data->fd[0] = data->conn->out;
620 data->fd[1] = data->conn->in;
621 data->got_remote_heads = 0;
622 transport->data = data;
623
624 transport->set_option = NULL;
625 transport->get_refs_list = get_refs_via_connect;
626 transport->fetch = fetch_refs_via_pack;
627 transport->push = NULL;
628 transport->push_refs = git_transport_push;
629 transport->disconnect = disconnect_git;
630 transport->smart_options = &(data->options);
b26ed430
JH
631
632 transport->cannot_reuse = 1;
61b075bd
IL
633}
634
9b288516
DB
635static int is_file(const char *url)
636{
637 struct stat buf;
638 if (stat(url, &buf))
639 return 0;
640 return S_ISREG(buf.st_mode);
641}
642
25d5cc48
IL
643static int external_specification_len(const char *url)
644{
645 return strchr(url, ':') - url;
646}
647
5088d3b3 648static const struct string_list *protocol_whitelist(void)
a5adaced 649{
5088d3b3
JK
650 static int enabled = -1;
651 static struct string_list allowed = STRING_LIST_INIT_DUP;
a5adaced 652
5088d3b3
JK
653 if (enabled < 0) {
654 const char *v = getenv("GIT_ALLOW_PROTOCOL");
655 if (v) {
656 string_list_split(&allowed, v, ':', -1);
657 string_list_sort(&allowed);
658 enabled = 1;
659 } else {
660 enabled = 0;
661 }
662 }
663
664 return enabled ? &allowed : NULL;
665}
a5adaced 666
5088d3b3
JK
667int is_transport_allowed(const char *type)
668{
669 const struct string_list *allowed = protocol_whitelist();
670 return !allowed || string_list_has_string(allowed, type);
671}
672
673void transport_check_allowed(const char *type)
674{
675 if (!is_transport_allowed(type))
a5adaced 676 die("transport '%s' not allowed", type);
5088d3b3
JK
677}
678
679int transport_restrict_protocols(void)
680{
681 return !!protocol_whitelist();
a5adaced
JK
682}
683
e5f4e214 684struct transport *transport_get(struct remote *remote, const char *url)
9b288516 685{
4da50460 686 const char *helper;
8eb554ae
SP
687 struct transport *ret = xcalloc(1, sizeof(*ret));
688
d01b3c02
TRC
689 ret->progress = isatty(2);
690
c1d45cf7
DB
691 if (!remote)
692 die("No remote provided to transport_get()");
693
b0d66e15 694 ret->got_remote_refs = 0;
8eb554ae 695 ret->remote = remote;
4da50460 696 helper = remote->foreign_vcs;
fb0cc87e 697
cb21d8f0 698 if (!url && remote->url)
fb0cc87e 699 url = remote->url[0];
8eb554ae 700 ret->url = url;
8eb554ae 701
87422439
JS
702 /* maybe it is a foreign URL? */
703 if (url) {
704 const char *p = url;
705
638794cd 706 while (is_urlschemechar(p == url, *p))
87422439 707 p++;
59556548 708 if (starts_with(p, "::"))
4da50460 709 helper = xstrndup(url, p - url);
87422439
JS
710 }
711
4da50460
IL
712 if (helper) {
713 transport_helper_init(ret, helper);
59556548 714 } else if (starts_with(url, "rsync:")) {
0d0bac67 715 die("git-over-rsync is no longer supported");
c59ab2e5 716 } else if (url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)) {
c7a8a162 717 struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
a5adaced 718 transport_check_allowed("file");
c7a8a162 719 ret->data = data;
824d5776
SP
720 ret->get_refs_list = get_refs_from_bundle;
721 ret->fetch = fetch_refs_from_bundle;
722 ret->disconnect = close_bundle;
aa5af974 723 ret->smart_options = NULL;
25d5cc48 724 } else if (!is_url(url)
59556548
CC
725 || starts_with(url, "file://")
726 || starts_with(url, "git://")
727 || starts_with(url, "ssh://")
07c7782c
CMN
728 || starts_with(url, "git+ssh://") /* deprecated - do not use */
729 || starts_with(url, "ssh+git://") /* deprecated - do not use */
730 ) {
a5adaced
JK
731 /*
732 * These are builtin smart transports; "allowed" transports
733 * will be checked individually in git_connect.
734 */
9b288516 735 struct git_transport_data *data = xcalloc(1, sizeof(*data));
9b288516 736 ret->data = data;
aa5af974 737 ret->set_option = NULL;
824d5776
SP
738 ret->get_refs_list = get_refs_via_connect;
739 ret->fetch = fetch_refs_via_pack;
64fcef2d 740 ret->push_refs = git_transport_push;
b236752a 741 ret->connect = connect_git;
f4e95765 742 ret->disconnect = disconnect_git;
aa5af974 743 ret->smart_options = &(data->options);
824d5776 744
ba227857 745 data->conn = NULL;
61b075bd 746 data->got_remote_heads = 0;
25d5cc48
IL
747 } else {
748 /* Unknown protocol in URL. Pass to external handler. */
749 int len = external_specification_len(url);
6b33894f 750 char *handler = xmemdupz(url, len);
25d5cc48 751 transport_helper_init(ret, handler);
9b288516 752 }
8eb554ae 753
aa5af974
IL
754 if (ret->smart_options) {
755 ret->smart_options->thin = 1;
756 ret->smart_options->uploadpack = "git-upload-pack";
757 if (remote->uploadpack)
758 ret->smart_options->uploadpack = remote->uploadpack;
759 ret->smart_options->receivepack = "git-receive-pack";
760 if (remote->receivepack)
761 ret->smart_options->receivepack = remote->receivepack;
762 }
763
9b288516
DB
764 return ret;
765}
766
767int transport_set_option(struct transport *transport,
768 const char *name, const char *value)
769{
aa5af974
IL
770 int git_reports = 1, protocol_reports = 1;
771
772 if (transport->smart_options)
773 git_reports = set_git_option(transport->smart_options,
774 name, value);
775
824d5776 776 if (transport->set_option)
aa5af974
IL
777 protocol_reports = transport->set_option(transport, name,
778 value);
779
780 /* If either report is 0, report 0 (success). */
781 if (!git_reports || !protocol_reports)
782 return 0;
783 /* If either reports -1 (invalid value), report -1. */
784 if ((git_reports == -1) || (protocol_reports == -1))
785 return -1;
786 /* Otherwise if both report unknown, report unknown. */
ab865e6e 787 return 1;
9b288516
DB
788}
789
d01b3c02
TRC
790void transport_set_verbosity(struct transport *transport, int verbosity,
791 int force_progress)
bde873c5 792{
bd2c86ef 793 if (verbosity >= 1)
bde873c5
TRC
794 transport->verbose = verbosity <= 3 ? verbosity : 3;
795 if (verbosity < 0)
796 transport->verbose = -1;
d01b3c02
TRC
797
798 /**
799 * Rules used to determine whether to report progress (processing aborts
800 * when a rule is satisfied):
801 *
01fdc21f
CB
802 * . Report progress, if force_progress is 1 (ie. --progress).
803 * . Don't report progress, if force_progress is 0 (ie. --no-progress).
804 * . Don't report progress, if verbosity < 0 (ie. -q/--quiet ).
805 * . Report progress if isatty(2) is 1.
d01b3c02 806 **/
01fdc21f
CB
807 if (force_progress >= 0)
808 transport->progress = !!force_progress;
809 else
810 transport->progress = verbosity >= 0 && isatty(2);
bde873c5
TRC
811}
812
a762e51e
HV
813static void die_with_unpushed_submodules(struct string_list *needs_pushing)
814{
815 int i;
816
7ab1d44f
VA
817 fprintf(stderr, _("The following submodule paths contain changes that can\n"
818 "not be found on any remote:\n"));
a762e51e 819 for (i = 0; i < needs_pushing->nr; i++)
5cb5fe4a 820 fprintf(stderr, " %s\n", needs_pushing->items[i].string);
7ab1d44f
VA
821 fprintf(stderr, _("\nPlease try\n\n"
822 " git push --recurse-submodules=on-demand\n\n"
823 "or cd to the path and use\n\n"
824 " git push\n\n"
825 "to push them to a remote.\n\n"));
a762e51e
HV
826
827 string_list_clear(needs_pushing, 0);
828
7ab1d44f 829 die(_("Aborting."));
a762e51e
HV
830}
831
ec55559f
AS
832static int run_pre_push_hook(struct transport *transport,
833 struct ref *remote_refs)
834{
835 int ret = 0, x;
836 struct ref *r;
d3180279 837 struct child_process proc = CHILD_PROCESS_INIT;
ec55559f
AS
838 struct strbuf buf;
839 const char *argv[4];
840
841 if (!(argv[0] = find_hook("pre-push")))
842 return 0;
843
844 argv[1] = transport->remote->name;
845 argv[2] = transport->url;
846 argv[3] = NULL;
847
ec55559f
AS
848 proc.argv = argv;
849 proc.in = -1;
850
851 if (start_command(&proc)) {
852 finish_command(&proc);
853 return -1;
854 }
855
af65f68c
CB
856 sigchain_push(SIGPIPE, SIG_IGN);
857
ec55559f
AS
858 strbuf_init(&buf, 256);
859
860 for (r = remote_refs; r; r = r->next) {
861 if (!r->peer_ref) continue;
862 if (r->status == REF_STATUS_REJECT_NONFASTFORWARD) continue;
631b5ef2 863 if (r->status == REF_STATUS_REJECT_STALE) continue;
ec55559f
AS
864 if (r->status == REF_STATUS_UPTODATE) continue;
865
866 strbuf_reset(&buf);
867 strbuf_addf( &buf, "%s %s %s %s\n",
f4e54d02 868 r->peer_ref->name, oid_to_hex(&r->new_oid),
869 r->name, oid_to_hex(&r->old_oid));
ec55559f 870
af65f68c
CB
871 if (write_in_full(proc.in, buf.buf, buf.len) < 0) {
872 /* We do not mind if a hook does not read all refs. */
873 if (errno != EPIPE)
874 ret = -1;
ec55559f
AS
875 break;
876 }
877 }
878
879 strbuf_release(&buf);
880
881 x = close(proc.in);
882 if (!ret)
883 ret = x;
884
af65f68c
CB
885 sigchain_pop(SIGPIPE);
886
ec55559f
AS
887 x = finish_command(&proc);
888 if (!ret)
889 ret = x;
890
891 return ret;
892}
893
9b288516 894int transport_push(struct transport *transport,
07436e43 895 int refspec_nr, const char **refspec, int flags,
10643d4e 896 unsigned int *reject_reasons)
9b288516 897{
10643d4e 898 *reject_reasons = 0;
f1863d0d 899 transport_verify_remote_names(refspec_nr, refspec);
64fcef2d 900
61b075bd 901 if (transport->push) {
e9fcd1e2
IL
902 /* Maybe FIXME. But no important transport uses this case. */
903 if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
904 die("This transport does not support using --set-upstream");
905
64fcef2d 906 return transport->push(transport, refspec_nr, refspec, flags);
61b075bd 907 } else if (transport->push_refs) {
ba928c13 908 struct ref *remote_refs;
64fcef2d
DB
909 struct ref *local_refs = get_local_heads();
910 int match_flags = MATCH_REFS_NONE;
8afd8dc0
TRC
911 int verbose = (transport->verbose > 0);
912 int quiet = (transport->verbose < 0);
1965ff74 913 int porcelain = flags & TRANSPORT_PUSH_PORCELAIN;
e9fcd1e2 914 int pretend = flags & TRANSPORT_PUSH_DRY_RUN;
77555854 915 int push_ret, ret, err;
64fcef2d 916
ba928c13
JK
917 if (check_push_refs(local_refs, refspec_nr, refspec) < 0)
918 return -1;
919
920 remote_refs = transport->get_refs_list(transport, 1);
921
64fcef2d
DB
922 if (flags & TRANSPORT_PUSH_ALL)
923 match_flags |= MATCH_REFS_ALL;
924 if (flags & TRANSPORT_PUSH_MIRROR)
925 match_flags |= MATCH_REFS_MIRROR;
6ddba5e2
FC
926 if (flags & TRANSPORT_PUSH_PRUNE)
927 match_flags |= MATCH_REFS_PRUNE;
c2aba155
JH
928 if (flags & TRANSPORT_PUSH_FOLLOW_TAGS)
929 match_flags |= MATCH_REFS_FOLLOW_TAGS;
64fcef2d 930
29753cdd
JH
931 if (match_push_refs(local_refs, &remote_refs,
932 refspec_nr, refspec, match_flags)) {
64fcef2d
DB
933 return -1;
934 }
935
91048a95
JH
936 if (transport->smart_options &&
937 transport->smart_options->cas &&
938 !is_empty_cas(transport->smart_options->cas))
939 apply_push_cas(transport->smart_options->cas,
940 transport->remote, remote_refs);
941
20e8b465
TRC
942 set_ref_status_for_push(remote_refs,
943 flags & TRANSPORT_PUSH_MIRROR,
944 flags & TRANSPORT_PUSH_FORCE);
945
ec55559f
AS
946 if (!(flags & TRANSPORT_PUSH_NO_HOOK))
947 if (run_pre_push_hook(transport, remote_refs))
948 return -1;
949
eb21c732 950 if ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) && !is_bare_repository()) {
d2b17b32 951 struct ref *ref = remote_refs;
9cfa1c26
HV
952 struct sha1_array commits = SHA1_ARRAY_INIT;
953
d2b17b32 954 for (; ref; ref = ref->next)
9cfa1c26
HV
955 if (!is_null_oid(&ref->new_oid))
956 sha1_array_append(&commits, ref->new_oid.hash);
957
0301c821
BW
958 if (!push_unpushed_submodules(&commits,
959 transport->remote->name,
960 pretend)) {
9cfa1c26
HV
961 sha1_array_clear(&commits);
962 die("Failed to push all needed submodules!");
963 }
964 sha1_array_clear(&commits);
eb21c732
HV
965 }
966
0301c821
BW
967 if (((flags & TRANSPORT_RECURSE_SUBMODULES_CHECK) ||
968 ((flags & TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND) &&
969 !pretend)) && !is_bare_repository()) {
d2b17b32 970 struct ref *ref = remote_refs;
f93d7c6f 971 struct string_list needs_pushing = STRING_LIST_INIT_DUP;
9cfa1c26 972 struct sha1_array commits = SHA1_ARRAY_INIT;
a762e51e 973
d2b17b32 974 for (; ref; ref = ref->next)
9cfa1c26
HV
975 if (!is_null_oid(&ref->new_oid))
976 sha1_array_append(&commits, ref->new_oid.hash);
977
978 if (find_unpushed_submodules(&commits, transport->remote->name,
979 &needs_pushing)) {
980 sha1_array_clear(&commits);
981 die_with_unpushed_submodules(&needs_pushing);
982 }
983 string_list_clear(&needs_pushing, 0);
984 sha1_array_clear(&commits);
d2b17b32
FG
985 }
986
77555854 987 push_ret = transport->push_refs(transport, remote_refs, flags);
42328267 988 err = push_had_errors(remote_refs);
77555854 989 ret = push_ret | err;
64fcef2d 990
42328267 991 if (!quiet || err)
f1863d0d 992 transport_print_push_status(transport->url, remote_refs,
6ffd7812 993 verbose | porcelain, porcelain,
10643d4e 994 reject_reasons);
64fcef2d 995
e9fcd1e2
IL
996 if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
997 set_upstreams(transport, remote_refs, pretend);
998
64fcef2d
DB
999 if (!(flags & TRANSPORT_PUSH_DRY_RUN)) {
1000 struct ref *ref;
1001 for (ref = remote_refs; ref; ref = ref->next)
f1863d0d 1002 transport_update_tracking_ref(transport->remote, ref, verbose);
64fcef2d
DB
1003 }
1004
77555854
LA
1005 if (porcelain && !push_ret)
1006 puts("Done");
66bce02e 1007 else if (!quiet && !ret && !transport_refs_pushed(remote_refs))
64fcef2d 1008 fprintf(stderr, "Everything up-to-date\n");
77555854 1009
64fcef2d
DB
1010 return ret;
1011 }
1012 return 1;
9b288516
DB
1013}
1014
4577370e 1015const struct ref *transport_get_remote_refs(struct transport *transport)
c29727d5 1016{
b0d66e15 1017 if (!transport->got_remote_refs) {
64fcef2d 1018 transport->remote_refs = transport->get_refs_list(transport, 0);
b0d66e15
TRC
1019 transport->got_remote_refs = 1;
1020 }
61b075bd 1021
c29727d5
DB
1022 return transport->remote_refs;
1023}
1024
37148311 1025int transport_fetch_refs(struct transport *transport, struct ref *refs)
c29727d5 1026{
425b1393 1027 int rc;
86386829 1028 int nr_heads = 0, nr_alloc = 0, nr_refs = 0;
37148311
DB
1029 struct ref **heads = NULL;
1030 struct ref *rm;
c29727d5
DB
1031
1032 for (rm = refs; rm; rm = rm->next) {
86386829 1033 nr_refs++;
c29727d5 1034 if (rm->peer_ref &&
f4e54d02 1035 !is_null_oid(&rm->old_oid) &&
1036 !oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))
c29727d5 1037 continue;
7a2bff45 1038 ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
425b1393 1039 heads[nr_heads++] = rm;
c29727d5
DB
1040 }
1041
86386829
NP
1042 if (!nr_heads) {
1043 /*
1044 * When deepening of a shallow repository is requested,
1045 * then local and remote refs are likely to still be equal.
1046 * Just feed them all to the fetch method in that case.
1047 * This condition shouldn't be met in a non-deepening fetch
09b7e220 1048 * (see builtin/fetch.c:quickfetch()).
86386829 1049 */
b32fa95f 1050 ALLOC_ARRAY(heads, nr_refs);
86386829
NP
1051 for (rm = refs; rm; rm = rm->next)
1052 heads[nr_heads++] = rm;
1053 }
1054
824d5776 1055 rc = transport->fetch(transport, nr_heads, heads);
61b075bd 1056
c29727d5 1057 free(heads);
425b1393 1058 return rc;
c29727d5
DB
1059}
1060
1788c39c
SP
1061void transport_unlock_pack(struct transport *transport)
1062{
1063 if (transport->pack_lockfile) {
691f1a28 1064 unlink_or_warn(transport->pack_lockfile);
1788c39c
SP
1065 free(transport->pack_lockfile);
1066 transport->pack_lockfile = NULL;
1067 }
1068}
1069
b236752a
IL
1070int transport_connect(struct transport *transport, const char *name,
1071 const char *exec, int fd[2])
1072{
1073 if (transport->connect)
1074 return transport->connect(transport, name, exec, fd);
1075 else
1076 die("Operation not supported by protocol");
1077}
1078
9b288516
DB
1079int transport_disconnect(struct transport *transport)
1080{
1081 int ret = 0;
824d5776
SP
1082 if (transport->disconnect)
1083 ret = transport->disconnect(transport);
9b288516
DB
1084 free(transport);
1085 return ret;
1086}
47abd85b
AE
1087
1088/*
a7793a74 1089 * Strip username (and password) from a URL and return
47abd85b
AE
1090 * it in a newly allocated string.
1091 */
1092char *transport_anonymize_url(const char *url)
1093{
21f9d0f6 1094 char *scheme_prefix, *anon_part;
47abd85b
AE
1095 size_t anon_len, prefix_len = 0;
1096
1097 anon_part = strchr(url, '@');
c59ab2e5 1098 if (url_is_local_not_ssh(url) || !anon_part)
47abd85b
AE
1099 goto literal_copy;
1100
1101 anon_len = strlen(++anon_part);
1102 scheme_prefix = strstr(url, "://");
1103 if (!scheme_prefix) {
1104 if (!strchr(anon_part, ':'))
1105 /* cannot be "me@there:/path/name" */
1106 goto literal_copy;
1107 } else {
1108 const char *cp;
1109 /* make sure scheme is reasonable */
1110 for (cp = url; cp < scheme_prefix; cp++) {
1111 switch (*cp) {
1112 /* RFC 1738 2.1 */
1113 case '+': case '.': case '-':
1114 break; /* ok */
1115 default:
1116 if (isalnum(*cp))
1117 break;
1118 /* it isn't */
1119 goto literal_copy;
1120 }
1121 }
1122 /* @ past the first slash does not count */
1123 cp = strchr(scheme_prefix + 3, '/');
1124 if (cp && cp < anon_part)
1125 goto literal_copy;
1126 prefix_len = scheme_prefix - url + 3;
1127 }
21f9d0f6
JK
1128 return xstrfmt("%.*s%.*s", (int)prefix_len, url,
1129 (int)anon_len, anon_part);
47abd85b
AE
1130literal_copy:
1131 return xstrdup(url);
1132}
36cfda15 1133
114a6a88
JK
1134struct alternate_refs_data {
1135 alternate_ref_fn *fn;
1136 void *data;
1137};
1138
1139static int refs_from_alternate_cb(struct alternate_object_database *e,
1140 void *data)
36cfda15
JH
1141{
1142 char *other;
1143 size_t len;
1144 struct remote *remote;
1145 struct transport *transport;
1146 const struct ref *extra;
114a6a88 1147 struct alternate_refs_data *cb = data;
36cfda15 1148
597f9134 1149 other = xstrdup(real_path(e->path));
36cfda15
JH
1150 len = strlen(other);
1151
1152 while (other[len-1] == '/')
1153 other[--len] = '\0';
1154 if (len < 8 || memcmp(other + len - 8, "/objects", 8))
def06971 1155 goto out;
36cfda15
JH
1156 /* Is this a git repository with refs? */
1157 memcpy(other + len - 8, "/refs", 6);
1158 if (!is_directory(other))
def06971 1159 goto out;
36cfda15
JH
1160 other[len - 8] = '\0';
1161 remote = remote_get(other);
1162 transport = transport_get(remote, other);
1163 for (extra = transport_get_remote_refs(transport);
1164 extra;
1165 extra = extra->next)
114a6a88 1166 cb->fn(extra, cb->data);
36cfda15 1167 transport_disconnect(transport);
def06971 1168out:
36cfda15
JH
1169 free(other);
1170 return 0;
1171}
114a6a88
JK
1172
1173void for_each_alternate_ref(alternate_ref_fn fn, void *data)
1174{
1175 struct alternate_refs_data cb;
1176 cb.fn = fn;
1177 cb.data = data;
1178 foreach_alt_odb(refs_from_alternate_cb, &cb);
1179}