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