]> git.ipfire.org Git - thirdparty/git.git/blame - upload-pack.c
builtin/clone.c: don't ignore transport_fetch_refs() errors
[thirdparty/git.git] / upload-pack.c
CommitLineData
def88e9a 1#include "cache.h"
b2141fc1 2#include "config.h"
def88e9a
LT
3#include "refs.h"
4#include "pkt-line.h"
958c24b1 5#include "sideband.h"
109cd76d 6#include "repository.h"
cbd53a21 7#include "object-store.h"
f6b42a81
JH
8#include "tag.h"
9#include "object.h"
f0243f26 10#include "commit.h"
9b8dc263
JS
11#include "diff.h"
12#include "revision.h"
13#include "list-objects.h"
10ac85c7
JH
14#include "list-objects-filter.h"
15#include "list-objects-filter-options.h"
cc41fa8d 16#include "run-command.h"
47a59185 17#include "connect.h"
051e4005 18#include "sigchain.h"
ff5effdf 19#include "version.h"
daebaa78 20#include "string-list.h"
dbbcd44f 21#include "strvec.h"
5411b10c 22#include "prio-queue.h"
aa9bab29 23#include "protocol.h"
10ac85c7 24#include "quote.h"
a3d6b53e 25#include "upload-pack.h"
3145ea95 26#include "serve.h"
829a3215 27#include "commit-graph.h"
ba3ca1ed 28#include "commit-reach.h"
120ad2b0 29#include "shallow.h"
def88e9a 30
208acbfb 31/* Remember to update object flag allocation in object.h */
937a515a
JH
32#define THEY_HAVE (1u << 11)
33#define OUR_REF (1u << 12)
34#define WANTED (1u << 13)
35#define COMMON_KNOWN (1u << 14)
937a515a 36
f53514bc
JS
37#define SHALLOW (1u << 16)
38#define NOT_SHALLOW (1u << 17)
39#define CLIENT_SHALLOW (1u << 18)
390eb36b 40#define HIDDEN_REF (1u << 19)
f53514bc 41
d1035cac
JT
42#define ALL_FLAGS (THEY_HAVE | OUR_REF | WANTED | COMMON_KNOWN | SHALLOW | \
43 NOT_SHALLOW | CLIENT_SHALLOW | HIDDEN_REF)
44
629060d9
CC
45/* Enum for allowed unadvertised object request (UOR) */
46enum allow_uor {
47 /* Allow specifying sha1 if it is a ref tip. */
48 ALLOW_TIP_SHA1 = 0x01,
49 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
50 ALLOW_REACHABLE_SHA1 = 0x02,
51 /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
52 ALLOW_ANY_SHA1 = 0x07
53};
960deccb 54
a8497288
CC
55/*
56 * Please annotate, and if possible group together, fields used only
57 * for protocol v0 or only for protocol v2.
58 */
e8498322 59struct upload_pack_data {
a8497288 60 struct string_list symref; /* v0 only */
e8498322
CC
61 struct object_array want_obj;
62 struct object_array have_obj;
a8497288
CC
63 struct oid_array haves; /* v2 only */
64 struct string_list wanted_refs; /* v2 only */
e8498322
CC
65
66 struct object_array shallows;
67 struct string_list deepen_not;
de0e9f74 68 struct object_array extra_edge_obj;
e8498322
CC
69 int depth;
70 timestamp_t deepen_since;
71 int deepen_rev_list;
72 int deepen_relative;
f203a88c 73 int keepalive;
35b43a10 74 int shallow_nr;
f01c7916 75 timestamp_t oldest_have;
e8498322 76
d40f04e0 77 unsigned int timeout; /* v0 only */
e9d882b8
CC
78 enum {
79 NO_MULTI_ACK = 0,
80 MULTI_ACK = 1,
81 MULTI_ACK_DETAILED = 2
82 } multi_ack; /* v0 only */
d40f04e0 83
f8edd1ca
CC
84 /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
85 int use_sideband;
86
dd4b732d 87 struct string_list uri_protocols;
629060d9 88 enum allow_uor allow_uor;
f1514c6a 89
e8498322 90 struct list_objects_filter_options filter_options;
6dd3456a 91 struct string_list allowed_filters;
e8498322
CC
92
93 struct packet_writer writer;
94
339a9840
CC
95 const char *pack_objects_hook;
96
a8497288 97 unsigned stateless_rpc : 1; /* v0 only */
d40f04e0
CC
98 unsigned no_done : 1; /* v0 only */
99 unsigned daemon_mode : 1; /* v0 only */
59a90261 100 unsigned filter_capability_requested : 1; /* v0 only */
e8498322
CC
101
102 unsigned use_thin_pack : 1;
103 unsigned use_ofs_delta : 1;
104 unsigned no_progress : 1;
105 unsigned use_include_tag : 1;
59abe196 106 unsigned allow_filter : 1;
6dd3456a 107 unsigned allow_filter_fallback : 1;
5b01a4e8 108 unsigned long tree_filter_max_depth;
a8497288
CC
109
110 unsigned done : 1; /* v2 only */
d1d7a945 111 unsigned allow_ref_in_want : 1; /* v2 only */
e3835cd4 112 unsigned allow_sideband_all : 1; /* v2 only */
e8498322
CC
113};
114
115static void upload_pack_data_init(struct upload_pack_data *data)
116{
438528f6 117 struct string_list symref = STRING_LIST_INIT_DUP;
e8498322
CC
118 struct string_list wanted_refs = STRING_LIST_INIT_DUP;
119 struct object_array want_obj = OBJECT_ARRAY_INIT;
120 struct object_array have_obj = OBJECT_ARRAY_INIT;
121 struct oid_array haves = OID_ARRAY_INIT;
122 struct object_array shallows = OBJECT_ARRAY_INIT;
123 struct string_list deepen_not = STRING_LIST_INIT_DUP;
dd4b732d 124 struct string_list uri_protocols = STRING_LIST_INIT_DUP;
de0e9f74 125 struct object_array extra_edge_obj = OBJECT_ARRAY_INIT;
6dd3456a 126 struct string_list allowed_filters = STRING_LIST_INIT_DUP;
e8498322
CC
127
128 memset(data, 0, sizeof(*data));
438528f6 129 data->symref = symref;
e8498322
CC
130 data->wanted_refs = wanted_refs;
131 data->want_obj = want_obj;
132 data->have_obj = have_obj;
133 data->haves = haves;
134 data->shallows = shallows;
135 data->deepen_not = deepen_not;
dd4b732d 136 data->uri_protocols = uri_protocols;
de0e9f74 137 data->extra_edge_obj = extra_edge_obj;
6dd3456a
TB
138 data->allowed_filters = allowed_filters;
139 data->allow_filter_fallback = 1;
5b01a4e8 140 data->tree_filter_max_depth = ULONG_MAX;
e8498322 141 packet_writer_init(&data->writer, 1);
f203a88c
CC
142
143 data->keepalive = 5;
e8498322
CC
144}
145
146static void upload_pack_data_clear(struct upload_pack_data *data)
147{
438528f6 148 string_list_clear(&data->symref, 1);
e8498322
CC
149 string_list_clear(&data->wanted_refs, 1);
150 object_array_clear(&data->want_obj);
151 object_array_clear(&data->have_obj);
152 oid_array_clear(&data->haves);
153 object_array_clear(&data->shallows);
154 string_list_clear(&data->deepen_not, 0);
de0e9f74 155 object_array_clear(&data->extra_edge_obj);
e8498322 156 list_objects_filter_release(&data->filter_options);
6dd3456a 157 string_list_clear(&data->allowed_filters, 1);
339a9840
CC
158
159 free((char *)data->pack_objects_hook);
e8498322
CC
160}
161
d40f04e0 162static void reset_timeout(unsigned int timeout)
960deccb
PA
163{
164 alarm(timeout);
165}
fb9040cc 166
f8edd1ca
CC
167static void send_client_data(int fd, const char *data, ssize_t sz,
168 int use_sideband)
583b7ea3 169{
4c4b7d1d
LF
170 if (use_sideband) {
171 send_sideband(1, fd, data, sz, use_sideband);
fcf0fe9e 172 return;
4c4b7d1d 173 }
958c24b1
JH
174 if (fd == 3)
175 /* emergency quit */
176 fd = 2;
177 if (fd == 2) {
93822c22 178 /* XXX: are we happy to lose stuff here? */
958c24b1 179 xwrite(fd, data, sz);
fcf0fe9e 180 return;
583b7ea3 181 }
cdf4fb8e 182 write_or_die(fd, data, sz);
583b7ea3
JH
183}
184
b790e0f6
NTND
185static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
186{
187 FILE *fp = cb_data;
188 if (graft->nr_parent == -1)
7683e2e6 189 fprintf(fp, "--shallow %s\n", oid_to_hex(&graft->oid));
b790e0f6
NTND
190 return 0;
191}
192
acaaca7d
JT
193struct output_state {
194 char buffer[8193];
195 int used;
dd4b732d
JT
196 unsigned packfile_uris_started : 1;
197 unsigned packfile_started : 1;
acaaca7d
JT
198};
199
200static int relay_pack_data(int pack_objects_out, struct output_state *os,
dd4b732d 201 int use_sideband, int write_packfile_line)
acaaca7d
JT
202{
203 /*
204 * We keep the last byte to ourselves
205 * in case we detect broken rev-list, so that we
206 * can leave the stream corrupted. This is
207 * unfortunate -- unpack-objects would happily
208 * accept a valid packdata with trailing garbage,
209 * so appending garbage after we pass all the
210 * pack data is not good enough to signal
211 * breakage to downstream.
212 */
213 ssize_t readsz;
214
215 readsz = xread(pack_objects_out, os->buffer + os->used,
216 sizeof(os->buffer) - os->used);
217 if (readsz < 0) {
218 return readsz;
219 }
220 os->used += readsz;
221
dd4b732d
JT
222 while (!os->packfile_started) {
223 char *p;
224 if (os->used >= 4 && !memcmp(os->buffer, "PACK", 4)) {
225 os->packfile_started = 1;
226 if (write_packfile_line) {
227 if (os->packfile_uris_started)
228 packet_delim(1);
229 packet_write_fmt(1, "\1packfile\n");
230 }
231 break;
232 }
233 if ((p = memchr(os->buffer, '\n', os->used))) {
234 if (!os->packfile_uris_started) {
235 os->packfile_uris_started = 1;
236 if (!write_packfile_line)
237 BUG("packfile_uris requires sideband-all");
238 packet_write_fmt(1, "\1packfile-uris\n");
239 }
240 *p = '\0';
241 packet_write_fmt(1, "\1%s\n", os->buffer);
242
243 os->used -= p - os->buffer + 1;
244 memmove(os->buffer, p + 1, os->used);
245 } else {
246 /*
247 * Incomplete line.
248 */
249 return readsz;
250 }
251 }
252
acaaca7d
JT
253 if (os->used > 1) {
254 send_client_data(1, os->buffer, os->used - 1, use_sideband);
255 os->buffer[0] = os->buffer[os->used - 1];
256 os->used = 1;
257 } else {
258 send_client_data(1, os->buffer, os->used, use_sideband);
259 os->used = 0;
260 }
261
262 return readsz;
263}
264
dd4b732d
JT
265static void create_pack_file(struct upload_pack_data *pack_data,
266 const struct string_list *uri_protocols)
fb9040cc 267{
d3180279 268 struct child_process pack_objects = CHILD_PROCESS_INIT;
acaaca7d
JT
269 struct output_state output_state = { { 0 } };
270 char progress[128];
583b7ea3
JH
271 char abort_msg[] = "aborting due to possible repository "
272 "corruption on the remote side.";
1456b043 273 ssize_t sz;
65a3629e 274 int i;
cdab4858 275 FILE *pipe_fd;
75bfc6c2 276
339a9840 277 if (!pack_data->pack_objects_hook)
20b20a22
JK
278 pack_objects.git_cmd = 1;
279 else {
c972bf4c
JK
280 strvec_push(&pack_objects.args, pack_data->pack_objects_hook);
281 strvec_push(&pack_objects.args, "git");
20b20a22
JK
282 pack_objects.use_shell = 1;
283 }
284
35b43a10 285 if (pack_data->shallow_nr) {
c972bf4c
JK
286 strvec_push(&pack_objects.args, "--shallow-file");
287 strvec_push(&pack_objects.args, "");
f0cea83f 288 }
c972bf4c
JK
289 strvec_push(&pack_objects.args, "pack-objects");
290 strvec_push(&pack_objects.args, "--revs");
b5a2068c 291 if (pack_data->use_thin_pack)
c972bf4c 292 strvec_push(&pack_objects.args, "--thin");
75bfc6c2 293
c972bf4c 294 strvec_push(&pack_objects.args, "--stdout");
35b43a10 295 if (pack_data->shallow_nr)
c972bf4c 296 strvec_push(&pack_objects.args, "--shallow");
b5a2068c 297 if (!pack_data->no_progress)
c972bf4c 298 strvec_push(&pack_objects.args, "--progress");
b5a2068c 299 if (pack_data->use_ofs_delta)
c972bf4c 300 strvec_push(&pack_objects.args, "--delta-base-offset");
b5a2068c 301 if (pack_data->use_include_tag)
c972bf4c 302 strvec_push(&pack_objects.args, "--include-tag");
c9f03259 303 if (pack_data->filter_options.choice) {
cf9ceb5a 304 const char *spec =
c9f03259 305 expand_list_objects_filter_spec(&pack_data->filter_options);
0b6069fe
JT
306 if (pack_objects.use_shell) {
307 struct strbuf buf = STRBUF_INIT;
cf9ceb5a 308 sq_quote_buf(&buf, spec);
c972bf4c 309 strvec_pushf(&pack_objects.args, "--filter=%s", buf.buf);
0b6069fe
JT
310 strbuf_release(&buf);
311 } else {
f6d8942b 312 strvec_pushf(&pack_objects.args, "--filter=%s", spec);
0b6069fe 313 }
10ac85c7 314 }
dd4b732d
JT
315 if (uri_protocols) {
316 for (i = 0; i < uri_protocols->nr; i++)
c972bf4c 317 strvec_pushf(&pack_objects.args, "--uri-protocol=%s",
dd4b732d
JT
318 uri_protocols->items[i].string);
319 }
cc41fa8d 320
b9612197 321 pack_objects.in = -1;
cc41fa8d
JS
322 pack_objects.out = -1;
323 pack_objects.err = -1;
309a4028 324 pack_objects.clean_on_exit = 1;
21edd3f1 325
4c324c00 326 if (start_command(&pack_objects))
7e44c935 327 die("git upload-pack: unable to fork git-pack-objects");
b1c71b72 328
cdab4858
NTND
329 pipe_fd = xfdopen(pack_objects.in, "w");
330
35b43a10 331 if (pack_data->shallow_nr)
b790e0f6
NTND
332 for_each_commit_graft(write_one_shallow, pipe_fd);
333
c9f03259 334 for (i = 0; i < pack_data->want_obj.nr; i++)
cdab4858 335 fprintf(pipe_fd, "%s\n",
c9f03259 336 oid_to_hex(&pack_data->want_obj.objects[i].item->oid));
cdab4858 337 fprintf(pipe_fd, "--not\n");
c9f03259 338 for (i = 0; i < pack_data->have_obj.nr; i++)
cdab4858 339 fprintf(pipe_fd, "%s\n",
c9f03259 340 oid_to_hex(&pack_data->have_obj.objects[i].item->oid));
de0e9f74 341 for (i = 0; i < pack_data->extra_edge_obj.nr; i++)
cdab4858 342 fprintf(pipe_fd, "%s\n",
de0e9f74 343 oid_to_hex(&pack_data->extra_edge_obj.objects[i].item->oid));
cdab4858
NTND
344 fprintf(pipe_fd, "\n");
345 fflush(pipe_fd);
346 fclose(pipe_fd);
f0cea83f 347
cc41fa8d
JS
348 /* We read from pack_objects.err to capture stderr output for
349 * progress bar, and pack_objects.out to capture the pack data.
b1c71b72 350 */
b1c71b72
JH
351
352 while (1) {
b1c71b72 353 struct pollfd pfd[2];
f203a88c 354 int pe, pu, pollsize, polltimeout;
05e95155 355 int ret;
b1c71b72 356
d40f04e0 357 reset_timeout(pack_data->timeout);
0d516ada 358
b1c71b72 359 pollsize = 0;
363b7817 360 pe = pu = -1;
b1c71b72 361
cc41fa8d
JS
362 if (0 <= pack_objects.out) {
363 pfd[pollsize].fd = pack_objects.out;
b1c71b72
JH
364 pfd[pollsize].events = POLLIN;
365 pu = pollsize;
366 pollsize++;
367 }
cc41fa8d
JS
368 if (0 <= pack_objects.err) {
369 pfd[pollsize].fd = pack_objects.err;
363b7817
JH
370 pfd[pollsize].events = POLLIN;
371 pe = pollsize;
372 pollsize++;
373 }
b1c71b72 374
4c324c00
JS
375 if (!pollsize)
376 break;
377
f203a88c
CC
378 polltimeout = pack_data->keepalive < 0
379 ? -1
380 : 1000 * pack_data->keepalive;
381
382 ret = poll(pfd, pollsize, polltimeout);
6c71f8b0 383
05e95155 384 if (ret < 0) {
4c324c00 385 if (errno != EINTR) {
d2b6afa2 386 error_errno("poll failed, resuming");
4c324c00 387 sleep(1);
b1c71b72 388 }
4c324c00
JS
389 continue;
390 }
6b59f51b
NP
391 if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
392 /* Status ready; we ship that in the side-band
393 * or dump to the standard error.
394 */
395 sz = xread(pack_objects.err, progress,
396 sizeof(progress));
397 if (0 < sz)
f8edd1ca
CC
398 send_client_data(2, progress, sz,
399 pack_data->use_sideband);
6b59f51b
NP
400 else if (sz == 0) {
401 close(pack_objects.err);
402 pack_objects.err = -1;
403 }
404 else
405 goto fail;
406 /* give priority to status messages */
407 continue;
408 }
4c324c00 409 if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
acaaca7d
JT
410 int result = relay_pack_data(pack_objects.out,
411 &output_state,
dd4b732d
JT
412 pack_data->use_sideband,
413 !!uri_protocols);
acaaca7d
JT
414
415 if (result == 0) {
4c324c00
JS
416 close(pack_objects.out);
417 pack_objects.out = -1;
acaaca7d 418 } else if (result < 0) {
4c324c00 419 goto fail;
b1c71b72 420 }
4c324c00 421 }
05e95155
JK
422
423 /*
424 * We hit the keepalive timeout without saying anything; send
425 * an empty message on the data sideband just to let the other
426 * side know we're still working on it, but don't have any data
427 * yet.
428 *
429 * If we don't have a sideband channel, there's no room in the
430 * protocol to say anything, so those clients are just out of
431 * luck.
432 */
f8edd1ca 433 if (!ret && pack_data->use_sideband) {
05e95155
JK
434 static const char buf[] = "0005\1";
435 write_or_die(1, buf, 5);
436 }
4c324c00 437 }
b1c71b72 438
4c324c00 439 if (finish_command(&pack_objects)) {
7e44c935 440 error("git upload-pack: git-pack-objects died with error.");
4c324c00
JS
441 goto fail;
442 }
b1c71b72 443
4c324c00 444 /* flush the data */
acaaca7d
JT
445 if (output_state.used > 0) {
446 send_client_data(1, output_state.buffer, output_state.used,
f8edd1ca 447 pack_data->use_sideband);
4c324c00 448 fprintf(stderr, "flushed.\n");
b1c71b72 449 }
f8edd1ca 450 if (pack_data->use_sideband)
4c324c00
JS
451 packet_flush(1);
452 return;
453
b1c71b72 454 fail:
f8edd1ca
CC
455 send_client_data(3, abort_msg, sizeof(abort_msg),
456 pack_data->use_sideband);
7e44c935 457 die("git upload-pack: %s", abort_msg);
fb9040cc
LT
458}
459
ea2c6e60 460static int do_got_oid(struct upload_pack_data *data, const struct object_id *oid)
def88e9a 461{
937a515a 462 int we_knew_they_have = 0;
ea2c6e60 463 struct object *o = parse_object(the_repository, oid);
b1e9fff7 464
b1e9fff7 465 if (!o)
cf93982f 466 die("oops (%s)", oid_to_hex(oid));
182a8dab 467 if (o->type == OBJ_COMMIT) {
b1e9fff7 468 struct commit_list *parents;
937a515a 469 struct commit *commit = (struct commit *)o;
b1e9fff7 470 if (o->flags & THEY_HAVE)
937a515a
JH
471 we_knew_they_have = 1;
472 else
473 o->flags |= THEY_HAVE;
f01c7916
CC
474 if (!data->oldest_have || (commit->date < data->oldest_have))
475 data->oldest_have = commit->date;
937a515a 476 for (parents = commit->parents;
b1e9fff7
JH
477 parents;
478 parents = parents->next)
479 parents->item->object.flags |= THEY_HAVE;
fb9040cc 480 }
937a515a 481 if (!we_knew_they_have) {
460ed0d4 482 add_object_array(o, NULL, &data->have_obj);
937a515a
JH
483 return 1;
484 }
485 return 0;
486}
487
ea2c6e60
CC
488static int got_oid(struct upload_pack_data *data,
489 const char *hex, struct object_id *oid)
490{
491 if (get_oid_hex(hex, oid))
492 die("git upload-pack: expected SHA1 object, got '%s'", hex);
77aa0941
JT
493 if (!has_object_file_with_flags(oid,
494 OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT))
ea2c6e60
CC
495 return -1;
496 return do_got_oid(data, oid);
497}
498
08667348 499static int ok_to_give_up(struct upload_pack_data *data)
937a515a 500{
4fbcca4e 501 uint32_t min_generation = GENERATION_NUMBER_ZERO;
937a515a 502
08667348 503 if (!data->have_obj.nr)
937a515a
JH
504 return 0;
505
08667348 506 return can_all_from_reach_with_flag(&data->want_obj, THEY_HAVE,
f01c7916 507 COMMON_KNOWN, data->oldest_have,
4fbcca4e 508 min_generation);
def88e9a
LT
509}
510
07977695
CC
511static int get_common_commits(struct upload_pack_data *data,
512 struct packet_reader *reader)
def88e9a 513{
cf93982f 514 struct object_id oid;
515 char last_hex[GIT_MAX_HEXSZ + 1];
49bee717
SP
516 int got_common = 0;
517 int got_other = 0;
4e10cf9a 518 int sent_ready = 0;
def88e9a 519
f0243f26
JS
520 save_commit_buffer = 0;
521
eeefa7c9 522 for (;;) {
8bf3b758
NTND
523 const char *arg;
524
d40f04e0 525 reset_timeout(data->timeout);
def88e9a 526
01f9ec64 527 if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
e9d882b8 528 if (data->multi_ack == MULTI_ACK_DETAILED
07977695
CC
529 && got_common
530 && !got_other
08667348 531 && ok_to_give_up(data)) {
4e10cf9a 532 sent_ready = 1;
81c634e9 533 packet_write_fmt(1, "ACK %s ready\n", last_hex);
4e10cf9a 534 }
53d69506 535 if (data->have_obj.nr == 0 || data->multi_ack)
81c634e9 536 packet_write_fmt(1, "NAK\n");
4e10cf9a 537
d40f04e0 538 if (data->no_done && sent_ready) {
81c634e9 539 packet_write_fmt(1, "ACK %s\n", last_hex);
4e10cf9a
JH
540 return 0;
541 }
df654abc 542 if (data->stateless_rpc)
42526b47 543 exit(0);
49bee717
SP
544 got_common = 0;
545 got_other = 0;
def88e9a
LT
546 continue;
547 }
01f9ec64 548 if (skip_prefix(reader->line, "have ", &arg)) {
460ed0d4 549 switch (got_oid(data, arg, &oid)) {
937a515a 550 case -1: /* they have what we do not */
49bee717 551 got_other = 1;
53d69506 552 if (data->multi_ack
08667348 553 && ok_to_give_up(data)) {
cf93982f 554 const char *hex = oid_to_hex(&oid);
e9d882b8 555 if (data->multi_ack == MULTI_ACK_DETAILED) {
4e10cf9a 556 sent_ready = 1;
81c634e9 557 packet_write_fmt(1, "ACK %s ready\n", hex);
4e10cf9a 558 } else
81c634e9 559 packet_write_fmt(1, "ACK %s continue\n", hex);
78affc49 560 }
937a515a
JH
561 break;
562 default:
49bee717 563 got_common = 1;
55dc227d 564 oid_to_hex_r(last_hex, &oid);
e9d882b8 565 if (data->multi_ack == MULTI_ACK_DETAILED)
81c634e9 566 packet_write_fmt(1, "ACK %s common\n", last_hex);
53d69506 567 else if (data->multi_ack)
81c634e9 568 packet_write_fmt(1, "ACK %s continue\n", last_hex);
07977695 569 else if (data->have_obj.nr == 1)
81c634e9 570 packet_write_fmt(1, "ACK %s\n", last_hex);
937a515a 571 break;
af2d3aa4 572 }
def88e9a
LT
573 continue;
574 }
01f9ec64 575 if (!strcmp(reader->line, "done")) {
07977695 576 if (data->have_obj.nr > 0) {
53d69506 577 if (data->multi_ack)
81c634e9 578 packet_write_fmt(1, "ACK %s\n", last_hex);
1bd8c8f0
JS
579 return 0;
580 }
81c634e9 581 packet_write_fmt(1, "NAK\n");
def88e9a
LT
582 return -1;
583 }
01f9ec64 584 die("git upload-pack: expected SHA1 list, got '%s'", reader->line);
def88e9a 585 }
def88e9a
LT
586}
587
629060d9 588static int is_our_ref(struct object *o, enum allow_uor allow_uor)
390eb36b 589{
629060d9
CC
590 int allow_hidden_ref = (allow_uor &
591 (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
7199c093 592 return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
390eb36b
JH
593}
594
2997178e
NTND
595/*
596 * on successful case, it's up to the caller to close cmd->out
597 */
598static int do_reachable_revlist(struct child_process *cmd,
079aa97e 599 struct object_array *src,
f1514c6a 600 struct object_array *reachable,
629060d9 601 enum allow_uor allow_uor)
051e4005
JH
602{
603 static const char *argv[] = {
604 "rev-list", "--stdin", NULL,
605 };
051e4005 606 struct object *o;
a698d67b 607 FILE *cmd_in = NULL;
051e4005
JH
608 int i;
609
2997178e
NTND
610 cmd->argv = argv;
611 cmd->git_cmd = 1;
612 cmd->no_stderr = 1;
613 cmd->in = -1;
614 cmd->out = -1;
051e4005
JH
615
616 /*
7fcbd37f
NTND
617 * If the next rev-list --stdin encounters an unknown commit,
618 * it terminates, which will cause SIGPIPE in the write loop
051e4005
JH
619 * below.
620 */
621 sigchain_push(SIGPIPE, SIG_IGN);
622
2997178e 623 if (start_command(cmd))
7fcbd37f
NTND
624 goto error;
625
a698d67b
RS
626 cmd_in = xfdopen(cmd->in, "w");
627
051e4005
JH
628 for (i = get_max_object_index(); 0 < i; ) {
629 o = get_indexed_object(--i);
2a745324
BH
630 if (!o)
631 continue;
079aa97e
NTND
632 if (reachable && o->type == OBJ_COMMIT)
633 o->flags &= ~TMP_MARK;
629060d9 634 if (!is_our_ref(o, allow_uor))
051e4005 635 continue;
a698d67b 636 if (fprintf(cmd_in, "^%s\n", oid_to_hex(&o->oid)) < 0)
051e4005
JH
637 goto error;
638 }
3f0f6624
NTND
639 for (i = 0; i < src->nr; i++) {
640 o = src->objects[i].item;
629060d9 641 if (is_our_ref(o, allow_uor)) {
079aa97e
NTND
642 if (reachable)
643 add_object_array(o, NULL, reachable);
051e4005 644 continue;
079aa97e
NTND
645 }
646 if (reachable && o->type == OBJ_COMMIT)
647 o->flags |= TMP_MARK;
a698d67b 648 if (fprintf(cmd_in, "%s\n", oid_to_hex(&o->oid)) < 0)
051e4005
JH
649 goto error;
650 }
a698d67b
RS
651 if (ferror(cmd_in) || fflush(cmd_in))
652 goto error;
653 fclose(cmd_in);
2997178e
NTND
654 cmd->in = -1;
655 sigchain_pop(SIGPIPE);
051e4005 656
2997178e
NTND
657 return 0;
658
659error:
051e4005
JH
660 sigchain_pop(SIGPIPE);
661
a698d67b
RS
662 if (cmd_in)
663 fclose(cmd_in);
2997178e
NTND
664 if (cmd->out >= 0)
665 close(cmd->out);
666 return -1;
667}
668
f1514c6a 669static int get_reachable_list(struct upload_pack_data *data,
079aa97e
NTND
670 struct object_array *reachable)
671{
672 struct child_process cmd = CHILD_PROCESS_INIT;
673 int i;
674 struct object *o;
55dc227d 675 char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
676 const unsigned hexsz = the_hash_algo->hexsz;
079aa97e 677
f1514c6a 678 if (do_reachable_revlist(&cmd, &data->shallows, reachable,
629060d9 679 data->allow_uor) < 0)
079aa97e
NTND
680 return -1;
681
55dc227d 682 while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
62b89d43 683 struct object_id oid;
55dc227d 684 const char *p;
079aa97e 685
62b89d43 686 if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n')
079aa97e
NTND
687 break;
688
d0229abd 689 o = lookup_object(the_repository, &oid);
079aa97e
NTND
690 if (o && o->type == OBJ_COMMIT) {
691 o->flags &= ~TMP_MARK;
692 }
693 }
694 for (i = get_max_object_index(); 0 < i; i--) {
695 o = get_indexed_object(i - 1);
696 if (o && o->type == OBJ_COMMIT &&
697 (o->flags & TMP_MARK)) {
698 add_object_array(o, NULL, reachable);
699 o->flags &= ~TMP_MARK;
700 }
701 }
702 close(cmd.out);
703
704 if (finish_command(&cmd))
705 return -1;
706
707 return 0;
708}
709
629060d9 710static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
2997178e
NTND
711{
712 struct child_process cmd = CHILD_PROCESS_INIT;
713 char buf[1];
714 int i;
715
629060d9 716 if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0)
2997178e 717 return 1;
051e4005
JH
718
719 /*
720 * The commits out of the rev-list are not ancestors of
721 * our ref.
722 */
2997178e 723 i = read_in_full(cmd.out, buf, 1);
051e4005
JH
724 if (i)
725 goto error;
726 close(cmd.out);
7fcbd37f 727 cmd.out = -1;
051e4005
JH
728
729 /*
730 * rev-list may have died by encountering a bad commit
731 * in the history, in which case we do want to bail out
732 * even when it showed no commit.
733 */
734 if (finish_command(&cmd))
735 goto error;
736
737 /* All the non-tip ones are ancestors of what we advertised */
3f0f6624 738 return 0;
051e4005
JH
739
740error:
7fcbd37f
NTND
741 if (cmd.out >= 0)
742 close(cmd.out);
3f0f6624
NTND
743 return 1;
744}
7fcbd37f 745
b08c9742 746static void check_non_tip(struct upload_pack_data *data)
3f0f6624
NTND
747{
748 int i;
749
750 /*
751 * In the normal in-process case without
752 * uploadpack.allowReachableSHA1InWant,
753 * non-tip requests can never happen.
754 */
629060d9 755 if (!data->stateless_rpc && !(data->allow_uor & ALLOW_REACHABLE_SHA1))
3f0f6624 756 goto error;
629060d9 757 if (!has_unreachable(&data->want_obj, data->allow_uor))
3f0f6624
NTND
758 /* All the non-tip ones are ancestors of what we advertised */
759 return;
051e4005
JH
760
761error:
762 /* Pick one of them (we know there at least is one) */
b08c9742
CC
763 for (i = 0; i < data->want_obj.nr; i++) {
764 struct object *o = data->want_obj.objects[i].item;
629060d9 765 if (!is_our_ref(o, data->allow_uor)) {
b08c9742 766 packet_writer_error(&data->writer,
014ade74
JK
767 "upload-pack: not our ref %s",
768 oid_to_hex(&o->oid));
051e4005 769 die("git upload-pack: not our ref %s",
f2fd0760 770 oid_to_hex(&o->oid));
014ade74 771 }
051e4005
JH
772 }
773}
774
35b43a10 775static void send_shallow(struct upload_pack_data *data,
bc2e795c 776 struct commit_list *result)
5c24cdea
NTND
777{
778 while (result) {
779 struct object *object = &result->item->object;
780 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
35b43a10 781 packet_writer_write(&data->writer, "shallow %s",
bc2e795c 782 oid_to_hex(&object->oid));
19143f13 783 register_shallow(the_repository, &object->oid);
35b43a10 784 data->shallow_nr++;
5c24cdea
NTND
785 }
786 result = result->next;
787 }
788}
789
329f9960 790static void send_unshallow(struct upload_pack_data *data)
e8e44de7 791{
e8e44de7 792 int i;
873700c9 793
329f9960
CC
794 for (i = 0; i < data->shallows.nr; i++) {
795 struct object *object = data->shallows.objects[i].item;
e8e44de7
NTND
796 if (object->flags & NOT_SHALLOW) {
797 struct commit_list *parents;
329f9960 798 packet_writer_write(&data->writer, "unshallow %s",
bc2e795c 799 oid_to_hex(&object->oid));
e8e44de7 800 object->flags &= ~CLIENT_SHALLOW;
873700c9
NTND
801 /*
802 * We want to _register_ "object" as shallow, but we
803 * also need to traverse object's parents to deepen a
804 * shallow clone. Unregister it for now so we can
805 * parse and add the parents to the want list, then
806 * re-register it.
807 */
e92b848c 808 unregister_shallow(&object->oid);
e8e44de7
NTND
809 object->parsed = 0;
810 parse_commit_or_die((struct commit *)object);
811 parents = ((struct commit *)object)->parents;
812 while (parents) {
813 add_object_array(&parents->item->object,
329f9960 814 NULL, &data->want_obj);
e8e44de7
NTND
815 parents = parents->next;
816 }
de0e9f74 817 add_object_array(object, NULL, &data->extra_edge_obj);
e8e44de7
NTND
818 }
819 /* make sure commit traversal conforms to client */
19143f13 820 register_shallow(the_repository, &object->oid);
e8e44de7 821 }
873700c9
NTND
822}
823
5056cf4a
JT
824static int check_ref(const char *refname_full, const struct object_id *oid,
825 int flag, void *cb_data);
b1492f22 826static void deepen(struct upload_pack_data *data, int depth)
873700c9 827{
c8813487 828 if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
873700c9
NTND
829 int i;
830
b1492f22
CC
831 for (i = 0; i < data->shallows.nr; i++) {
832 struct object *object = data->shallows.objects[i].item;
873700c9
NTND
833 object->flags |= NOT_SHALLOW;
834 }
b1492f22 835 } else if (data->deepen_relative) {
cccf74e2
NTND
836 struct object_array reachable_shallows = OBJECT_ARRAY_INIT;
837 struct commit_list *result;
838
5056cf4a
JT
839 /*
840 * Checking for reachable shallows requires that our refs be
841 * marked with OUR_REF.
842 */
843 head_ref_namespaced(check_ref, NULL);
844 for_each_namespaced_ref(check_ref, NULL);
845
f1514c6a 846 get_reachable_list(data, &reachable_shallows);
cccf74e2
NTND
847 result = get_shallow_commits(&reachable_shallows,
848 depth + 1,
849 SHALLOW, NOT_SHALLOW);
35b43a10 850 send_shallow(data, result);
cccf74e2
NTND
851 free_commit_list(result);
852 object_array_clear(&reachable_shallows);
873700c9
NTND
853 } else {
854 struct commit_list *result;
855
b1492f22 856 result = get_shallow_commits(&data->want_obj, depth,
873700c9 857 SHALLOW, NOT_SHALLOW);
35b43a10 858 send_shallow(data, result);
873700c9
NTND
859 free_commit_list(result);
860 }
861
329f9960 862 send_unshallow(data);
e8e44de7
NTND
863}
864
446e42c5
CC
865static void deepen_by_rev_list(struct upload_pack_data *data,
866 int ac,
867 const char **av)
569e554b
NTND
868{
869 struct commit_list *result;
870
6abada18 871 disable_commit_graph(the_repository);
569e554b 872 result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
35b43a10 873 send_shallow(data, result);
569e554b 874 free_commit_list(result);
329f9960 875 send_unshallow(data);
685fbd32
BW
876}
877
878/* Returns 1 if a shallow list is sent or 0 otherwise */
ee703c8a 879static int send_shallow_list(struct upload_pack_data *data)
685fbd32
BW
880{
881 int ret = 0;
882
ee703c8a 883 if (data->depth > 0 && data->deepen_rev_list)
685fbd32 884 die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together");
ee703c8a 885 if (data->depth > 0) {
b1492f22 886 deepen(data, data->depth);
685fbd32 887 ret = 1;
ee703c8a 888 } else if (data->deepen_rev_list) {
c972bf4c 889 struct strvec av = STRVEC_INIT;
685fbd32
BW
890 int i;
891
c972bf4c 892 strvec_push(&av, "rev-list");
ee703c8a 893 if (data->deepen_since)
c972bf4c 894 strvec_pushf(&av, "--max-age=%"PRItime, data->deepen_since);
ee703c8a 895 if (data->deepen_not.nr) {
c972bf4c 896 strvec_push(&av, "--not");
ee703c8a
CC
897 for (i = 0; i < data->deepen_not.nr; i++) {
898 struct string_list_item *s = data->deepen_not.items + i;
c972bf4c 899 strvec_push(&av, s->string);
685fbd32 900 }
c972bf4c 901 strvec_push(&av, "--not");
685fbd32 902 }
ee703c8a
CC
903 for (i = 0; i < data->want_obj.nr; i++) {
904 struct object *o = data->want_obj.objects[i].item;
c972bf4c 905 strvec_push(&av, oid_to_hex(&o->oid));
685fbd32 906 }
d70a9eb6 907 deepen_by_rev_list(data, av.nr, av.v);
c972bf4c 908 strvec_clear(&av);
685fbd32
BW
909 ret = 1;
910 } else {
ee703c8a 911 if (data->shallows.nr > 0) {
685fbd32 912 int i;
ee703c8a 913 for (i = 0; i < data->shallows.nr; i++)
00624d60 914 register_shallow(the_repository,
ee703c8a 915 &data->shallows.objects[i].item->oid);
685fbd32
BW
916 }
917 }
918
35b43a10 919 data->shallow_nr += data->shallows.nr;
685fbd32 920 return ret;
569e554b
NTND
921}
922
ae2948f3
BW
923static int process_shallow(const char *line, struct object_array *shallows)
924{
925 const char *arg;
926 if (skip_prefix(line, "shallow ", &arg)) {
927 struct object_id oid;
928 struct object *object;
929 if (get_oid_hex(arg, &oid))
930 die("invalid shallow line: %s", line);
109cd76d 931 object = parse_object(the_repository, &oid);
ae2948f3
BW
932 if (!object)
933 return 1;
934 if (object->type != OBJ_COMMIT)
935 die("invalid shallow object %s", oid_to_hex(&oid));
936 if (!(object->flags & CLIENT_SHALLOW)) {
937 object->flags |= CLIENT_SHALLOW;
938 add_object_array(object, NULL, shallows);
939 }
940 return 1;
941 }
942
943 return 0;
944}
945
946static int process_deepen(const char *line, int *depth)
947{
948 const char *arg;
949 if (skip_prefix(line, "deepen ", &arg)) {
950 char *end = NULL;
951 *depth = (int)strtol(arg, &end, 0);
952 if (!end || *end || *depth <= 0)
953 die("Invalid deepen: %s", line);
954 return 1;
955 }
956
957 return 0;
958}
959
960static int process_deepen_since(const char *line, timestamp_t *deepen_since, int *deepen_rev_list)
961{
962 const char *arg;
963 if (skip_prefix(line, "deepen-since ", &arg)) {
964 char *end = NULL;
965 *deepen_since = parse_timestamp(arg, &end, 0);
966 if (!end || *end || !deepen_since ||
967 /* revisions.c's max_age -1 is special */
968 *deepen_since == -1)
969 die("Invalid deepen-since: %s", line);
970 *deepen_rev_list = 1;
971 return 1;
972 }
973 return 0;
974}
975
976static int process_deepen_not(const char *line, struct string_list *deepen_not, int *deepen_rev_list)
977{
978 const char *arg;
979 if (skip_prefix(line, "deepen-not ", &arg)) {
980 char *ref = NULL;
981 struct object_id oid;
0b1dbf53 982 if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
ae2948f3
BW
983 die("git upload-pack: ambiguous deepen-not: %s", line);
984 string_list_append(deepen_not, ref);
985 free(ref);
986 *deepen_rev_list = 1;
987 return 1;
988 }
989 return 0;
569e554b
NTND
990}
991
6dd3456a
TB
992NORETURN __attribute__((format(printf,2,3)))
993static void send_err_and_die(struct upload_pack_data *data,
994 const char *fmt, ...)
995{
996 struct strbuf buf = STRBUF_INIT;
997 va_list ap;
998
999 va_start(ap, fmt);
1000 strbuf_vaddf(&buf, fmt, ap);
1001 va_end(ap);
1002
1003 packet_writer_error(&data->writer, "%s", buf.buf);
1004 die("%s", buf.buf);
1005}
1006
1007static void check_one_filter(struct upload_pack_data *data,
1008 struct list_objects_filter_options *opts)
1009{
1010 const char *key = list_object_filter_config_name(opts->choice);
1011 struct string_list_item *item = string_list_lookup(&data->allowed_filters,
1012 key);
1013 int allowed;
1014
1015 if (item)
1016 allowed = (intptr_t)item->util;
1017 else
1018 allowed = data->allow_filter_fallback;
1019
1020 if (!allowed)
1021 send_err_and_die(data, "filter '%s' not supported", key);
5b01a4e8
TB
1022
1023 if (opts->choice == LOFC_TREE_DEPTH &&
1024 opts->tree_exclude_depth > data->tree_filter_max_depth)
1025 send_err_and_die(data,
1026 "tree filter allows max depth %lu, but got %lu",
1027 data->tree_filter_max_depth,
1028 opts->tree_exclude_depth);
6dd3456a
TB
1029}
1030
1031static void check_filter_recurse(struct upload_pack_data *data,
1032 struct list_objects_filter_options *opts)
1033{
1034 size_t i;
1035
1036 check_one_filter(data, opts);
1037 if (opts->choice != LOFC_COMBINE)
1038 return;
1039
1040 for (i = 0; i < opts->sub_nr; i++)
1041 check_filter_recurse(data, &opts->sub[i]);
1042}
1043
1044static void die_if_using_banned_filter(struct upload_pack_data *data)
1045{
1046 check_filter_recurse(data, &data->filter_options);
1047}
1048
d92ae2c0
CC
1049static void receive_needs(struct upload_pack_data *data,
1050 struct packet_reader *reader)
fb9040cc 1051{
051e4005 1052 int has_non_tip = 0;
fb9040cc 1053
35b43a10 1054 data->shallow_nr = 0;
fb9040cc 1055 for (;;) {
565ebbf7 1056 struct object *o;
f47182c8 1057 const char *features;
cf93982f 1058 struct object_id oid_buf;
8bf3b758
NTND
1059 const char *arg;
1060
d40f04e0 1061 reset_timeout(data->timeout);
01f9ec64 1062 if (packet_reader_read(reader) != PACKET_READ_NORMAL)
ed09aef0 1063 break;
e091eb93 1064
7a516764 1065 if (process_shallow(reader->line, &data->shallows))
ed09aef0 1066 continue;
7a516764 1067 if (process_deepen(reader->line, &data->depth))
016e6ccb 1068 continue;
7a516764 1069 if (process_deepen_since(reader->line, &data->deepen_since, &data->deepen_rev_list))
569e554b 1070 continue;
7a516764 1071 if (process_deepen_not(reader->line, &data->deepen_not, &data->deepen_rev_list))
269a7a83 1072 continue;
ae2948f3 1073
01f9ec64 1074 if (skip_prefix(reader->line, "filter ", &arg)) {
59a90261 1075 if (!data->filter_capability_requested)
10ac85c7 1076 die("git upload-pack: filtering capability not negotiated");
d92ae2c0
CC
1077 list_objects_filter_die_if_populated(&data->filter_options);
1078 parse_list_objects_filter(&data->filter_options, arg);
6dd3456a 1079 die_if_using_banned_filter(data);
10ac85c7
JH
1080 continue;
1081 }
9bfa0f9b 1082
01f9ec64 1083 if (!skip_prefix(reader->line, "want ", &arg) ||
55dc227d 1084 parse_oid_hex(arg, &oid_buf, &features))
7e44c935 1085 die("git upload-pack: protocol error, "
01f9ec64 1086 "expected to get object ID, not '%s'", reader->line);
f47182c8 1087
cccf74e2 1088 if (parse_feature_request(features, "deepen-relative"))
7a516764 1089 data->deepen_relative = 1;
f47182c8 1090 if (parse_feature_request(features, "multi_ack_detailed"))
e9d882b8 1091 data->multi_ack = MULTI_ACK_DETAILED;
f47182c8 1092 else if (parse_feature_request(features, "multi_ack"))
e9d882b8 1093 data->multi_ack = MULTI_ACK;
f47182c8 1094 if (parse_feature_request(features, "no-done"))
d40f04e0 1095 data->no_done = 1;
f47182c8 1096 if (parse_feature_request(features, "thin-pack"))
b5a2068c 1097 data->use_thin_pack = 1;
f47182c8 1098 if (parse_feature_request(features, "ofs-delta"))
b5a2068c 1099 data->use_ofs_delta = 1;
f47182c8 1100 if (parse_feature_request(features, "side-band-64k"))
f8edd1ca 1101 data->use_sideband = LARGE_PACKET_MAX;
f47182c8 1102 else if (parse_feature_request(features, "side-band"))
f8edd1ca 1103 data->use_sideband = DEFAULT_PACKET_MAX;
f47182c8 1104 if (parse_feature_request(features, "no-progress"))
b5a2068c 1105 data->no_progress = 1;
f47182c8 1106 if (parse_feature_request(features, "include-tag"))
b5a2068c 1107 data->use_include_tag = 1;
59abe196
CC
1108 if (data->allow_filter &&
1109 parse_feature_request(features, "filter"))
59a90261 1110 data->filter_capability_requested = 1;
565ebbf7 1111
109cd76d 1112 o = parse_object(the_repository, &oid_buf);
bdb31ead 1113 if (!o) {
4ace0283 1114 packet_writer_error(&data->writer,
bc2e795c
JT
1115 "upload-pack: not our ref %s",
1116 oid_to_hex(&oid_buf));
9f9aa761 1117 die("git upload-pack: not our ref %s",
cf93982f 1118 oid_to_hex(&oid_buf));
bdb31ead 1119 }
565ebbf7
JH
1120 if (!(o->flags & WANTED)) {
1121 o->flags |= WANTED;
629060d9
CC
1122 if (!((data->allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
1123 || is_our_ref(o, data->allow_uor)))
051e4005 1124 has_non_tip = 1;
d92ae2c0 1125 add_object_array(o, NULL, &data->want_obj);
565ebbf7 1126 }
fb9040cc 1127 }
9462e3f5 1128
051e4005
JH
1129 /*
1130 * We have sent all our refs already, and the other end
1131 * should have chosen out of them. When we are operating
1132 * in the stateless RPC mode, however, their choice may
1133 * have been based on the set of older refs advertised
1134 * by another process that handled the initial request.
1135 */
1136 if (has_non_tip)
b08c9742 1137 check_non_tip(data);
051e4005 1138
f8edd1ca 1139 if (!data->use_sideband && data->daemon_mode)
b5a2068c 1140 data->no_progress = 1;
9462e3f5 1141
7a516764 1142 if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
f53514bc 1143 return;
569e554b 1144
ee703c8a 1145 if (send_shallow_list(data))
685fbd32 1146 packet_flush(1);
fb9040cc
LT
1147}
1148
daebaa78 1149/* return non-zero if the ref is hidden, otherwise 0 */
78a766ab
LF
1150static int mark_our_ref(const char *refname, const char *refname_full,
1151 const struct object_id *oid)
cbbe50db 1152{
0ebbcf70 1153 struct object *o = lookup_unknown_object(oid);
daebaa78 1154
78a766ab 1155 if (ref_is_hidden(refname, refname_full)) {
390eb36b 1156 o->flags |= HIDDEN_REF;
daebaa78 1157 return 1;
390eb36b 1158 }
3f1da57f 1159 o->flags |= OUR_REF;
cbbe50db
JH
1160 return 0;
1161}
1162
78a766ab 1163static int check_ref(const char *refname_full, const struct object_id *oid,
363e98bf 1164 int flag, void *cb_data)
e172755b 1165{
78a766ab
LF
1166 const char *refname = strip_namespace(refname_full);
1167
1168 mark_our_ref(refname, refname_full, oid);
e172755b
JK
1169 return 0;
1170}
1171
7171d8c1
JH
1172static void format_symref_info(struct strbuf *buf, struct string_list *symref)
1173{
1174 struct string_list_item *item;
1175
1176 if (!symref->nr)
1177 return;
1178 for_each_string_list_item(item, symref)
1179 strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util);
1180}
1181
363e98bf
MH
1182static int send_ref(const char *refname, const struct object_id *oid,
1183 int flag, void *cb_data)
def88e9a 1184{
ed09aef0 1185 static const char *capabilities = "multi_ack thin-pack side-band"
cccf74e2
NTND
1186 " side-band-64k ofs-delta shallow deepen-since deepen-not"
1187 " deepen-relative no-progress include-tag multi_ack_detailed";
6b01ecfe 1188 const char *refname_nons = strip_namespace(refname);
21758aff 1189 struct object_id peeled;
762f9276 1190 struct upload_pack_data *data = cb_data;
b5b16990 1191
78a766ab 1192 if (mark_our_ref(refname_nons, refname, oid))
daebaa78 1193 return 0;
cbbe50db 1194
7171d8c1
JH
1195 if (capabilities) {
1196 struct strbuf symref_info = STRBUF_INIT;
1197
762f9276 1198 format_symref_info(&symref_info, &data->symref);
bf30dbf8 1199 packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s object-format=%s agent=%s\n",
363e98bf 1200 oid_to_hex(oid), refname_nons,
cf2ad8e6 1201 0, capabilities,
629060d9 1202 (data->allow_uor & ALLOW_TIP_SHA1) ?
7199c093 1203 " allow-tip-sha1-in-want" : "",
629060d9 1204 (data->allow_uor & ALLOW_REACHABLE_SHA1) ?
68ee6289 1205 " allow-reachable-sha1-in-want" : "",
df654abc 1206 data->stateless_rpc ? " no-done" : "",
7171d8c1 1207 symref_info.buf,
59abe196 1208 data->allow_filter ? " filter" : "",
bf30dbf8 1209 the_hash_algo->name,
ff5effdf 1210 git_user_agent_sanitized());
7171d8c1
JH
1211 strbuf_release(&symref_info);
1212 } else {
81c634e9 1213 packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
7171d8c1 1214 }
1f5881bb 1215 capabilities = NULL;
b420d909 1216 if (!peel_ref(refname, &peeled))
81c634e9 1217 packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
def88e9a
LT
1218 return 0;
1219}
1220
7dabd056
MH
1221static int find_symref(const char *refname, const struct object_id *oid,
1222 int flag, void *cb_data)
7171d8c1
JH
1223{
1224 const char *symref_target;
1225 struct string_list_item *item;
7171d8c1
JH
1226
1227 if ((flag & REF_ISSYMREF) == 0)
1228 return 0;
744c040b 1229 symref_target = resolve_ref_unsafe(refname, 0, NULL, &flag);
7171d8c1
JH
1230 if (!symref_target || (flag & REF_ISSYMREF) == 0)
1231 die("'%s' is a symref but it is not?", refname);
533e0882
JK
1232 item = string_list_append(cb_data, strip_namespace(refname));
1233 item->util = xstrdup(strip_namespace(symref_target));
7171d8c1
JH
1234 return 0;
1235}
1236
6dd3456a
TB
1237static int parse_object_filter_config(const char *var, const char *value,
1238 struct upload_pack_data *data)
1239{
1240 struct strbuf buf = STRBUF_INIT;
1241 const char *sub, *key;
1242 size_t sub_len;
1243
1244 if (parse_config_key(var, "uploadpackfilter", &sub, &sub_len, &key))
1245 return 0;
1246
1247 if (!sub) {
1248 if (!strcmp(key, "allow"))
1249 data->allow_filter_fallback = git_config_bool(var, value);
1250 return 0;
1251 }
1252
1253 strbuf_add(&buf, sub, sub_len);
1254
1255 if (!strcmp(key, "allow"))
1256 string_list_insert(&data->allowed_filters, buf.buf)->util =
1257 (void *)(intptr_t)git_config_bool(var, value);
5b01a4e8
TB
1258 else if (!strcmp(buf.buf, "tree") && !strcmp(key, "maxdepth")) {
1259 if (!value) {
1260 strbuf_release(&buf);
1261 return config_error_nonbool(var);
1262 }
1263 string_list_insert(&data->allowed_filters, buf.buf)->util =
1264 (void *)(intptr_t)1;
1265 data->tree_filter_max_depth = git_config_ulong(var, value);
1266 }
6dd3456a
TB
1267
1268 strbuf_release(&buf);
1269 return 0;
1270}
1271
8a0e6f16 1272static int upload_pack_config(const char *var, const char *value, void *cb_data)
daebaa78 1273{
f203a88c
CC
1274 struct upload_pack_data *data = cb_data;
1275
7199c093
FM
1276 if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
1277 if (git_config_bool(var, value))
629060d9 1278 data->allow_uor |= ALLOW_TIP_SHA1;
7199c093 1279 else
629060d9 1280 data->allow_uor &= ~ALLOW_TIP_SHA1;
68ee6289
FM
1281 } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
1282 if (git_config_bool(var, value))
629060d9 1283 data->allow_uor |= ALLOW_REACHABLE_SHA1;
68ee6289 1284 else
629060d9 1285 data->allow_uor &= ~ALLOW_REACHABLE_SHA1;
f8edeaa0
DT
1286 } else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
1287 if (git_config_bool(var, value))
629060d9 1288 data->allow_uor |= ALLOW_ANY_SHA1;
f8edeaa0 1289 else
629060d9 1290 data->allow_uor &= ~ALLOW_ANY_SHA1;
7199c093 1291 } else if (!strcmp("uploadpack.keepalive", var)) {
f203a88c
CC
1292 data->keepalive = git_config_int(var, value);
1293 if (!data->keepalive)
1294 data->keepalive = -1;
10ac85c7 1295 } else if (!strcmp("uploadpack.allowfilter", var)) {
59abe196 1296 data->allow_filter = git_config_bool(var, value);
516e2b76 1297 } else if (!strcmp("uploadpack.allowrefinwant", var)) {
d1d7a945 1298 data->allow_ref_in_want = git_config_bool(var, value);
0bbc0bc5 1299 } else if (!strcmp("uploadpack.allowsidebandall", var)) {
e3835cd4 1300 data->allow_sideband_all = git_config_bool(var, value);
8e712ef6
EN
1301 } else if (!strcmp("core.precomposeunicode", var)) {
1302 precomposed_unicode = git_config_bool(var, value);
05e95155 1303 }
aaaa8818 1304
6dc905d9
MR
1305 if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
1306 current_config_scope() != CONFIG_SCOPE_WORKTREE) {
aaaa8818 1307 if (!strcmp("uploadpack.packobjectshook", var))
339a9840 1308 return git_config_string(&data->pack_objects_hook, var, value);
aaaa8818
JK
1309 }
1310
6dd3456a
TB
1311 parse_object_filter_config(var, value, data);
1312
daebaa78
JH
1313 return parse_hide_refs_config(var, value, "uploadpack");
1314}
1315
a3d6b53e 1316void upload_pack(struct upload_pack_options *options)
def88e9a 1317{
01f9ec64 1318 struct packet_reader reader;
ebf8ebcc 1319 struct upload_pack_data data;
960deccb 1320
ebf8ebcc
CC
1321 upload_pack_data_init(&data);
1322
8a0e6f16
CC
1323 git_config(upload_pack_config, &data);
1324
df654abc 1325 data.stateless_rpc = options->stateless_rpc;
d40f04e0
CC
1326 data.daemon_mode = options->daemon_mode;
1327 data.timeout = options->timeout;
df654abc 1328
438528f6 1329 head_ref_namespaced(find_symref, &data.symref);
a6080a0a 1330
df654abc 1331 if (options->advertise_refs || !data.stateless_rpc) {
d40f04e0 1332 reset_timeout(data.timeout);
762f9276
CC
1333 head_ref_namespaced(send_ref, &data);
1334 for_each_namespaced_ref(send_ref, &data);
a3d6b53e
BW
1335 advertise_shallow_grafts(1);
1336 packet_flush(1);
1337 } else {
1338 head_ref_namespaced(check_ref, NULL);
1339 for_each_namespaced_ref(check_ref, NULL);
aa9bab29 1340 }
01f9ec64 1341
ebf8ebcc
CC
1342 if (!options->advertise_refs) {
1343 packet_reader_init(&reader, 0, NULL, 0,
1344 PACKET_READ_CHOMP_NEWLINE |
1345 PACKET_READ_DIE_ON_ERR_PACKET);
1346
d92ae2c0 1347 receive_needs(&data, &reader);
fb3d1a08
DD
1348
1349 /*
1350 * An EOF at this exact point in negotiation should be
1351 * acceptable from stateless clients as they will consume the
1352 * shallow list before doing subsequent rpc with haves/etc.
1353 */
1354 if (data.stateless_rpc)
1355 reader.options |= PACKET_READ_GENTLE_ON_EOF;
1356
1357 if (data.want_obj.nr &&
1358 packet_reader_peek(&reader) != PACKET_READ_EOF) {
1359 reader.options &= ~PACKET_READ_GENTLE_ON_EOF;
07977695 1360 get_common_commits(&data, &reader);
cae2ee10 1361 create_pack_file(&data, NULL);
ebf8ebcc 1362 }
a3d6b53e 1363 }
08450ef7 1364
ebf8ebcc 1365 upload_pack_data_clear(&data);
def88e9a 1366}
04b33055 1367
bc2e795c
JT
1368static int parse_want(struct packet_writer *writer, const char *line,
1369 struct object_array *want_obj)
3145ea95
BW
1370{
1371 const char *arg;
1372 if (skip_prefix(line, "want ", &arg)) {
1373 struct object_id oid;
1374 struct object *o;
1375
1376 if (get_oid_hex(arg, &oid))
1377 die("git upload-pack: protocol error, "
1378 "expected to get oid, not '%s'", line);
1379
109cd76d 1380 o = parse_object(the_repository, &oid);
3145ea95 1381 if (!o) {
bc2e795c
JT
1382 packet_writer_error(writer,
1383 "upload-pack: not our ref %s",
1384 oid_to_hex(&oid));
3145ea95
BW
1385 die("git upload-pack: not our ref %s",
1386 oid_to_hex(&oid));
1387 }
1388
1389 if (!(o->flags & WANTED)) {
1390 o->flags |= WANTED;
1d1243fe 1391 add_object_array(o, NULL, want_obj);
3145ea95
BW
1392 }
1393
1394 return 1;
1395 }
1396
1397 return 0;
1398}
1399
bc2e795c
JT
1400static int parse_want_ref(struct packet_writer *writer, const char *line,
1401 struct string_list *wanted_refs,
1d1243fe 1402 struct object_array *want_obj)
516e2b76
BW
1403{
1404 const char *arg;
1405 if (skip_prefix(line, "want-ref ", &arg)) {
1406 struct object_id oid;
1407 struct string_list_item *item;
1408 struct object *o;
1409
1410 if (read_ref(arg, &oid)) {
bc2e795c 1411 packet_writer_error(writer, "unknown ref %s", arg);
516e2b76
BW
1412 die("unknown ref %s", arg);
1413 }
1414
1415 item = string_list_append(wanted_refs, arg);
1416 item->util = oiddup(&oid);
1417
1418 o = parse_object_or_die(&oid, arg);
1419 if (!(o->flags & WANTED)) {
1420 o->flags |= WANTED;
1d1243fe 1421 add_object_array(o, NULL, want_obj);
516e2b76
BW
1422 }
1423
1424 return 1;
1425 }
1426
1427 return 0;
1428}
1429
3145ea95
BW
1430static int parse_have(const char *line, struct oid_array *haves)
1431{
1432 const char *arg;
1433 if (skip_prefix(line, "have ", &arg)) {
1434 struct object_id oid;
1435
1436 if (get_oid_hex(arg, &oid))
1437 die("git upload-pack: expected SHA1 object, got '%s'", arg);
1438 oid_array_append(haves, &oid);
1439 return 1;
aa9bab29
BW
1440 }
1441
def88e9a
LT
1442 return 0;
1443}
3145ea95
BW
1444
1445static void process_args(struct packet_reader *request,
389f161a 1446 struct upload_pack_data *data)
3145ea95 1447{
4845b772 1448 while (packet_reader_read(request) == PACKET_READ_NORMAL) {
3145ea95 1449 const char *arg = request->line;
ba95710a 1450 const char *p;
3145ea95
BW
1451
1452 /* process want */
389f161a 1453 if (parse_want(&data->writer, arg, &data->want_obj))
3145ea95 1454 continue;
d1d7a945 1455 if (data->allow_ref_in_want &&
bc2e795c 1456 parse_want_ref(&data->writer, arg, &data->wanted_refs,
389f161a 1457 &data->want_obj))
516e2b76 1458 continue;
3145ea95
BW
1459 /* process have line */
1460 if (parse_have(arg, &data->haves))
1461 continue;
1462
1463 /* process args like thin-pack */
1464 if (!strcmp(arg, "thin-pack")) {
b5a2068c 1465 data->use_thin_pack = 1;
3145ea95
BW
1466 continue;
1467 }
1468 if (!strcmp(arg, "ofs-delta")) {
b5a2068c 1469 data->use_ofs_delta = 1;
3145ea95
BW
1470 continue;
1471 }
1472 if (!strcmp(arg, "no-progress")) {
b5a2068c 1473 data->no_progress = 1;
3145ea95
BW
1474 continue;
1475 }
1476 if (!strcmp(arg, "include-tag")) {
b5a2068c 1477 data->use_include_tag = 1;
3145ea95
BW
1478 continue;
1479 }
1480 if (!strcmp(arg, "done")) {
1481 data->done = 1;
1482 continue;
1483 }
1484
685fbd32
BW
1485 /* Shallow related arguments */
1486 if (process_shallow(arg, &data->shallows))
1487 continue;
1488 if (process_deepen(arg, &data->depth))
1489 continue;
1490 if (process_deepen_since(arg, &data->deepen_since,
1491 &data->deepen_rev_list))
1492 continue;
1493 if (process_deepen_not(arg, &data->deepen_not,
1494 &data->deepen_rev_list))
1495 continue;
1496 if (!strcmp(arg, "deepen-relative")) {
1497 data->deepen_relative = 1;
1498 continue;
1499 }
1500
59abe196 1501 if (data->allow_filter && skip_prefix(arg, "filter ", &p)) {
08450ef7
CC
1502 list_objects_filter_die_if_populated(&data->filter_options);
1503 parse_list_objects_filter(&data->filter_options, p);
6dd3456a 1504 die_if_using_banned_filter(data);
ba95710a
JT
1505 continue;
1506 }
1507
07c3c2aa 1508 if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
e3835cd4 1509 data->allow_sideband_all) &&
07c3c2aa 1510 !strcmp(arg, "sideband-all")) {
0bbc0bc5
JT
1511 data->writer.use_sideband = 1;
1512 continue;
1513 }
1514
dd4b732d
JT
1515 if (skip_prefix(arg, "packfile-uris ", &p)) {
1516 string_list_split(&data->uri_protocols, p, ',', -1);
1517 continue;
1518 }
1519
3145ea95 1520 /* ignore unknown lines maybe? */
7cc6ed2d 1521 die("unexpected line: '%s'", arg);
3145ea95 1522 }
4845b772 1523
dd4b732d
JT
1524 if (data->uri_protocols.nr && !data->writer.use_sideband)
1525 string_list_clear(&data->uri_protocols, 0);
1526
4845b772
JK
1527 if (request->status != PACKET_READ_FLUSH)
1528 die(_("expected flush after fetch arguments"));
3145ea95
BW
1529}
1530
8dcf2278 1531static int process_haves(struct upload_pack_data *data, struct oid_array *common)
3145ea95
BW
1532{
1533 int i;
1534
1535 /* Process haves */
8dcf2278
CC
1536 for (i = 0; i < data->haves.nr; i++) {
1537 const struct object_id *oid = &data->haves.oid[i];
3145ea95 1538
77aa0941
JT
1539 if (!has_object_file_with_flags(oid,
1540 OBJECT_INFO_QUICK | OBJECT_INFO_SKIP_FETCH_OBJECT))
3145ea95
BW
1541 continue;
1542
1543 oid_array_append(common, oid);
1544
ea2c6e60 1545 do_got_oid(data, oid);
3145ea95
BW
1546 }
1547
1548 return 0;
1549}
1550
6fbbc437 1551static int send_acks(struct upload_pack_data *data, struct oid_array *acks)
3145ea95
BW
1552{
1553 int i;
1554
6fbbc437 1555 packet_writer_write(&data->writer, "acknowledgments\n");
3145ea95
BW
1556
1557 /* Send Acks */
1558 if (!acks->nr)
6fbbc437 1559 packet_writer_write(&data->writer, "NAK\n");
3145ea95
BW
1560
1561 for (i = 0; i < acks->nr; i++) {
6fbbc437 1562 packet_writer_write(&data->writer, "ACK %s\n",
bc2e795c 1563 oid_to_hex(&acks->oid[i]));
3145ea95
BW
1564 }
1565
08667348 1566 if (ok_to_give_up(data)) {
3145ea95 1567 /* Send Ready */
6fbbc437 1568 packet_writer_write(&data->writer, "ready\n");
3145ea95
BW
1569 return 1;
1570 }
1571
1572 return 0;
1573}
1574
389f161a 1575static int process_haves_and_send_acks(struct upload_pack_data *data)
3145ea95
BW
1576{
1577 struct oid_array common = OID_ARRAY_INIT;
3145ea95
BW
1578 int ret = 0;
1579
8dcf2278 1580 process_haves(data, &common);
3145ea95
BW
1581 if (data->done) {
1582 ret = 1;
6fbbc437 1583 } else if (send_acks(data, &common)) {
bc2e795c 1584 packet_writer_delim(&data->writer);
3145ea95
BW
1585 ret = 1;
1586 } else {
1587 /* Add Flush */
bc2e795c 1588 packet_writer_flush(&data->writer);
3145ea95
BW
1589 ret = 0;
1590 }
1591
3145ea95
BW
1592 oid_array_clear(&data->haves);
1593 oid_array_clear(&common);
1594 return ret;
1595}
1596
516e2b76
BW
1597static void send_wanted_ref_info(struct upload_pack_data *data)
1598{
1599 const struct string_list_item *item;
1600
1601 if (!data->wanted_refs.nr)
1602 return;
1603
bc2e795c 1604 packet_writer_write(&data->writer, "wanted-refs\n");
516e2b76
BW
1605
1606 for_each_string_list_item(item, &data->wanted_refs) {
bc2e795c
JT
1607 packet_writer_write(&data->writer, "%s %s\n",
1608 oid_to_hex(item->util),
1609 item->string);
516e2b76
BW
1610 }
1611
bc2e795c 1612 packet_writer_delim(&data->writer);
516e2b76
BW
1613}
1614
389f161a 1615static void send_shallow_info(struct upload_pack_data *data)
685fbd32
BW
1616{
1617 /* No shallow info needs to be sent */
1618 if (!data->depth && !data->deepen_rev_list && !data->shallows.nr &&
00624d60 1619 !is_repository_shallow(the_repository))
685fbd32
BW
1620 return;
1621
bc2e795c 1622 packet_writer_write(&data->writer, "shallow-info\n");
685fbd32 1623
ee703c8a 1624 if (!send_shallow_list(data) &&
00624d60 1625 is_repository_shallow(the_repository))
b1492f22 1626 deepen(data, INFINITE_DEPTH);
685fbd32
BW
1627
1628 packet_delim(1);
1629}
1630
3145ea95
BW
1631enum fetch_state {
1632 FETCH_PROCESS_ARGS = 0,
1633 FETCH_SEND_ACKS,
1634 FETCH_SEND_PACK,
1635 FETCH_DONE,
1636};
1637
c972bf4c 1638int upload_pack_v2(struct repository *r, struct strvec *keys,
3145ea95
BW
1639 struct packet_reader *request)
1640{
1641 enum fetch_state state = FETCH_PROCESS_ARGS;
1642 struct upload_pack_data data;
d1035cac
JT
1643
1644 clear_object_flags(ALL_FLAGS);
3145ea95
BW
1645
1646 upload_pack_data_init(&data);
f8edd1ca 1647 data.use_sideband = LARGE_PACKET_MAX;
3145ea95 1648
8a0e6f16
CC
1649 git_config(upload_pack_config, &data);
1650
3145ea95
BW
1651 while (state != FETCH_DONE) {
1652 switch (state) {
1653 case FETCH_PROCESS_ARGS:
389f161a 1654 process_args(request, &data);
3145ea95 1655
389f161a 1656 if (!data.want_obj.nr) {
3145ea95
BW
1657 /*
1658 * Request didn't contain any 'want' lines,
1659 * guess they didn't want anything.
1660 */
1661 state = FETCH_DONE;
1662 } else if (data.haves.nr) {
1663 /*
1664 * Request had 'have' lines, so lets ACK them.
1665 */
1666 state = FETCH_SEND_ACKS;
1667 } else {
1668 /*
1669 * Request had 'want's but no 'have's so we can
1670 * immedietly go to construct and send a pack.
1671 */
1672 state = FETCH_SEND_PACK;
1673 }
1674 break;
1675 case FETCH_SEND_ACKS:
389f161a 1676 if (process_haves_and_send_acks(&data))
3145ea95
BW
1677 state = FETCH_SEND_PACK;
1678 else
1679 state = FETCH_DONE;
1680 break;
1681 case FETCH_SEND_PACK:
516e2b76 1682 send_wanted_ref_info(&data);
389f161a 1683 send_shallow_info(&data);
685fbd32 1684
dd4b732d
JT
1685 if (data.uri_protocols.nr) {
1686 create_pack_file(&data, &data.uri_protocols);
1687 } else {
1688 packet_writer_write(&data.writer, "packfile\n");
1689 create_pack_file(&data, NULL);
1690 }
3145ea95
BW
1691 state = FETCH_DONE;
1692 break;
1693 case FETCH_DONE:
1694 continue;
1695 }
1696 }
1697
1698 upload_pack_data_clear(&data);
1699 return 0;
1700}
685fbd32
BW
1701
1702int upload_pack_advertise(struct repository *r,
1703 struct strbuf *value)
1704{
ba95710a
JT
1705 if (value) {
1706 int allow_filter_value;
516e2b76 1707 int allow_ref_in_want;
0bbc0bc5 1708 int allow_sideband_all_value;
dd4b732d 1709 char *str = NULL;
516e2b76 1710
685fbd32 1711 strbuf_addstr(value, "shallow");
516e2b76 1712
ba95710a
JT
1713 if (!repo_config_get_bool(the_repository,
1714 "uploadpack.allowfilter",
1715 &allow_filter_value) &&
1716 allow_filter_value)
1717 strbuf_addstr(value, " filter");
516e2b76
BW
1718
1719 if (!repo_config_get_bool(the_repository,
1720 "uploadpack.allowrefinwant",
1721 &allow_ref_in_want) &&
1722 allow_ref_in_want)
1723 strbuf_addstr(value, " ref-in-want");
0bbc0bc5 1724
07c3c2aa
JT
1725 if (git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
1726 (!repo_config_get_bool(the_repository,
1727 "uploadpack.allowsidebandall",
1728 &allow_sideband_all_value) &&
1729 allow_sideband_all_value))
0bbc0bc5 1730 strbuf_addstr(value, " sideband-all");
dd4b732d
JT
1731
1732 if (!repo_config_get_string(the_repository,
1733 "uploadpack.blobpackfileuri",
1734 &str) &&
1735 str) {
1736 strbuf_addstr(value, " packfile-uris");
1737 free(str);
1738 }
ba95710a 1739 }
516e2b76 1740
685fbd32
BW
1741 return 1;
1742}