]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/receive-pack.c
send-pack: factor out capability string generation
[thirdparty/git.git] / builtin / receive-pack.c
CommitLineData
1e4cd68c 1#include "builtin.h"
fc04c412 2#include "pack.h"
8a65ff76 3#include "refs.h"
f3a3214e 4#include "pkt-line.h"
38a81b4e 5#include "sideband.h"
b1bf95bb 6#include "run-command.h"
576162a4 7#include "exec_cmd.h"
11031d7e
JS
8#include "commit.h"
9#include "object.h"
d79796bc 10#include "remote.h"
47a59185 11#include "connect.h"
d79796bc 12#include "transport.h"
da3efdb1 13#include "string-list.h"
cff38a5e 14#include "sha1-array.h"
52fed6e1 15#include "connected.h"
31c42bff 16#include "argv-array.h"
ff5effdf 17#include "version.h"
575f4974 18
34263de0 19static const char receive_pack_usage[] = "git receive-pack <git-dir>";
575f4974 20
986e8239 21enum deny_action {
3d95d92b 22 DENY_UNCONFIGURED,
986e8239
JK
23 DENY_IGNORE,
24 DENY_WARN,
4b05548f 25 DENY_REFUSE
986e8239
JK
26};
27
1b53a076
JH
28static int deny_deletes;
29static int deny_non_fast_forwards;
3d95d92b 30static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
747ca245 31static enum deny_action deny_delete_current = DENY_UNCONFIGURED;
dab76d3a
JH
32static int receive_fsck_objects = -1;
33static int transfer_fsck_objects = -1;
e28714c5
JH
34static int receive_unpack_limit = -1;
35static int transfer_unpack_limit = -1;
46732fae 36static int unpack_limit = 100;
96f1e58f 37static int report_status;
38a81b4e 38static int use_sideband;
c207e34f 39static int quiet;
b74fce16 40static int prefer_ofs_delta = 1;
77e3efbf
JH
41static int auto_update_server_info;
42static int auto_gc = 1;
f7c815c3 43static int fix_thin = 1;
747ca245 44static const char *head_name;
96ec7b1e 45static void *head_name_to_free;
185c04e0 46static int sent_capabilities;
0a1bc12b 47static int shallow_update;
5dbd7676 48static const char *alt_shallow_file;
cfee10a7 49
986e8239
JK
50static enum deny_action parse_deny_action(const char *var, const char *value)
51{
52 if (value) {
53 if (!strcasecmp(value, "ignore"))
54 return DENY_IGNORE;
55 if (!strcasecmp(value, "warn"))
56 return DENY_WARN;
57 if (!strcasecmp(value, "refuse"))
58 return DENY_REFUSE;
59 }
60 if (git_config_bool(var, value))
61 return DENY_REFUSE;
62 return DENY_IGNORE;
63}
64
ef90d6d4 65static int receive_pack_config(const char *var, const char *value, void *cb)
6fb75bed 66{
daebaa78
JH
67 int status = parse_hide_refs_config(var, value, "receive");
68
69 if (status)
70 return status;
71
a240de11
JK
72 if (strcmp(var, "receive.denydeletes") == 0) {
73 deny_deletes = git_config_bool(var, value);
74 return 0;
75 }
76
e28714c5 77 if (strcmp(var, "receive.denynonfastforwards") == 0) {
6fb75bed
SP
78 deny_non_fast_forwards = git_config_bool(var, value);
79 return 0;
80 }
81
e28714c5
JH
82 if (strcmp(var, "receive.unpacklimit") == 0) {
83 receive_unpack_limit = git_config_int(var, value);
fc04c412
SP
84 return 0;
85 }
86
e28714c5
JH
87 if (strcmp(var, "transfer.unpacklimit") == 0) {
88 transfer_unpack_limit = git_config_int(var, value);
89 return 0;
90 }
91
20dc0016
MK
92 if (strcmp(var, "receive.fsckobjects") == 0) {
93 receive_fsck_objects = git_config_bool(var, value);
94 return 0;
95 }
96
dab76d3a
JH
97 if (strcmp(var, "transfer.fsckobjects") == 0) {
98 transfer_fsck_objects = git_config_bool(var, value);
99 return 0;
100 }
101
986e8239
JK
102 if (!strcmp(var, "receive.denycurrentbranch")) {
103 deny_current_branch = parse_deny_action(var, value);
104 return 0;
105 }
106
747ca245
JH
107 if (strcmp(var, "receive.denydeletecurrent") == 0) {
108 deny_delete_current = parse_deny_action(var, value);
109 return 0;
110 }
111
b74fce16
NP
112 if (strcmp(var, "repack.usedeltabaseoffset") == 0) {
113 prefer_ofs_delta = git_config_bool(var, value);
114 return 0;
115 }
116
77e3efbf
JH
117 if (strcmp(var, "receive.updateserverinfo") == 0) {
118 auto_update_server_info = git_config_bool(var, value);
119 return 0;
120 }
121
122 if (strcmp(var, "receive.autogc") == 0) {
123 auto_gc = git_config_bool(var, value);
124 return 0;
125 }
126
0a1bc12b
NTND
127 if (strcmp(var, "receive.shallowupdate") == 0) {
128 shallow_update = git_config_bool(var, value);
129 return 0;
130 }
131
ef90d6d4 132 return git_default_config(var, value, cb);
6fb75bed
SP
133}
134
bc98201d 135static void show_ref(const char *path, const unsigned char *sha1)
575f4974 136{
daebaa78
JH
137 if (ref_is_hidden(path))
138 return;
139
185c04e0 140 if (sent_capabilities)
cfee10a7
JH
141 packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
142 else
ff5effdf 143 packet_write(1, "%s %s%c%s%s agent=%s\n",
185c04e0 144 sha1_to_hex(sha1), path, 0,
c207e34f 145 " report-status delete-refs side-band-64k quiet",
ff5effdf
JK
146 prefer_ofs_delta ? " ofs-delta" : "",
147 git_user_agent_sanitized());
185c04e0 148 sent_capabilities = 1;
575f4974
LT
149}
150
bc98201d 151static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *unused)
6b01ecfe
JT
152{
153 path = strip_namespace(path);
154 /*
155 * Advertise refs outside our current namespace as ".have"
156 * refs, so that the client can use them to minimize data
157 * transfer but will otherwise ignore them. This happens to
158 * cover ".have" that are thrown in by add_one_alternate_ref()
159 * to mark histories that are complete in our alternates as
160 * well.
161 */
162 if (!path)
163 path = ".have";
bc98201d
MH
164 show_ref(path, sha1);
165 return 0;
6b01ecfe
JT
166}
167
85f25104 168static void show_one_alternate_sha1(const unsigned char sha1[20], void *unused)
b7a025d9 169{
85f25104 170 show_ref(".have", sha1);
b7a025d9
MH
171}
172
173static void collect_one_alternate_ref(const struct ref *ref, void *data)
174{
175 struct sha1_array *sa = data;
176 sha1_array_append(sa, ref->old_sha1);
6b01ecfe
JT
177}
178
8a65ff76 179static void write_head_info(void)
575f4974 180{
b7a025d9
MH
181 struct sha1_array sa = SHA1_ARRAY_INIT;
182 for_each_alternate_ref(collect_one_alternate_ref, &sa);
85f25104 183 sha1_array_for_each_unique(&sa, show_one_alternate_sha1, NULL);
b7a025d9 184 sha1_array_clear(&sa);
6b01ecfe 185 for_each_ref(show_ref_cb, NULL);
185c04e0 186 if (!sent_capabilities)
bc98201d 187 show_ref("capabilities^{}", null_sha1);
cfee10a7 188
ad491366
NTND
189 advertise_shallow_grafts(1);
190
b7a025d9
MH
191 /* EOF */
192 packet_flush(1);
575f4974
LT
193}
194
eb1af2df
LT
195struct command {
196 struct command *next;
cfee10a7 197 const char *error_string;
160b81ed
PYH
198 unsigned int skip_update:1,
199 did_not_exist:1;
5dbd7676 200 int index;
eb1af2df
LT
201 unsigned char old_sha1[20];
202 unsigned char new_sha1[20];
8f1d2e6f 203 char ref_name[FLEX_ARRAY]; /* more */
575f4974
LT
204};
205
466dbc42
SP
206static void rp_error(const char *err, ...) __attribute__((format (printf, 1, 2)));
207static void rp_warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
208
209static void report_message(const char *prefix, const char *err, va_list params)
210{
211 int sz = strlen(prefix);
212 char msg[4096];
213
214 strncpy(msg, prefix, sz);
215 sz += vsnprintf(msg + sz, sizeof(msg) - sz, err, params);
216 if (sz > (sizeof(msg) - 1))
217 sz = sizeof(msg) - 1;
218 msg[sz++] = '\n';
219
220 if (use_sideband)
221 send_sideband(1, 2, msg, sz, use_sideband);
222 else
223 xwrite(2, msg, sz);
224}
225
226static void rp_warning(const char *err, ...)
227{
228 va_list params;
229 va_start(params, err);
230 report_message("warning: ", err, params);
231 va_end(params);
232}
233
234static void rp_error(const char *err, ...)
235{
236 va_list params;
237 va_start(params, err);
238 report_message("error: ", err, params);
239 va_end(params);
240}
241
6d525d38
SP
242static int copy_to_sideband(int in, int out, void *arg)
243{
244 char data[128];
245 while (1) {
246 ssize_t sz = xread(in, data, sizeof(data));
247 if (sz <= 0)
248 break;
249 send_sideband(1, 2, data, sz, use_sideband);
250 }
251 close(in);
252 return 0;
253}
254
9684e44a
JH
255typedef int (*feed_fn)(void *, const char **, size_t *);
256static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_state)
b1bf95bb 257{
f43cd49f 258 struct child_process proc;
6d525d38 259 struct async muxer;
f43cd49f 260 const char *argv[2];
9684e44a 261 int code;
b1bf95bb 262
5a7da2dc
AS
263 argv[0] = find_hook(hook_name);
264 if (!argv[0])
b1bf95bb 265 return 0;
c8dd2771 266
f43cd49f
SP
267 argv[1] = NULL;
268
269 memset(&proc, 0, sizeof(proc));
270 proc.argv = argv;
271 proc.in = -1;
272 proc.stdout_to_stderr = 1;
273
6d525d38
SP
274 if (use_sideband) {
275 memset(&muxer, 0, sizeof(muxer));
276 muxer.proc = copy_to_sideband;
277 muxer.in = -1;
278 code = start_async(&muxer);
279 if (code)
280 return code;
281 proc.err = muxer.in;
282 }
283
f43cd49f 284 code = start_command(&proc);
6d525d38
SP
285 if (code) {
286 if (use_sideband)
287 finish_async(&muxer);
90e41a89 288 return code;
6d525d38
SP
289 }
290
9684e44a
JH
291 while (1) {
292 const char *buf;
293 size_t n;
294 if (feed(feed_state, &buf, &n))
295 break;
296 if (write_in_full(proc.in, buf, n) != n)
297 break;
c8dd2771 298 }
e72ae288 299 close(proc.in);
6d525d38
SP
300 if (use_sideband)
301 finish_async(&muxer);
90e41a89 302 return finish_command(&proc);
b1bf95bb
JW
303}
304
9684e44a
JH
305struct receive_hook_feed_state {
306 struct command *cmd;
cdc2b2f3 307 int skip_broken;
9684e44a
JH
308 struct strbuf buf;
309};
310
311static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
312{
313 struct receive_hook_feed_state *state = state_;
314 struct command *cmd = state->cmd;
315
cdc2b2f3
JH
316 while (cmd &&
317 state->skip_broken && (cmd->error_string || cmd->did_not_exist))
9684e44a
JH
318 cmd = cmd->next;
319 if (!cmd)
320 return -1; /* EOF */
321 strbuf_reset(&state->buf);
322 strbuf_addf(&state->buf, "%s %s %s\n",
323 sha1_to_hex(cmd->old_sha1), sha1_to_hex(cmd->new_sha1),
324 cmd->ref_name);
325 state->cmd = cmd->next;
326 if (bufp) {
327 *bufp = state->buf.buf;
328 *sizep = state->buf.len;
329 }
330 return 0;
331}
332
cdc2b2f3
JH
333static int run_receive_hook(struct command *commands, const char *hook_name,
334 int skip_broken)
9684e44a
JH
335{
336 struct receive_hook_feed_state state;
337 int status;
338
339 strbuf_init(&state.buf, 0);
340 state.cmd = commands;
cdc2b2f3 341 state.skip_broken = skip_broken;
9684e44a
JH
342 if (feed_receive_hook(&state, NULL, NULL))
343 return 0;
344 state.cmd = commands;
345 status = run_and_feed_hook(hook_name, feed_receive_hook, &state);
346 strbuf_release(&state.buf);
347 return status;
348}
349
1d9e8b56
SP
350static int run_update_hook(struct command *cmd)
351{
1d9e8b56 352 const char *argv[5];
6d525d38
SP
353 struct child_process proc;
354 int code;
1d9e8b56 355
5a7da2dc
AS
356 argv[0] = find_hook("update");
357 if (!argv[0])
1d9e8b56
SP
358 return 0;
359
1d9e8b56
SP
360 argv[1] = cmd->ref_name;
361 argv[2] = sha1_to_hex(cmd->old_sha1);
362 argv[3] = sha1_to_hex(cmd->new_sha1);
363 argv[4] = NULL;
364
6d525d38
SP
365 memset(&proc, 0, sizeof(proc));
366 proc.no_stdin = 1;
367 proc.stdout_to_stderr = 1;
368 proc.err = use_sideband ? -1 : 0;
369 proc.argv = argv;
370
371 code = start_command(&proc);
372 if (code)
373 return code;
374 if (use_sideband)
375 copy_to_sideband(proc.err, -1, NULL);
376 return finish_command(&proc);
1d9e8b56
SP
377}
378
986e8239
JK
379static int is_ref_checked_out(const char *ref)
380{
986e8239
JK
381 if (is_bare_repository())
382 return 0;
383
747ca245 384 if (!head_name)
986e8239 385 return 0;
747ca245 386 return !strcmp(head_name, ref);
986e8239
JK
387}
388
acd2a45b
JH
389static char *refuse_unconfigured_deny_msg[] = {
390 "By default, updating the current branch in a non-bare repository",
391 "is denied, because it will make the index and work tree inconsistent",
392 "with what you pushed, and will require 'git reset --hard' to match",
393 "the work tree to HEAD.",
3d95d92b
JH
394 "",
395 "You can set 'receive.denyCurrentBranch' configuration variable to",
acd2a45b
JH
396 "'ignore' or 'warn' in the remote repository to allow pushing into",
397 "its current branch; however, this is not recommended unless you",
398 "arranged to update its work tree to match what you pushed in some",
399 "other way.",
3d95d92b 400 "",
acd2a45b
JH
401 "To squelch this message and still keep the default behaviour, set",
402 "'receive.denyCurrentBranch' configuration variable to 'refuse'."
3d95d92b
JH
403};
404
acd2a45b 405static void refuse_unconfigured_deny(void)
3d95d92b
JH
406{
407 int i;
acd2a45b 408 for (i = 0; i < ARRAY_SIZE(refuse_unconfigured_deny_msg); i++)
a886ba28 409 rp_error("%s", refuse_unconfigured_deny_msg[i]);
3d95d92b
JH
410}
411
375881fa
JH
412static char *refuse_unconfigured_deny_delete_current_msg[] = {
413 "By default, deleting the current branch is denied, because the next",
414 "'git clone' won't result in any file checked out, causing confusion.",
747ca245
JH
415 "",
416 "You can set 'receive.denyDeleteCurrent' configuration variable to",
375881fa
JH
417 "'warn' or 'ignore' in the remote repository to allow deleting the",
418 "current branch, with or without a warning message.",
747ca245 419 "",
375881fa 420 "To squelch this message, you can set it to 'refuse'."
747ca245
JH
421};
422
375881fa 423static void refuse_unconfigured_deny_delete_current(void)
747ca245
JH
424{
425 int i;
426 for (i = 0;
375881fa 427 i < ARRAY_SIZE(refuse_unconfigured_deny_delete_current_msg);
747ca245 428 i++)
a886ba28 429 rp_error("%s", refuse_unconfigured_deny_delete_current_msg[i]);
747ca245
JH
430}
431
0a1bc12b
NTND
432static int command_singleton_iterator(void *cb_data, unsigned char sha1[20]);
433static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
434{
435 static struct lock_file shallow_lock;
436 struct sha1_array extra = SHA1_ARRAY_INIT;
437 const char *alt_file;
438 uint32_t mask = 1 << (cmd->index % 32);
439 int i;
440
6aa30857 441 trace_printf_key(&trace_shallow,
0a1bc12b
NTND
442 "shallow: update_shallow_ref %s\n", cmd->ref_name);
443 for (i = 0; i < si->shallow->nr; i++)
444 if (si->used_shallow[i] &&
445 (si->used_shallow[i][cmd->index / 32] & mask) &&
446 !delayed_reachability_test(si, i))
447 sha1_array_append(&extra, si->shallow->sha1[i]);
448
449 setup_alternate_shallow(&shallow_lock, &alt_file, &extra);
450 if (check_shallow_connected(command_singleton_iterator,
451 0, cmd, alt_file)) {
452 rollback_lock_file(&shallow_lock);
453 sha1_array_clear(&extra);
454 return -1;
455 }
456
457 commit_lock_file(&shallow_lock);
458
459 /*
460 * Make sure setup_alternate_shallow() for the next ref does
461 * not lose these new roots..
462 */
463 for (i = 0; i < extra.nr; i++)
464 register_shallow(extra.sha1[i]);
465
466 si->shallow_ref[cmd->index] = 0;
467 sha1_array_clear(&extra);
468 return 0;
469}
470
471static const char *update(struct command *cmd, struct shallow_info *si)
2eca23da 472{
cfee10a7 473 const char *name = cmd->ref_name;
6b01ecfe
JT
474 struct strbuf namespaced_name_buf = STRBUF_INIT;
475 const char *namespaced_name;
cfee10a7
JH
476 unsigned char *old_sha1 = cmd->old_sha1;
477 unsigned char *new_sha1 = cmd->new_sha1;
3159c8dc 478 struct ref_lock *lock;
2eca23da 479
061d6b9a 480 /* only refs/... are allowed */
59556548 481 if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) {
466dbc42 482 rp_error("refusing to create funny ref '%s' remotely", name);
8aaf7d64 483 return "funny refname";
cfee10a7 484 }
d8a1deec 485
6b01ecfe
JT
486 strbuf_addf(&namespaced_name_buf, "%s%s", get_git_namespace(), name);
487 namespaced_name = strbuf_detach(&namespaced_name_buf, NULL);
488
489 if (is_ref_checked_out(namespaced_name)) {
3d95d92b
JH
490 switch (deny_current_branch) {
491 case DENY_IGNORE:
986e8239 492 break;
3d95d92b 493 case DENY_WARN:
466dbc42 494 rp_warning("updating the current branch");
986e8239 495 break;
3d95d92b 496 case DENY_REFUSE:
acd2a45b 497 case DENY_UNCONFIGURED:
466dbc42 498 rp_error("refusing to update checked out branch: %s", name);
acd2a45b
JH
499 if (deny_current_branch == DENY_UNCONFIGURED)
500 refuse_unconfigured_deny();
3d95d92b
JH
501 return "branch is currently checked out";
502 }
986e8239
JK
503 }
504
d4f694ba 505 if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) {
8aaf7d64
SP
506 error("unpack should have generated %s, "
507 "but I can't find it!", sha1_to_hex(new_sha1));
508 return "bad pack";
cfee10a7 509 }
747ca245
JH
510
511 if (!is_null_sha1(old_sha1) && is_null_sha1(new_sha1)) {
59556548 512 if (deny_deletes && starts_with(name, "refs/heads/")) {
466dbc42 513 rp_error("denying ref deletion for %s", name);
747ca245
JH
514 return "deletion prohibited";
515 }
516
6b01ecfe 517 if (!strcmp(namespaced_name, head_name)) {
747ca245
JH
518 switch (deny_delete_current) {
519 case DENY_IGNORE:
520 break;
521 case DENY_WARN:
466dbc42 522 rp_warning("deleting the current branch");
747ca245
JH
523 break;
524 case DENY_REFUSE:
375881fa
JH
525 case DENY_UNCONFIGURED:
526 if (deny_delete_current == DENY_UNCONFIGURED)
527 refuse_unconfigured_deny_delete_current();
466dbc42 528 rp_error("refusing to delete the current branch: %s", name);
747ca245
JH
529 return "deletion of the current branch prohibited";
530 }
531 }
a240de11 532 }
747ca245 533
d4f694ba 534 if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
ba988a83 535 !is_null_sha1(old_sha1) &&
59556548 536 starts_with(name, "refs/heads/")) {
eab82707 537 struct object *old_object, *new_object;
11031d7e 538 struct commit *old_commit, *new_commit;
11031d7e 539
eab82707
MK
540 old_object = parse_object(old_sha1);
541 new_object = parse_object(new_sha1);
542
543 if (!old_object || !new_object ||
544 old_object->type != OBJ_COMMIT ||
545 new_object->type != OBJ_COMMIT) {
546 error("bad sha1 objects for %s", name);
547 return "bad ref";
548 }
549 old_commit = (struct commit *)old_object;
550 new_commit = (struct commit *)new_object;
5d55915c 551 if (!in_merge_bases(old_commit, new_commit)) {
466dbc42
SP
552 rp_error("denying non-fast-forward %s"
553 " (you should pull first)", name);
a75d7b54 554 return "non-fast-forward";
8aaf7d64 555 }
11031d7e 556 }
1d9e8b56 557 if (run_update_hook(cmd)) {
466dbc42 558 rp_error("hook declined to update %s", name);
8aaf7d64 559 return "hook declined";
b1bf95bb 560 }
3159c8dc 561
d4f694ba 562 if (is_null_sha1(new_sha1)) {
28391a80 563 if (!parse_object(old_sha1)) {
28391a80 564 old_sha1 = NULL;
160b81ed
PYH
565 if (ref_exists(name)) {
566 rp_warning("Allowing deletion of corrupt ref.");
567 } else {
568 rp_warning("Deleting a non-existent ref.");
569 cmd->did_not_exist = 1;
570 }
28391a80 571 }
6b01ecfe 572 if (delete_ref(namespaced_name, old_sha1, 0)) {
466dbc42 573 rp_error("failed to delete %s", name);
8aaf7d64 574 return "failed to delete";
d4f694ba 575 }
8aaf7d64 576 return NULL; /* good */
d4f694ba
JH
577 }
578 else {
0a1bc12b
NTND
579 if (shallow_update && si->shallow_ref[cmd->index] &&
580 update_shallow_ref(cmd, si))
581 return "shallow error";
582
9bbb0fa1
BK
583 lock = lock_any_ref_for_update(namespaced_name, old_sha1,
584 0, NULL);
d4f694ba 585 if (!lock) {
466dbc42 586 rp_error("failed to lock %s", name);
8aaf7d64 587 return "failed to lock";
d4f694ba 588 }
ef203f08 589 if (write_ref_sha1(lock, new_sha1, "push")) {
8aaf7d64 590 return "failed to write"; /* error() already called */
ef203f08 591 }
8aaf7d64 592 return NULL; /* good */
19614330 593 }
2eca23da
LT
594}
595
5e1c71fd 596static void run_update_post_hook(struct command *commands)
19614330 597{
5e1c71fd 598 struct command *cmd;
6d525d38 599 int argc;
9201c707 600 const char **argv;
6d525d38 601 struct child_process proc;
5a7da2dc 602 char *hook;
19614330 603
5a7da2dc 604 hook = find_hook("post-update");
5e1c71fd 605 for (argc = 0, cmd = commands; cmd; cmd = cmd->next) {
160b81ed 606 if (cmd->error_string || cmd->did_not_exist)
19614330
JH
607 continue;
608 argc++;
609 }
5a7da2dc 610 if (!argc || !hook)
3e6e152c 611 return;
5a7da2dc 612
3e6e152c 613 argv = xmalloc(sizeof(*argv) * (2 + argc));
5a7da2dc 614 argv[0] = hook;
19614330 615
5e1c71fd 616 for (argc = 1, cmd = commands; cmd; cmd = cmd->next) {
160b81ed 617 if (cmd->error_string || cmd->did_not_exist)
19614330 618 continue;
95244ae3 619 argv[argc] = xstrdup(cmd->ref_name);
19614330
JH
620 argc++;
621 }
622 argv[argc] = NULL;
6d525d38
SP
623
624 memset(&proc, 0, sizeof(proc));
625 proc.no_stdin = 1;
626 proc.stdout_to_stderr = 1;
627 proc.err = use_sideband ? -1 : 0;
628 proc.argv = argv;
629
630 if (!start_command(&proc)) {
631 if (use_sideband)
632 copy_to_sideband(proc.err, -1, NULL);
633 finish_command(&proc);
634 }
19614330 635}
2eca23da 636
da3efdb1
JS
637static void check_aliased_update(struct command *cmd, struct string_list *list)
638{
6b01ecfe
JT
639 struct strbuf buf = STRBUF_INIT;
640 const char *dst_name;
da3efdb1
JS
641 struct string_list_item *item;
642 struct command *dst_cmd;
643 unsigned char sha1[20];
644 char cmd_oldh[41], cmd_newh[41], dst_oldh[41], dst_newh[41];
645 int flag;
646
6b01ecfe 647 strbuf_addf(&buf, "%s%s", get_git_namespace(), cmd->ref_name);
8cad4744 648 dst_name = resolve_ref_unsafe(buf.buf, sha1, 0, &flag);
6b01ecfe 649 strbuf_release(&buf);
da3efdb1
JS
650
651 if (!(flag & REF_ISSYMREF))
652 return;
653
6b01ecfe
JT
654 dst_name = strip_namespace(dst_name);
655 if (!dst_name) {
656 rp_error("refusing update to broken symref '%s'", cmd->ref_name);
657 cmd->skip_update = 1;
658 cmd->error_string = "broken symref";
659 return;
660 }
661
e8c8b713 662 if ((item = string_list_lookup(list, dst_name)) == NULL)
da3efdb1
JS
663 return;
664
665 cmd->skip_update = 1;
666
667 dst_cmd = (struct command *) item->util;
668
669 if (!hashcmp(cmd->old_sha1, dst_cmd->old_sha1) &&
670 !hashcmp(cmd->new_sha1, dst_cmd->new_sha1))
671 return;
672
673 dst_cmd->skip_update = 1;
674
675 strcpy(cmd_oldh, find_unique_abbrev(cmd->old_sha1, DEFAULT_ABBREV));
0e71bc30 676 strcpy(cmd_newh, find_unique_abbrev(cmd->new_sha1, DEFAULT_ABBREV));
da3efdb1 677 strcpy(dst_oldh, find_unique_abbrev(dst_cmd->old_sha1, DEFAULT_ABBREV));
0e71bc30 678 strcpy(dst_newh, find_unique_abbrev(dst_cmd->new_sha1, DEFAULT_ABBREV));
da3efdb1
JS
679 rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
680 " its target '%s' (%s..%s)",
681 cmd->ref_name, cmd_oldh, cmd_newh,
682 dst_cmd->ref_name, dst_oldh, dst_newh);
683
684 cmd->error_string = dst_cmd->error_string =
685 "inconsistent aliased update";
686}
687
688static void check_aliased_updates(struct command *commands)
689{
690 struct command *cmd;
183113a5 691 struct string_list ref_list = STRING_LIST_INIT_NODUP;
da3efdb1
JS
692
693 for (cmd = commands; cmd; cmd = cmd->next) {
694 struct string_list_item *item =
1d2f80fa 695 string_list_append(&ref_list, cmd->ref_name);
da3efdb1
JS
696 item->util = (void *)cmd;
697 }
698 sort_string_list(&ref_list);
699
ef7e93d9
CB
700 for (cmd = commands; cmd; cmd = cmd->next) {
701 if (!cmd->error_string)
702 check_aliased_update(cmd, &ref_list);
703 }
da3efdb1
JS
704
705 string_list_clear(&ref_list, 0);
706}
707
52fed6e1
JH
708static int command_singleton_iterator(void *cb_data, unsigned char sha1[20])
709{
710 struct command **cmd_list = cb_data;
711 struct command *cmd = *cmd_list;
712
ee6dfb2d 713 if (!cmd || is_null_sha1(cmd->new_sha1))
52fed6e1
JH
714 return -1; /* end of list */
715 *cmd_list = NULL; /* this returns only one */
716 hashcpy(sha1, cmd->new_sha1);
717 return 0;
718}
719
0a1bc12b
NTND
720static void set_connectivity_errors(struct command *commands,
721 struct shallow_info *si)
52fed6e1
JH
722{
723 struct command *cmd;
724
725 for (cmd = commands; cmd; cmd = cmd->next) {
726 struct command *singleton = cmd;
0a1bc12b
NTND
727 if (shallow_update && si->shallow_ref[cmd->index])
728 /* to be checked in update_shallow_ref() */
729 continue;
52fed6e1
JH
730 if (!check_everything_connected(command_singleton_iterator,
731 0, &singleton))
732 continue;
733 cmd->error_string = "missing necessary objects";
734 }
735}
736
0a1bc12b
NTND
737struct iterate_data {
738 struct command *cmds;
739 struct shallow_info *si;
740};
741
52fed6e1
JH
742static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20])
743{
0a1bc12b
NTND
744 struct iterate_data *data = cb_data;
745 struct command **cmd_list = &data->cmds;
52fed6e1
JH
746 struct command *cmd = *cmd_list;
747
0a1bc12b
NTND
748 for (; cmd; cmd = cmd->next) {
749 if (shallow_update && data->si->shallow_ref[cmd->index])
750 /* to be checked in update_shallow_ref() */
751 continue;
5dbd7676 752 if (!is_null_sha1(cmd->new_sha1) && !cmd->skip_update) {
ee6dfb2d
JH
753 hashcpy(sha1, cmd->new_sha1);
754 *cmd_list = cmd->next;
755 return 0;
756 }
ee6dfb2d
JH
757 }
758 *cmd_list = NULL;
759 return -1; /* end of list */
52fed6e1
JH
760}
761
daebaa78
JH
762static void reject_updates_to_hidden(struct command *commands)
763{
764 struct command *cmd;
765
766 for (cmd = commands; cmd; cmd = cmd->next) {
767 if (cmd->error_string || !ref_is_hidden(cmd->ref_name))
768 continue;
769 if (is_null_sha1(cmd->new_sha1))
770 cmd->error_string = "deny deleting a hidden ref";
771 else
772 cmd->error_string = "deny updating a hidden ref";
773 }
774}
775
0a1bc12b
NTND
776static void execute_commands(struct command *commands,
777 const char *unpacker_error,
778 struct shallow_info *si)
575f4974 779{
0a1bc12b 780 int checked_connectivity;
5e1c71fd 781 struct command *cmd;
747ca245 782 unsigned char sha1[20];
0a1bc12b 783 struct iterate_data data;
8aaf7d64
SP
784
785 if (unpacker_error) {
5e1c71fd 786 for (cmd = commands; cmd; cmd = cmd->next)
74eb32d3 787 cmd->error_string = "unpacker error";
8aaf7d64
SP
788 return;
789 }
790
0a1bc12b
NTND
791 data.cmds = commands;
792 data.si = si;
793 if (check_everything_connected(iterate_receive_command_list, 0, &data))
794 set_connectivity_errors(commands, si);
52fed6e1 795
daebaa78
JH
796 reject_updates_to_hidden(commands);
797
5a7da2dc 798 if (run_receive_hook(commands, "pre-receive", 0)) {
ef7e93d9
CB
799 for (cmd = commands; cmd; cmd = cmd->next) {
800 if (!cmd->error_string)
801 cmd->error_string = "pre-receive hook declined";
802 }
05ef58ec
SP
803 return;
804 }
805
da3efdb1
JS
806 check_aliased_updates(commands);
807
96ec7b1e
NTND
808 free(head_name_to_free);
809 head_name = head_name_to_free = resolve_refdup("HEAD", sha1, 0, NULL);
747ca245 810
0a1bc12b 811 checked_connectivity = 1;
ef7e93d9
CB
812 for (cmd = commands; cmd; cmd = cmd->next) {
813 if (cmd->error_string)
814 continue;
815
816 if (cmd->skip_update)
817 continue;
818
0a1bc12b
NTND
819 cmd->error_string = update(cmd, si);
820 if (shallow_update && !cmd->error_string &&
821 si->shallow_ref[cmd->index]) {
822 error("BUG: connectivity check has not been run on ref %s",
823 cmd->ref_name);
824 checked_connectivity = 0;
825 }
826 }
827
0179c945
JK
828 if (shallow_update && !checked_connectivity)
829 error("BUG: run 'git fsck' for safety.\n"
830 "If there are errors, try to remove "
831 "the reported refs above");
575f4974
LT
832}
833
39895c74
JH
834static struct command **queue_command(struct command **tail,
835 const char *line,
836 int linelen)
837{
838 unsigned char old_sha1[20], new_sha1[20];
839 struct command *cmd;
840 const char *refname;
841 int reflen;
842
843 if (linelen < 83 ||
844 line[40] != ' ' ||
845 line[81] != ' ' ||
846 get_sha1_hex(line, old_sha1) ||
847 get_sha1_hex(line + 41, new_sha1))
848 die("protocol error: expected old/new/ref, got '%s'", line);
849
850 refname = line + 82;
851 reflen = linelen - 82;
852 cmd = xcalloc(1, sizeof(struct command) + reflen + 1);
853 hashcpy(cmd->old_sha1, old_sha1);
854 hashcpy(cmd->new_sha1, new_sha1);
855 memcpy(cmd->ref_name, refname, reflen);
856 cmd->ref_name[reflen] = '\0';
857 *tail = cmd;
858 return &cmd->next;
859}
860
5dbd7676 861static struct command *read_head_info(struct sha1_array *shallow)
575f4974 862{
5e1c71fd 863 struct command *commands = NULL;
eb1af2df 864 struct command **p = &commands;
575f4974 865 for (;;) {
74543a04 866 char *line;
39895c74 867 int len, linelen;
eb1af2df 868
74543a04
JK
869 line = packet_read_line(0, &len);
870 if (!line)
575f4974 871 break;
5dbd7676 872
92251b1b 873 if (len == 48 && starts_with(line, "shallow ")) {
c09b71cc
JH
874 unsigned char sha1[20];
875 if (get_sha1_hex(line + 8, sha1))
876 die("protocol error: expected shallow sha, got '%s'",
877 line + 8);
878 sha1_array_append(shallow, sha1);
5dbd7676
NTND
879 continue;
880 }
881
0e3c339b
JH
882 linelen = strlen(line);
883 if (linelen < len) {
884 const char *feature_list = line + linelen + 1;
885 if (parse_feature_request(feature_list, "report-status"))
886 report_status = 1;
887 if (parse_feature_request(feature_list, "side-band-64k"))
888 use_sideband = LARGE_PACKET_MAX;
889 if (parse_feature_request(feature_list, "quiet"))
890 quiet = 1;
891 }
892
39895c74 893 p = queue_command(p, line, linelen);
575f4974 894 }
5e1c71fd 895 return commands;
575f4974
LT
896}
897
fc04c412
SP
898static const char *parse_pack_header(struct pack_header *hdr)
899{
a69e5429
JH
900 switch (read_pack_header(0, hdr)) {
901 case PH_ERROR_EOF:
902 return "eof before pack header was fully read";
903
904 case PH_ERROR_PACK_SIGNATURE:
fc04c412 905 return "protocol error (pack signature mismatch detected)";
a69e5429
JH
906
907 case PH_ERROR_PROTOCOL:
fc04c412 908 return "protocol error (pack version unsupported)";
a69e5429
JH
909
910 default:
911 return "unknown error in parse_pack_header";
912
913 case 0:
914 return NULL;
915 }
fc04c412
SP
916}
917
576162a4
NP
918static const char *pack_lockfile;
919
5dbd7676 920static const char *unpack(int err_fd, struct shallow_info *si)
575f4974 921{
fc04c412 922 struct pack_header hdr;
31c42bff 923 struct argv_array av = ARGV_ARRAY_INIT;
fc04c412 924 const char *hdr_err;
31c42bff 925 int status;
fc04c412 926 char hdr_arg[38];
31c42bff 927 struct child_process child;
dab76d3a
JH
928 int fsck_objects = (receive_fsck_objects >= 0
929 ? receive_fsck_objects
930 : transfer_fsck_objects >= 0
931 ? transfer_fsck_objects
932 : 0);
fc04c412
SP
933
934 hdr_err = parse_pack_header(&hdr);
49ecfa13
JK
935 if (hdr_err) {
936 if (err_fd > 0)
937 close(err_fd);
fc04c412 938 return hdr_err;
49ecfa13 939 }
6e1c2344
RJ
940 snprintf(hdr_arg, sizeof(hdr_arg),
941 "--pack_header=%"PRIu32",%"PRIu32,
fc04c412
SP
942 ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
943
5dbd7676
NTND
944 if (si->nr_ours || si->nr_theirs) {
945 alt_shallow_file = setup_temporary_shallow(si->shallow);
946 argv_array_pushl(&av, "--shallow-file", alt_shallow_file, NULL);
947 }
948
31c42bff 949 memset(&child, 0, sizeof(child));
fc04c412 950 if (ntohl(hdr.hdr_entries) < unpack_limit) {
31c42bff 951 argv_array_pushl(&av, "unpack-objects", hdr_arg, NULL);
c207e34f 952 if (quiet)
31c42bff 953 argv_array_push(&av, "-q");
dab76d3a 954 if (fsck_objects)
31c42bff
NTND
955 argv_array_push(&av, "--strict");
956 child.argv = av.argv;
59bfdfb8 957 child.no_stdout = 1;
a22e6f85 958 child.err = err_fd;
59bfdfb8 959 child.git_cmd = 1;
31c42bff
NTND
960 status = run_command(&child);
961 if (status)
962 return "unpack-objects abnormal exit";
576162a4 963 } else {
31c42bff 964 int s;
576162a4 965 char keep_arg[256];
576162a4 966
85e72830 967 s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid());
576162a4
NP
968 if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
969 strcpy(keep_arg + s, "localhost");
970
31c42bff
NTND
971 argv_array_pushl(&av, "index-pack",
972 "--stdin", hdr_arg, keep_arg, NULL);
dab76d3a 973 if (fsck_objects)
31c42bff 974 argv_array_push(&av, "--strict");
f7c815c3 975 if (fix_thin)
31c42bff
NTND
976 argv_array_push(&av, "--fix-thin");
977 child.argv = av.argv;
978 child.out = -1;
979 child.err = err_fd;
980 child.git_cmd = 1;
981 status = start_command(&child);
982 if (status)
576162a4 983 return "index-pack fork failed";
31c42bff
NTND
984 pack_lockfile = index_pack_lockfile(child.out);
985 close(child.out);
986 status = finish_command(&child);
987 if (status)
988 return "index-pack abnormal exit";
989 reprepare_packed_git();
cfee10a7 990 }
31c42bff 991 return NULL;
cfee10a7
JH
992}
993
5dbd7676 994static const char *unpack_with_sideband(struct shallow_info *si)
a22e6f85
JK
995{
996 struct async muxer;
997 const char *ret;
998
999 if (!use_sideband)
5dbd7676 1000 return unpack(0, si);
a22e6f85
JK
1001
1002 memset(&muxer, 0, sizeof(muxer));
1003 muxer.proc = copy_to_sideband;
1004 muxer.in = -1;
1005 if (start_async(&muxer))
1006 return NULL;
1007
5dbd7676 1008 ret = unpack(muxer.in, si);
a22e6f85
JK
1009
1010 finish_async(&muxer);
1011 return ret;
1012}
1013
0a1bc12b
NTND
1014static void prepare_shallow_update(struct command *commands,
1015 struct shallow_info *si)
1016{
1017 int i, j, k, bitmap_size = (si->ref->nr + 31) / 32;
1018
1019 si->used_shallow = xmalloc(sizeof(*si->used_shallow) *
1020 si->shallow->nr);
1021 assign_shallow_commits_to_refs(si, si->used_shallow, NULL);
1022
1023 si->need_reachability_test =
1024 xcalloc(si->shallow->nr, sizeof(*si->need_reachability_test));
1025 si->reachable =
1026 xcalloc(si->shallow->nr, sizeof(*si->reachable));
1027 si->shallow_ref = xcalloc(si->ref->nr, sizeof(*si->shallow_ref));
1028
1029 for (i = 0; i < si->nr_ours; i++)
1030 si->need_reachability_test[si->ours[i]] = 1;
1031
1032 for (i = 0; i < si->shallow->nr; i++) {
1033 if (!si->used_shallow[i])
1034 continue;
1035 for (j = 0; j < bitmap_size; j++) {
1036 if (!si->used_shallow[i][j])
1037 continue;
1038 si->need_reachability_test[i]++;
1039 for (k = 0; k < 32; k++)
1040 if (si->used_shallow[i][j] & (1 << k))
1041 si->shallow_ref[j * 32 + k]++;
1042 }
1043
1044 /*
1045 * true for those associated with some refs and belong
1046 * in "ours" list aka "step 7 not done yet"
1047 */
1048 si->need_reachability_test[i] =
1049 si->need_reachability_test[i] > 1;
1050 }
1051
1052 /*
1053 * keep hooks happy by forcing a temporary shallow file via
1054 * env variable because we can't add --shallow-file to every
1055 * command. check_everything_connected() will be done with
1056 * true .git/shallow though.
1057 */
1058 setenv(GIT_SHALLOW_FILE_ENVIRONMENT, alt_shallow_file, 1);
1059}
1060
5dbd7676
NTND
1061static void update_shallow_info(struct command *commands,
1062 struct shallow_info *si,
1063 struct sha1_array *ref)
1064{
1065 struct command *cmd;
1066 int *ref_status;
1067 remove_nonexistent_theirs_shallow(si);
0a1bc12b
NTND
1068 if (!si->nr_ours && !si->nr_theirs) {
1069 shallow_update = 0;
5dbd7676 1070 return;
0a1bc12b 1071 }
5dbd7676
NTND
1072
1073 for (cmd = commands; cmd; cmd = cmd->next) {
1074 if (is_null_sha1(cmd->new_sha1))
1075 continue;
1076 sha1_array_append(ref, cmd->new_sha1);
1077 cmd->index = ref->nr - 1;
1078 }
1079 si->ref = ref;
1080
0a1bc12b
NTND
1081 if (shallow_update) {
1082 prepare_shallow_update(commands, si);
1083 return;
1084 }
1085
5dbd7676
NTND
1086 ref_status = xmalloc(sizeof(*ref_status) * ref->nr);
1087 assign_shallow_commits_to_refs(si, NULL, ref_status);
1088 for (cmd = commands; cmd; cmd = cmd->next) {
1089 if (is_null_sha1(cmd->new_sha1))
1090 continue;
1091 if (ref_status[cmd->index]) {
1092 cmd->error_string = "shallow update not allowed";
1093 cmd->skip_update = 1;
1094 }
1095 }
5dbd7676
NTND
1096 free(ref_status);
1097}
1098
5e1c71fd 1099static void report(struct command *commands, const char *unpack_status)
cfee10a7
JH
1100{
1101 struct command *cmd;
38a81b4e
SP
1102 struct strbuf buf = STRBUF_INIT;
1103
1104 packet_buf_write(&buf, "unpack %s\n",
1105 unpack_status ? unpack_status : "ok");
cfee10a7
JH
1106 for (cmd = commands; cmd; cmd = cmd->next) {
1107 if (!cmd->error_string)
38a81b4e
SP
1108 packet_buf_write(&buf, "ok %s\n",
1109 cmd->ref_name);
cfee10a7 1110 else
38a81b4e
SP
1111 packet_buf_write(&buf, "ng %s %s\n",
1112 cmd->ref_name, cmd->error_string);
575f4974 1113 }
38a81b4e
SP
1114 packet_buf_flush(&buf);
1115
1116 if (use_sideband)
1117 send_sideband(1, 1, buf.buf, buf.len, use_sideband);
1118 else
cdf4fb8e 1119 write_or_die(1, buf.buf, buf.len);
38a81b4e 1120 strbuf_release(&buf);
575f4974
LT
1121}
1122
5e1c71fd 1123static int delete_only(struct command *commands)
d4f694ba 1124{
5e1c71fd
JS
1125 struct command *cmd;
1126 for (cmd = commands; cmd; cmd = cmd->next) {
d4f694ba
JH
1127 if (!is_null_sha1(cmd->new_sha1))
1128 return 0;
d4f694ba
JH
1129 }
1130 return 1;
1131}
1132
be5908ae 1133int cmd_receive_pack(int argc, const char **argv, const char *prefix)
575f4974 1134{
42526b47
SP
1135 int advertise_refs = 0;
1136 int stateless_rpc = 0;
d0efc8a7 1137 int i;
d51428bf 1138 const char *dir = NULL;
5e1c71fd 1139 struct command *commands;
5dbd7676
NTND
1140 struct sha1_array shallow = SHA1_ARRAY_INIT;
1141 struct sha1_array ref = SHA1_ARRAY_INIT;
1142 struct shallow_info si;
575f4974 1143
bbc30f99
JK
1144 packet_trace_identity("receive-pack");
1145
575f4974
LT
1146 argv++;
1147 for (i = 1; i < argc; i++) {
be5908ae 1148 const char *arg = *argv++;
575f4974
LT
1149
1150 if (*arg == '-') {
c207e34f
CB
1151 if (!strcmp(arg, "--quiet")) {
1152 quiet = 1;
1153 continue;
1154 }
1155
42526b47
SP
1156 if (!strcmp(arg, "--advertise-refs")) {
1157 advertise_refs = 1;
1158 continue;
1159 }
1160 if (!strcmp(arg, "--stateless-rpc")) {
1161 stateless_rpc = 1;
1162 continue;
1163 }
f7c815c3
NTND
1164 if (!strcmp(arg, "--reject-thin-pack-for-testing")) {
1165 fix_thin = 0;
1166 continue;
1167 }
42526b47 1168
575f4974
LT
1169 usage(receive_pack_usage);
1170 }
d0efc8a7
LT
1171 if (dir)
1172 usage(receive_pack_usage);
d51428bf 1173 dir = arg;
575f4974
LT
1174 }
1175 if (!dir)
1176 usage(receive_pack_usage);
1177
e1464ca7 1178 setup_path();
5c09f321 1179
3159c8dc 1180 if (!enter_repo(dir, 0))
05ac6b34 1181 die("'%s' does not appear to be a git repository", dir);
575f4974 1182
ef90d6d4 1183 git_config(receive_pack_config, NULL);
6fb75bed 1184
e28714c5
JH
1185 if (0 <= transfer_unpack_limit)
1186 unpack_limit = transfer_unpack_limit;
1187 else if (0 <= receive_unpack_limit)
1188 unpack_limit = receive_unpack_limit;
1189
42526b47 1190 if (advertise_refs || !stateless_rpc) {
42526b47 1191 write_head_info();
42526b47
SP
1192 }
1193 if (advertise_refs)
1194 return 0;
575f4974 1195
5dbd7676 1196 if ((commands = read_head_info(&shallow)) != NULL) {
d4f694ba
JH
1197 const char *unpack_status = NULL;
1198
5dbd7676 1199 prepare_shallow_info(&si, &shallow);
0a1bc12b
NTND
1200 if (!si.nr_ours && !si.nr_theirs)
1201 shallow_update = 0;
5dbd7676
NTND
1202 if (!delete_only(commands)) {
1203 unpack_status = unpack_with_sideband(&si);
1204 update_shallow_info(commands, &si, &ref);
1205 }
0a1bc12b 1206 execute_commands(commands, unpack_status, &si);
576162a4 1207 if (pack_lockfile)
691f1a28 1208 unlink_or_warn(pack_lockfile);
cfee10a7 1209 if (report_status)
5e1c71fd 1210 report(commands, unpack_status);
5a7da2dc 1211 run_receive_hook(commands, "post-receive", 1);
8e663d9e 1212 run_update_post_hook(commands);
77e3efbf
JH
1213 if (auto_gc) {
1214 const char *argv_gc_auto[] = {
1215 "gc", "--auto", "--quiet", NULL,
1216 };
4b7f2fa4
JH
1217 int opt = RUN_GIT_CMD | RUN_COMMAND_STDOUT_TO_STDERR;
1218 run_command_v_opt(argv_gc_auto, opt);
77e3efbf
JH
1219 }
1220 if (auto_update_server_info)
1221 update_server_info(0);
5dbd7676 1222 clear_shallow_info(&si);
7f8e9828 1223 }
38a81b4e
SP
1224 if (use_sideband)
1225 packet_flush(1);
5dbd7676
NTND
1226 sha1_array_clear(&shallow);
1227 sha1_array_clear(&ref);
575f4974
LT
1228 return 0;
1229}