upload-pack: pass upload_pack_data to send_ref()
[git.git] / upload-pack.c
blobbc259f17138f153b83ac1b3aeb39a71d1ae241bb
1 #include "cache.h"
2 #include "config.h"
3 #include "refs.h"
4 #include "pkt-line.h"
5 #include "sideband.h"
6 #include "repository.h"
7 #include "object-store.h"
8 #include "tag.h"
9 #include "object.h"
10 #include "commit.h"
11 #include "diff.h"
12 #include "revision.h"
13 #include "list-objects.h"
14 #include "list-objects-filter.h"
15 #include "list-objects-filter-options.h"
16 #include "run-command.h"
17 #include "connect.h"
18 #include "sigchain.h"
19 #include "version.h"
20 #include "string-list.h"
21 #include "argv-array.h"
22 #include "prio-queue.h"
23 #include "protocol.h"
24 #include "quote.h"
25 #include "upload-pack.h"
26 #include "serve.h"
27 #include "commit-graph.h"
28 #include "commit-reach.h"
29 #include "shallow.h"
31 /* Remember to update object flag allocation in object.h */
32 #define THEY_HAVE (1u << 11)
33 #define OUR_REF (1u << 12)
34 #define WANTED (1u << 13)
35 #define COMMON_KNOWN (1u << 14)
37 #define SHALLOW (1u << 16)
38 #define NOT_SHALLOW (1u << 17)
39 #define CLIENT_SHALLOW (1u << 18)
40 #define HIDDEN_REF (1u << 19)
42 #define ALL_FLAGS (THEY_HAVE | OUR_REF | WANTED | COMMON_KNOWN | SHALLOW | \
43 NOT_SHALLOW | CLIENT_SHALLOW | HIDDEN_REF)
45 static timestamp_t oldest_have;
47 static int multi_ack;
48 static int no_done;
49 static int use_thin_pack, use_ofs_delta, use_include_tag;
50 static int no_progress, daemon_mode;
51 /* Allow specifying sha1 if it is a ref tip. */
52 #define ALLOW_TIP_SHA1 01
53 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
54 #define ALLOW_REACHABLE_SHA1 02
55 /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
56 #define ALLOW_ANY_SHA1 07
57 static unsigned int allow_unadvertised_object_request;
58 static int shallow_nr;
59 static struct object_array extra_edge_obj;
60 static unsigned int timeout;
61 static int keepalive = 5;
62 /* 0 for no sideband,
63 * otherwise maximum packet size (up to 65520 bytes).
65 static int use_sideband;
66 static int stateless_rpc;
67 static const char *pack_objects_hook;
69 static int filter_capability_requested;
70 static int allow_filter;
71 static int allow_ref_in_want;
73 static int allow_sideband_all;
75 struct upload_pack_data {
76 struct string_list symref;
77 struct string_list wanted_refs;
78 struct object_array want_obj;
79 struct object_array have_obj;
80 struct oid_array haves;
82 struct object_array shallows;
83 struct string_list deepen_not;
84 int depth;
85 timestamp_t deepen_since;
86 int deepen_rev_list;
87 int deepen_relative;
89 struct list_objects_filter_options filter_options;
91 struct packet_writer writer;
93 unsigned stateless_rpc : 1;
95 unsigned use_thin_pack : 1;
96 unsigned use_ofs_delta : 1;
97 unsigned no_progress : 1;
98 unsigned use_include_tag : 1;
99 unsigned done : 1;
102 static void upload_pack_data_init(struct upload_pack_data *data)
104 struct string_list symref = STRING_LIST_INIT_DUP;
105 struct string_list wanted_refs = STRING_LIST_INIT_DUP;
106 struct object_array want_obj = OBJECT_ARRAY_INIT;
107 struct object_array have_obj = OBJECT_ARRAY_INIT;
108 struct oid_array haves = OID_ARRAY_INIT;
109 struct object_array shallows = OBJECT_ARRAY_INIT;
110 struct string_list deepen_not = STRING_LIST_INIT_DUP;
112 memset(data, 0, sizeof(*data));
113 data->symref = symref;
114 data->wanted_refs = wanted_refs;
115 data->want_obj = want_obj;
116 data->have_obj = have_obj;
117 data->haves = haves;
118 data->shallows = shallows;
119 data->deepen_not = deepen_not;
120 packet_writer_init(&data->writer, 1);
123 static void upload_pack_data_clear(struct upload_pack_data *data)
125 string_list_clear(&data->symref, 1);
126 string_list_clear(&data->wanted_refs, 1);
127 object_array_clear(&data->want_obj);
128 object_array_clear(&data->have_obj);
129 oid_array_clear(&data->haves);
130 object_array_clear(&data->shallows);
131 string_list_clear(&data->deepen_not, 0);
132 list_objects_filter_release(&data->filter_options);
135 static void reset_timeout(void)
137 alarm(timeout);
140 static void send_client_data(int fd, const char *data, ssize_t sz)
142 if (use_sideband) {
143 send_sideband(1, fd, data, sz, use_sideband);
144 return;
146 if (fd == 3)
147 /* emergency quit */
148 fd = 2;
149 if (fd == 2) {
150 /* XXX: are we happy to lose stuff here? */
151 xwrite(fd, data, sz);
152 return;
154 write_or_die(fd, data, sz);
157 static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
159 FILE *fp = cb_data;
160 if (graft->nr_parent == -1)
161 fprintf(fp, "--shallow %s\n", oid_to_hex(&graft->oid));
162 return 0;
165 static void create_pack_file(const struct object_array *have_obj,
166 const struct object_array *want_obj,
167 struct list_objects_filter_options *filter_options)
169 struct child_process pack_objects = CHILD_PROCESS_INIT;
170 char data[8193], progress[128];
171 char abort_msg[] = "aborting due to possible repository "
172 "corruption on the remote side.";
173 int buffered = -1;
174 ssize_t sz;
175 int i;
176 FILE *pipe_fd;
178 if (!pack_objects_hook)
179 pack_objects.git_cmd = 1;
180 else {
181 argv_array_push(&pack_objects.args, pack_objects_hook);
182 argv_array_push(&pack_objects.args, "git");
183 pack_objects.use_shell = 1;
186 if (shallow_nr) {
187 argv_array_push(&pack_objects.args, "--shallow-file");
188 argv_array_push(&pack_objects.args, "");
190 argv_array_push(&pack_objects.args, "pack-objects");
191 argv_array_push(&pack_objects.args, "--revs");
192 if (use_thin_pack)
193 argv_array_push(&pack_objects.args, "--thin");
195 argv_array_push(&pack_objects.args, "--stdout");
196 if (shallow_nr)
197 argv_array_push(&pack_objects.args, "--shallow");
198 if (!no_progress)
199 argv_array_push(&pack_objects.args, "--progress");
200 if (use_ofs_delta)
201 argv_array_push(&pack_objects.args, "--delta-base-offset");
202 if (use_include_tag)
203 argv_array_push(&pack_objects.args, "--include-tag");
204 if (filter_options->choice) {
205 const char *spec =
206 expand_list_objects_filter_spec(filter_options);
207 if (pack_objects.use_shell) {
208 struct strbuf buf = STRBUF_INIT;
209 sq_quote_buf(&buf, spec);
210 argv_array_pushf(&pack_objects.args, "--filter=%s", buf.buf);
211 strbuf_release(&buf);
212 } else {
213 argv_array_pushf(&pack_objects.args, "--filter=%s",
214 spec);
218 pack_objects.in = -1;
219 pack_objects.out = -1;
220 pack_objects.err = -1;
222 if (start_command(&pack_objects))
223 die("git upload-pack: unable to fork git-pack-objects");
225 pipe_fd = xfdopen(pack_objects.in, "w");
227 if (shallow_nr)
228 for_each_commit_graft(write_one_shallow, pipe_fd);
230 for (i = 0; i < want_obj->nr; i++)
231 fprintf(pipe_fd, "%s\n",
232 oid_to_hex(&want_obj->objects[i].item->oid));
233 fprintf(pipe_fd, "--not\n");
234 for (i = 0; i < have_obj->nr; i++)
235 fprintf(pipe_fd, "%s\n",
236 oid_to_hex(&have_obj->objects[i].item->oid));
237 for (i = 0; i < extra_edge_obj.nr; i++)
238 fprintf(pipe_fd, "%s\n",
239 oid_to_hex(&extra_edge_obj.objects[i].item->oid));
240 fprintf(pipe_fd, "\n");
241 fflush(pipe_fd);
242 fclose(pipe_fd);
244 /* We read from pack_objects.err to capture stderr output for
245 * progress bar, and pack_objects.out to capture the pack data.
248 while (1) {
249 struct pollfd pfd[2];
250 int pe, pu, pollsize;
251 int ret;
253 reset_timeout();
255 pollsize = 0;
256 pe = pu = -1;
258 if (0 <= pack_objects.out) {
259 pfd[pollsize].fd = pack_objects.out;
260 pfd[pollsize].events = POLLIN;
261 pu = pollsize;
262 pollsize++;
264 if (0 <= pack_objects.err) {
265 pfd[pollsize].fd = pack_objects.err;
266 pfd[pollsize].events = POLLIN;
267 pe = pollsize;
268 pollsize++;
271 if (!pollsize)
272 break;
274 ret = poll(pfd, pollsize,
275 keepalive < 0 ? -1 : 1000 * keepalive);
277 if (ret < 0) {
278 if (errno != EINTR) {
279 error_errno("poll failed, resuming");
280 sleep(1);
282 continue;
284 if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
285 /* Status ready; we ship that in the side-band
286 * or dump to the standard error.
288 sz = xread(pack_objects.err, progress,
289 sizeof(progress));
290 if (0 < sz)
291 send_client_data(2, progress, sz);
292 else if (sz == 0) {
293 close(pack_objects.err);
294 pack_objects.err = -1;
296 else
297 goto fail;
298 /* give priority to status messages */
299 continue;
301 if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
302 /* Data ready; we keep the last byte to ourselves
303 * in case we detect broken rev-list, so that we
304 * can leave the stream corrupted. This is
305 * unfortunate -- unpack-objects would happily
306 * accept a valid packdata with trailing garbage,
307 * so appending garbage after we pass all the
308 * pack data is not good enough to signal
309 * breakage to downstream.
311 char *cp = data;
312 ssize_t outsz = 0;
313 if (0 <= buffered) {
314 *cp++ = buffered;
315 outsz++;
317 sz = xread(pack_objects.out, cp,
318 sizeof(data) - outsz);
319 if (0 < sz)
321 else if (sz == 0) {
322 close(pack_objects.out);
323 pack_objects.out = -1;
325 else
326 goto fail;
327 sz += outsz;
328 if (1 < sz) {
329 buffered = data[sz-1] & 0xFF;
330 sz--;
332 else
333 buffered = -1;
334 send_client_data(1, data, sz);
338 * We hit the keepalive timeout without saying anything; send
339 * an empty message on the data sideband just to let the other
340 * side know we're still working on it, but don't have any data
341 * yet.
343 * If we don't have a sideband channel, there's no room in the
344 * protocol to say anything, so those clients are just out of
345 * luck.
347 if (!ret && use_sideband) {
348 static const char buf[] = "0005\1";
349 write_or_die(1, buf, 5);
353 if (finish_command(&pack_objects)) {
354 error("git upload-pack: git-pack-objects died with error.");
355 goto fail;
358 /* flush the data */
359 if (0 <= buffered) {
360 data[0] = buffered;
361 send_client_data(1, data, 1);
362 fprintf(stderr, "flushed.\n");
364 if (use_sideband)
365 packet_flush(1);
366 return;
368 fail:
369 send_client_data(3, abort_msg, sizeof(abort_msg));
370 die("git upload-pack: %s", abort_msg);
373 static int got_oid(const char *hex, struct object_id *oid,
374 struct object_array *have_obj)
376 struct object *o;
377 int we_knew_they_have = 0;
379 if (get_oid_hex(hex, oid))
380 die("git upload-pack: expected SHA1 object, got '%s'", hex);
381 if (!has_object_file(oid))
382 return -1;
384 o = parse_object(the_repository, oid);
385 if (!o)
386 die("oops (%s)", oid_to_hex(oid));
387 if (o->type == OBJ_COMMIT) {
388 struct commit_list *parents;
389 struct commit *commit = (struct commit *)o;
390 if (o->flags & THEY_HAVE)
391 we_knew_they_have = 1;
392 else
393 o->flags |= THEY_HAVE;
394 if (!oldest_have || (commit->date < oldest_have))
395 oldest_have = commit->date;
396 for (parents = commit->parents;
397 parents;
398 parents = parents->next)
399 parents->item->object.flags |= THEY_HAVE;
401 if (!we_knew_they_have) {
402 add_object_array(o, NULL, have_obj);
403 return 1;
405 return 0;
408 static int ok_to_give_up(const struct object_array *have_obj,
409 struct object_array *want_obj)
411 uint32_t min_generation = GENERATION_NUMBER_ZERO;
413 if (!have_obj->nr)
414 return 0;
416 return can_all_from_reach_with_flag(want_obj, THEY_HAVE,
417 COMMON_KNOWN, oldest_have,
418 min_generation);
421 static int get_common_commits(struct upload_pack_data *data,
422 struct packet_reader *reader)
424 struct object_id oid;
425 char last_hex[GIT_MAX_HEXSZ + 1];
426 int got_common = 0;
427 int got_other = 0;
428 int sent_ready = 0;
430 save_commit_buffer = 0;
432 for (;;) {
433 const char *arg;
435 reset_timeout();
437 if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
438 if (multi_ack == 2
439 && got_common
440 && !got_other
441 && ok_to_give_up(&data->have_obj, &data->want_obj)) {
442 sent_ready = 1;
443 packet_write_fmt(1, "ACK %s ready\n", last_hex);
445 if (data->have_obj.nr == 0 || multi_ack)
446 packet_write_fmt(1, "NAK\n");
448 if (no_done && sent_ready) {
449 packet_write_fmt(1, "ACK %s\n", last_hex);
450 return 0;
452 if (stateless_rpc)
453 exit(0);
454 got_common = 0;
455 got_other = 0;
456 continue;
458 if (skip_prefix(reader->line, "have ", &arg)) {
459 switch (got_oid(arg, &oid, &data->have_obj)) {
460 case -1: /* they have what we do not */
461 got_other = 1;
462 if (multi_ack
463 && ok_to_give_up(&data->have_obj, &data->want_obj)) {
464 const char *hex = oid_to_hex(&oid);
465 if (multi_ack == 2) {
466 sent_ready = 1;
467 packet_write_fmt(1, "ACK %s ready\n", hex);
468 } else
469 packet_write_fmt(1, "ACK %s continue\n", hex);
471 break;
472 default:
473 got_common = 1;
474 oid_to_hex_r(last_hex, &oid);
475 if (multi_ack == 2)
476 packet_write_fmt(1, "ACK %s common\n", last_hex);
477 else if (multi_ack)
478 packet_write_fmt(1, "ACK %s continue\n", last_hex);
479 else if (data->have_obj.nr == 1)
480 packet_write_fmt(1, "ACK %s\n", last_hex);
481 break;
483 continue;
485 if (!strcmp(reader->line, "done")) {
486 if (data->have_obj.nr > 0) {
487 if (multi_ack)
488 packet_write_fmt(1, "ACK %s\n", last_hex);
489 return 0;
491 packet_write_fmt(1, "NAK\n");
492 return -1;
494 die("git upload-pack: expected SHA1 list, got '%s'", reader->line);
498 static int is_our_ref(struct object *o)
500 int allow_hidden_ref = (allow_unadvertised_object_request &
501 (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
502 return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
506 * on successful case, it's up to the caller to close cmd->out
508 static int do_reachable_revlist(struct child_process *cmd,
509 struct object_array *src,
510 struct object_array *reachable)
512 static const char *argv[] = {
513 "rev-list", "--stdin", NULL,
515 struct object *o;
516 char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
517 int i;
518 const unsigned hexsz = the_hash_algo->hexsz;
520 cmd->argv = argv;
521 cmd->git_cmd = 1;
522 cmd->no_stderr = 1;
523 cmd->in = -1;
524 cmd->out = -1;
527 * If the next rev-list --stdin encounters an unknown commit,
528 * it terminates, which will cause SIGPIPE in the write loop
529 * below.
531 sigchain_push(SIGPIPE, SIG_IGN);
533 if (start_command(cmd))
534 goto error;
536 namebuf[0] = '^';
537 namebuf[hexsz + 1] = '\n';
538 for (i = get_max_object_index(); 0 < i; ) {
539 o = get_indexed_object(--i);
540 if (!o)
541 continue;
542 if (reachable && o->type == OBJ_COMMIT)
543 o->flags &= ~TMP_MARK;
544 if (!is_our_ref(o))
545 continue;
546 memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
547 if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
548 goto error;
550 namebuf[hexsz] = '\n';
551 for (i = 0; i < src->nr; i++) {
552 o = src->objects[i].item;
553 if (is_our_ref(o)) {
554 if (reachable)
555 add_object_array(o, NULL, reachable);
556 continue;
558 if (reachable && o->type == OBJ_COMMIT)
559 o->flags |= TMP_MARK;
560 memcpy(namebuf, oid_to_hex(&o->oid), hexsz);
561 if (write_in_full(cmd->in, namebuf, hexsz + 1) < 0)
562 goto error;
564 close(cmd->in);
565 cmd->in = -1;
566 sigchain_pop(SIGPIPE);
568 return 0;
570 error:
571 sigchain_pop(SIGPIPE);
573 if (cmd->in >= 0)
574 close(cmd->in);
575 if (cmd->out >= 0)
576 close(cmd->out);
577 return -1;
580 static int get_reachable_list(struct object_array *src,
581 struct object_array *reachable)
583 struct child_process cmd = CHILD_PROCESS_INIT;
584 int i;
585 struct object *o;
586 char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
587 const unsigned hexsz = the_hash_algo->hexsz;
589 if (do_reachable_revlist(&cmd, src, reachable) < 0)
590 return -1;
592 while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
593 struct object_id oid;
594 const char *p;
596 if (parse_oid_hex(namebuf, &oid, &p) || *p != '\n')
597 break;
599 o = lookup_object(the_repository, &oid);
600 if (o && o->type == OBJ_COMMIT) {
601 o->flags &= ~TMP_MARK;
604 for (i = get_max_object_index(); 0 < i; i--) {
605 o = get_indexed_object(i - 1);
606 if (o && o->type == OBJ_COMMIT &&
607 (o->flags & TMP_MARK)) {
608 add_object_array(o, NULL, reachable);
609 o->flags &= ~TMP_MARK;
612 close(cmd.out);
614 if (finish_command(&cmd))
615 return -1;
617 return 0;
620 static int has_unreachable(struct object_array *src)
622 struct child_process cmd = CHILD_PROCESS_INIT;
623 char buf[1];
624 int i;
626 if (do_reachable_revlist(&cmd, src, NULL) < 0)
627 return 1;
630 * The commits out of the rev-list are not ancestors of
631 * our ref.
633 i = read_in_full(cmd.out, buf, 1);
634 if (i)
635 goto error;
636 close(cmd.out);
637 cmd.out = -1;
640 * rev-list may have died by encountering a bad commit
641 * in the history, in which case we do want to bail out
642 * even when it showed no commit.
644 if (finish_command(&cmd))
645 goto error;
647 /* All the non-tip ones are ancestors of what we advertised */
648 return 0;
650 error:
651 sigchain_pop(SIGPIPE);
652 if (cmd.out >= 0)
653 close(cmd.out);
654 return 1;
657 static void check_non_tip(struct object_array *want_obj,
658 struct packet_writer *writer)
660 int i;
663 * In the normal in-process case without
664 * uploadpack.allowReachableSHA1InWant,
665 * non-tip requests can never happen.
667 if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
668 goto error;
669 if (!has_unreachable(want_obj))
670 /* All the non-tip ones are ancestors of what we advertised */
671 return;
673 error:
674 /* Pick one of them (we know there at least is one) */
675 for (i = 0; i < want_obj->nr; i++) {
676 struct object *o = want_obj->objects[i].item;
677 if (!is_our_ref(o)) {
678 packet_writer_error(writer,
679 "upload-pack: not our ref %s",
680 oid_to_hex(&o->oid));
681 die("git upload-pack: not our ref %s",
682 oid_to_hex(&o->oid));
687 static void send_shallow(struct packet_writer *writer,
688 struct commit_list *result)
690 while (result) {
691 struct object *object = &result->item->object;
692 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
693 packet_writer_write(writer, "shallow %s",
694 oid_to_hex(&object->oid));
695 register_shallow(the_repository, &object->oid);
696 shallow_nr++;
698 result = result->next;
702 static void send_unshallow(struct packet_writer *writer,
703 const struct object_array *shallows,
704 struct object_array *want_obj)
706 int i;
708 for (i = 0; i < shallows->nr; i++) {
709 struct object *object = shallows->objects[i].item;
710 if (object->flags & NOT_SHALLOW) {
711 struct commit_list *parents;
712 packet_writer_write(writer, "unshallow %s",
713 oid_to_hex(&object->oid));
714 object->flags &= ~CLIENT_SHALLOW;
716 * We want to _register_ "object" as shallow, but we
717 * also need to traverse object's parents to deepen a
718 * shallow clone. Unregister it for now so we can
719 * parse and add the parents to the want list, then
720 * re-register it.
722 unregister_shallow(&object->oid);
723 object->parsed = 0;
724 parse_commit_or_die((struct commit *)object);
725 parents = ((struct commit *)object)->parents;
726 while (parents) {
727 add_object_array(&parents->item->object,
728 NULL, want_obj);
729 parents = parents->next;
731 add_object_array(object, NULL, &extra_edge_obj);
733 /* make sure commit traversal conforms to client */
734 register_shallow(the_repository, &object->oid);
738 static int check_ref(const char *refname_full, const struct object_id *oid,
739 int flag, void *cb_data);
740 static void deepen(struct packet_writer *writer, int depth, int deepen_relative,
741 struct object_array *shallows, struct object_array *want_obj)
743 if (depth == INFINITE_DEPTH && !is_repository_shallow(the_repository)) {
744 int i;
746 for (i = 0; i < shallows->nr; i++) {
747 struct object *object = shallows->objects[i].item;
748 object->flags |= NOT_SHALLOW;
750 } else if (deepen_relative) {
751 struct object_array reachable_shallows = OBJECT_ARRAY_INIT;
752 struct commit_list *result;
755 * Checking for reachable shallows requires that our refs be
756 * marked with OUR_REF.
758 head_ref_namespaced(check_ref, NULL);
759 for_each_namespaced_ref(check_ref, NULL);
761 get_reachable_list(shallows, &reachable_shallows);
762 result = get_shallow_commits(&reachable_shallows,
763 depth + 1,
764 SHALLOW, NOT_SHALLOW);
765 send_shallow(writer, result);
766 free_commit_list(result);
767 object_array_clear(&reachable_shallows);
768 } else {
769 struct commit_list *result;
771 result = get_shallow_commits(want_obj, depth,
772 SHALLOW, NOT_SHALLOW);
773 send_shallow(writer, result);
774 free_commit_list(result);
777 send_unshallow(writer, shallows, want_obj);
780 static void deepen_by_rev_list(struct packet_writer *writer, int ac,
781 const char **av,
782 struct object_array *shallows,
783 struct object_array *want_obj)
785 struct commit_list *result;
787 disable_commit_graph(the_repository);
788 result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
789 send_shallow(writer, result);
790 free_commit_list(result);
791 send_unshallow(writer, shallows, want_obj);
794 /* Returns 1 if a shallow list is sent or 0 otherwise */
795 static int send_shallow_list(struct packet_writer *writer,
796 int depth, int deepen_rev_list,
797 timestamp_t deepen_since,
798 struct string_list *deepen_not,
799 int deepen_relative,
800 struct object_array *shallows,
801 struct object_array *want_obj)
803 int ret = 0;
805 if (depth > 0 && deepen_rev_list)
806 die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together");
807 if (depth > 0) {
808 deepen(writer, depth, deepen_relative, shallows, want_obj);
809 ret = 1;
810 } else if (deepen_rev_list) {
811 struct argv_array av = ARGV_ARRAY_INIT;
812 int i;
814 argv_array_push(&av, "rev-list");
815 if (deepen_since)
816 argv_array_pushf(&av, "--max-age=%"PRItime, deepen_since);
817 if (deepen_not->nr) {
818 argv_array_push(&av, "--not");
819 for (i = 0; i < deepen_not->nr; i++) {
820 struct string_list_item *s = deepen_not->items + i;
821 argv_array_push(&av, s->string);
823 argv_array_push(&av, "--not");
825 for (i = 0; i < want_obj->nr; i++) {
826 struct object *o = want_obj->objects[i].item;
827 argv_array_push(&av, oid_to_hex(&o->oid));
829 deepen_by_rev_list(writer, av.argc, av.argv, shallows, want_obj);
830 argv_array_clear(&av);
831 ret = 1;
832 } else {
833 if (shallows->nr > 0) {
834 int i;
835 for (i = 0; i < shallows->nr; i++)
836 register_shallow(the_repository,
837 &shallows->objects[i].item->oid);
841 shallow_nr += shallows->nr;
842 return ret;
845 static int process_shallow(const char *line, struct object_array *shallows)
847 const char *arg;
848 if (skip_prefix(line, "shallow ", &arg)) {
849 struct object_id oid;
850 struct object *object;
851 if (get_oid_hex(arg, &oid))
852 die("invalid shallow line: %s", line);
853 object = parse_object(the_repository, &oid);
854 if (!object)
855 return 1;
856 if (object->type != OBJ_COMMIT)
857 die("invalid shallow object %s", oid_to_hex(&oid));
858 if (!(object->flags & CLIENT_SHALLOW)) {
859 object->flags |= CLIENT_SHALLOW;
860 add_object_array(object, NULL, shallows);
862 return 1;
865 return 0;
868 static int process_deepen(const char *line, int *depth)
870 const char *arg;
871 if (skip_prefix(line, "deepen ", &arg)) {
872 char *end = NULL;
873 *depth = (int)strtol(arg, &end, 0);
874 if (!end || *end || *depth <= 0)
875 die("Invalid deepen: %s", line);
876 return 1;
879 return 0;
882 static int process_deepen_since(const char *line, timestamp_t *deepen_since, int *deepen_rev_list)
884 const char *arg;
885 if (skip_prefix(line, "deepen-since ", &arg)) {
886 char *end = NULL;
887 *deepen_since = parse_timestamp(arg, &end, 0);
888 if (!end || *end || !deepen_since ||
889 /* revisions.c's max_age -1 is special */
890 *deepen_since == -1)
891 die("Invalid deepen-since: %s", line);
892 *deepen_rev_list = 1;
893 return 1;
895 return 0;
898 static int process_deepen_not(const char *line, struct string_list *deepen_not, int *deepen_rev_list)
900 const char *arg;
901 if (skip_prefix(line, "deepen-not ", &arg)) {
902 char *ref = NULL;
903 struct object_id oid;
904 if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
905 die("git upload-pack: ambiguous deepen-not: %s", line);
906 string_list_append(deepen_not, ref);
907 free(ref);
908 *deepen_rev_list = 1;
909 return 1;
911 return 0;
914 static void receive_needs(struct upload_pack_data *data,
915 struct packet_reader *reader)
917 struct object_array shallows = OBJECT_ARRAY_INIT;
918 struct string_list deepen_not = STRING_LIST_INIT_DUP;
919 int depth = 0;
920 int has_non_tip = 0;
921 timestamp_t deepen_since = 0;
922 int deepen_rev_list = 0;
923 int deepen_relative = 0;
925 shallow_nr = 0;
926 for (;;) {
927 struct object *o;
928 const char *features;
929 struct object_id oid_buf;
930 const char *arg;
932 reset_timeout();
933 if (packet_reader_read(reader) != PACKET_READ_NORMAL)
934 break;
936 if (process_shallow(reader->line, &shallows))
937 continue;
938 if (process_deepen(reader->line, &depth))
939 continue;
940 if (process_deepen_since(reader->line, &deepen_since, &deepen_rev_list))
941 continue;
942 if (process_deepen_not(reader->line, &deepen_not, &deepen_rev_list))
943 continue;
945 if (skip_prefix(reader->line, "filter ", &arg)) {
946 if (!filter_capability_requested)
947 die("git upload-pack: filtering capability not negotiated");
948 list_objects_filter_die_if_populated(&data->filter_options);
949 parse_list_objects_filter(&data->filter_options, arg);
950 continue;
953 if (!skip_prefix(reader->line, "want ", &arg) ||
954 parse_oid_hex(arg, &oid_buf, &features))
955 die("git upload-pack: protocol error, "
956 "expected to get object ID, not '%s'", reader->line);
958 if (parse_feature_request(features, "deepen-relative"))
959 deepen_relative = 1;
960 if (parse_feature_request(features, "multi_ack_detailed"))
961 multi_ack = 2;
962 else if (parse_feature_request(features, "multi_ack"))
963 multi_ack = 1;
964 if (parse_feature_request(features, "no-done"))
965 no_done = 1;
966 if (parse_feature_request(features, "thin-pack"))
967 use_thin_pack = 1;
968 if (parse_feature_request(features, "ofs-delta"))
969 use_ofs_delta = 1;
970 if (parse_feature_request(features, "side-band-64k"))
971 use_sideband = LARGE_PACKET_MAX;
972 else if (parse_feature_request(features, "side-band"))
973 use_sideband = DEFAULT_PACKET_MAX;
974 if (parse_feature_request(features, "no-progress"))
975 no_progress = 1;
976 if (parse_feature_request(features, "include-tag"))
977 use_include_tag = 1;
978 if (allow_filter && parse_feature_request(features, "filter"))
979 filter_capability_requested = 1;
981 o = parse_object(the_repository, &oid_buf);
982 if (!o) {
983 packet_writer_error(&data->writer,
984 "upload-pack: not our ref %s",
985 oid_to_hex(&oid_buf));
986 die("git upload-pack: not our ref %s",
987 oid_to_hex(&oid_buf));
989 if (!(o->flags & WANTED)) {
990 o->flags |= WANTED;
991 if (!((allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
992 || is_our_ref(o)))
993 has_non_tip = 1;
994 add_object_array(o, NULL, &data->want_obj);
999 * We have sent all our refs already, and the other end
1000 * should have chosen out of them. When we are operating
1001 * in the stateless RPC mode, however, their choice may
1002 * have been based on the set of older refs advertised
1003 * by another process that handled the initial request.
1005 if (has_non_tip)
1006 check_non_tip(&data->want_obj, &data->writer);
1008 if (!use_sideband && daemon_mode)
1009 no_progress = 1;
1011 if (depth == 0 && !deepen_rev_list && shallows.nr == 0)
1012 return;
1014 if (send_shallow_list(&data->writer, depth, deepen_rev_list, deepen_since,
1015 &deepen_not, deepen_relative, &shallows,
1016 &data->want_obj))
1017 packet_flush(1);
1018 object_array_clear(&shallows);
1021 /* return non-zero if the ref is hidden, otherwise 0 */
1022 static int mark_our_ref(const char *refname, const char *refname_full,
1023 const struct object_id *oid)
1025 struct object *o = lookup_unknown_object(oid);
1027 if (ref_is_hidden(refname, refname_full)) {
1028 o->flags |= HIDDEN_REF;
1029 return 1;
1031 o->flags |= OUR_REF;
1032 return 0;
1035 static int check_ref(const char *refname_full, const struct object_id *oid,
1036 int flag, void *cb_data)
1038 const char *refname = strip_namespace(refname_full);
1040 mark_our_ref(refname, refname_full, oid);
1041 return 0;
1044 static void format_symref_info(struct strbuf *buf, struct string_list *symref)
1046 struct string_list_item *item;
1048 if (!symref->nr)
1049 return;
1050 for_each_string_list_item(item, symref)
1051 strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util);
1054 static int send_ref(const char *refname, const struct object_id *oid,
1055 int flag, void *cb_data)
1057 static const char *capabilities = "multi_ack thin-pack side-band"
1058 " side-band-64k ofs-delta shallow deepen-since deepen-not"
1059 " deepen-relative no-progress include-tag multi_ack_detailed";
1060 const char *refname_nons = strip_namespace(refname);
1061 struct object_id peeled;
1062 struct upload_pack_data *data = cb_data;
1064 if (mark_our_ref(refname_nons, refname, oid))
1065 return 0;
1067 if (capabilities) {
1068 struct strbuf symref_info = STRBUF_INIT;
1070 format_symref_info(&symref_info, &data->symref);
1071 packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
1072 oid_to_hex(oid), refname_nons,
1073 0, capabilities,
1074 (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
1075 " allow-tip-sha1-in-want" : "",
1076 (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
1077 " allow-reachable-sha1-in-want" : "",
1078 stateless_rpc ? " no-done" : "",
1079 symref_info.buf,
1080 allow_filter ? " filter" : "",
1081 git_user_agent_sanitized());
1082 strbuf_release(&symref_info);
1083 } else {
1084 packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
1086 capabilities = NULL;
1087 if (!peel_ref(refname, &peeled))
1088 packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
1089 return 0;
1092 static int find_symref(const char *refname, const struct object_id *oid,
1093 int flag, void *cb_data)
1095 const char *symref_target;
1096 struct string_list_item *item;
1098 if ((flag & REF_ISSYMREF) == 0)
1099 return 0;
1100 symref_target = resolve_ref_unsafe(refname, 0, NULL, &flag);
1101 if (!symref_target || (flag & REF_ISSYMREF) == 0)
1102 die("'%s' is a symref but it is not?", refname);
1103 item = string_list_append(cb_data, strip_namespace(refname));
1104 item->util = xstrdup(strip_namespace(symref_target));
1105 return 0;
1108 static int upload_pack_config(const char *var, const char *value, void *unused)
1110 if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
1111 if (git_config_bool(var, value))
1112 allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
1113 else
1114 allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
1115 } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
1116 if (git_config_bool(var, value))
1117 allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1118 else
1119 allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
1120 } else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
1121 if (git_config_bool(var, value))
1122 allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
1123 else
1124 allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
1125 } else if (!strcmp("uploadpack.keepalive", var)) {
1126 keepalive = git_config_int(var, value);
1127 if (!keepalive)
1128 keepalive = -1;
1129 } else if (!strcmp("uploadpack.allowfilter", var)) {
1130 allow_filter = git_config_bool(var, value);
1131 } else if (!strcmp("uploadpack.allowrefinwant", var)) {
1132 allow_ref_in_want = git_config_bool(var, value);
1133 } else if (!strcmp("uploadpack.allowsidebandall", var)) {
1134 allow_sideband_all = git_config_bool(var, value);
1135 } else if (!strcmp("core.precomposeunicode", var)) {
1136 precomposed_unicode = git_config_bool(var, value);
1139 if (current_config_scope() != CONFIG_SCOPE_LOCAL &&
1140 current_config_scope() != CONFIG_SCOPE_WORKTREE) {
1141 if (!strcmp("uploadpack.packobjectshook", var))
1142 return git_config_string(&pack_objects_hook, var, value);
1145 return parse_hide_refs_config(var, value, "uploadpack");
1148 void upload_pack(struct upload_pack_options *options)
1150 struct packet_reader reader;
1151 struct upload_pack_data data;
1153 stateless_rpc = options->stateless_rpc;
1154 timeout = options->timeout;
1155 daemon_mode = options->daemon_mode;
1157 git_config(upload_pack_config, NULL);
1159 upload_pack_data_init(&data);
1161 head_ref_namespaced(find_symref, &data.symref);
1163 if (options->advertise_refs || !stateless_rpc) {
1164 reset_timeout();
1165 head_ref_namespaced(send_ref, &data);
1166 for_each_namespaced_ref(send_ref, &data);
1167 advertise_shallow_grafts(1);
1168 packet_flush(1);
1169 } else {
1170 head_ref_namespaced(check_ref, NULL);
1171 for_each_namespaced_ref(check_ref, NULL);
1174 if (!options->advertise_refs) {
1175 packet_reader_init(&reader, 0, NULL, 0,
1176 PACKET_READ_CHOMP_NEWLINE |
1177 PACKET_READ_DIE_ON_ERR_PACKET);
1179 receive_needs(&data, &reader);
1180 if (data.want_obj.nr) {
1181 get_common_commits(&data, &reader);
1182 create_pack_file(&data.have_obj,
1183 &data.want_obj,
1184 &data.filter_options);
1188 upload_pack_data_clear(&data);
1191 static int parse_want(struct packet_writer *writer, const char *line,
1192 struct object_array *want_obj)
1194 const char *arg;
1195 if (skip_prefix(line, "want ", &arg)) {
1196 struct object_id oid;
1197 struct object *o;
1199 if (get_oid_hex(arg, &oid))
1200 die("git upload-pack: protocol error, "
1201 "expected to get oid, not '%s'", line);
1203 o = parse_object(the_repository, &oid);
1204 if (!o) {
1205 packet_writer_error(writer,
1206 "upload-pack: not our ref %s",
1207 oid_to_hex(&oid));
1208 die("git upload-pack: not our ref %s",
1209 oid_to_hex(&oid));
1212 if (!(o->flags & WANTED)) {
1213 o->flags |= WANTED;
1214 add_object_array(o, NULL, want_obj);
1217 return 1;
1220 return 0;
1223 static int parse_want_ref(struct packet_writer *writer, const char *line,
1224 struct string_list *wanted_refs,
1225 struct object_array *want_obj)
1227 const char *arg;
1228 if (skip_prefix(line, "want-ref ", &arg)) {
1229 struct object_id oid;
1230 struct string_list_item *item;
1231 struct object *o;
1233 if (read_ref(arg, &oid)) {
1234 packet_writer_error(writer, "unknown ref %s", arg);
1235 die("unknown ref %s", arg);
1238 item = string_list_append(wanted_refs, arg);
1239 item->util = oiddup(&oid);
1241 o = parse_object_or_die(&oid, arg);
1242 if (!(o->flags & WANTED)) {
1243 o->flags |= WANTED;
1244 add_object_array(o, NULL, want_obj);
1247 return 1;
1250 return 0;
1253 static int parse_have(const char *line, struct oid_array *haves)
1255 const char *arg;
1256 if (skip_prefix(line, "have ", &arg)) {
1257 struct object_id oid;
1259 if (get_oid_hex(arg, &oid))
1260 die("git upload-pack: expected SHA1 object, got '%s'", arg);
1261 oid_array_append(haves, &oid);
1262 return 1;
1265 return 0;
1268 static void process_args(struct packet_reader *request,
1269 struct upload_pack_data *data)
1271 while (packet_reader_read(request) == PACKET_READ_NORMAL) {
1272 const char *arg = request->line;
1273 const char *p;
1275 /* process want */
1276 if (parse_want(&data->writer, arg, &data->want_obj))
1277 continue;
1278 if (allow_ref_in_want &&
1279 parse_want_ref(&data->writer, arg, &data->wanted_refs,
1280 &data->want_obj))
1281 continue;
1282 /* process have line */
1283 if (parse_have(arg, &data->haves))
1284 continue;
1286 /* process args like thin-pack */
1287 if (!strcmp(arg, "thin-pack")) {
1288 use_thin_pack = 1;
1289 continue;
1291 if (!strcmp(arg, "ofs-delta")) {
1292 use_ofs_delta = 1;
1293 continue;
1295 if (!strcmp(arg, "no-progress")) {
1296 no_progress = 1;
1297 continue;
1299 if (!strcmp(arg, "include-tag")) {
1300 use_include_tag = 1;
1301 continue;
1303 if (!strcmp(arg, "done")) {
1304 data->done = 1;
1305 continue;
1308 /* Shallow related arguments */
1309 if (process_shallow(arg, &data->shallows))
1310 continue;
1311 if (process_deepen(arg, &data->depth))
1312 continue;
1313 if (process_deepen_since(arg, &data->deepen_since,
1314 &data->deepen_rev_list))
1315 continue;
1316 if (process_deepen_not(arg, &data->deepen_not,
1317 &data->deepen_rev_list))
1318 continue;
1319 if (!strcmp(arg, "deepen-relative")) {
1320 data->deepen_relative = 1;
1321 continue;
1324 if (allow_filter && skip_prefix(arg, "filter ", &p)) {
1325 list_objects_filter_die_if_populated(&data->filter_options);
1326 parse_list_objects_filter(&data->filter_options, p);
1327 continue;
1330 if ((git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
1331 allow_sideband_all) &&
1332 !strcmp(arg, "sideband-all")) {
1333 data->writer.use_sideband = 1;
1334 continue;
1337 /* ignore unknown lines maybe? */
1338 die("unexpected line: '%s'", arg);
1341 if (request->status != PACKET_READ_FLUSH)
1342 die(_("expected flush after fetch arguments"));
1345 static int process_haves(struct oid_array *haves, struct oid_array *common,
1346 struct object_array *have_obj)
1348 int i;
1350 /* Process haves */
1351 for (i = 0; i < haves->nr; i++) {
1352 const struct object_id *oid = &haves->oid[i];
1353 struct object *o;
1354 int we_knew_they_have = 0;
1356 if (!has_object_file(oid))
1357 continue;
1359 oid_array_append(common, oid);
1361 o = parse_object(the_repository, oid);
1362 if (!o)
1363 die("oops (%s)", oid_to_hex(oid));
1364 if (o->type == OBJ_COMMIT) {
1365 struct commit_list *parents;
1366 struct commit *commit = (struct commit *)o;
1367 if (o->flags & THEY_HAVE)
1368 we_knew_they_have = 1;
1369 else
1370 o->flags |= THEY_HAVE;
1371 if (!oldest_have || (commit->date < oldest_have))
1372 oldest_have = commit->date;
1373 for (parents = commit->parents;
1374 parents;
1375 parents = parents->next)
1376 parents->item->object.flags |= THEY_HAVE;
1378 if (!we_knew_they_have)
1379 add_object_array(o, NULL, have_obj);
1382 return 0;
1385 static int send_acks(struct packet_writer *writer, struct oid_array *acks,
1386 const struct object_array *have_obj,
1387 struct object_array *want_obj)
1389 int i;
1391 packet_writer_write(writer, "acknowledgments\n");
1393 /* Send Acks */
1394 if (!acks->nr)
1395 packet_writer_write(writer, "NAK\n");
1397 for (i = 0; i < acks->nr; i++) {
1398 packet_writer_write(writer, "ACK %s\n",
1399 oid_to_hex(&acks->oid[i]));
1402 if (ok_to_give_up(have_obj, want_obj)) {
1403 /* Send Ready */
1404 packet_writer_write(writer, "ready\n");
1405 return 1;
1408 return 0;
1411 static int process_haves_and_send_acks(struct upload_pack_data *data)
1413 struct oid_array common = OID_ARRAY_INIT;
1414 int ret = 0;
1416 process_haves(&data->haves, &common, &data->have_obj);
1417 if (data->done) {
1418 ret = 1;
1419 } else if (send_acks(&data->writer, &common,
1420 &data->have_obj, &data->want_obj)) {
1421 packet_writer_delim(&data->writer);
1422 ret = 1;
1423 } else {
1424 /* Add Flush */
1425 packet_writer_flush(&data->writer);
1426 ret = 0;
1429 oid_array_clear(&data->haves);
1430 oid_array_clear(&common);
1431 return ret;
1434 static void send_wanted_ref_info(struct upload_pack_data *data)
1436 const struct string_list_item *item;
1438 if (!data->wanted_refs.nr)
1439 return;
1441 packet_writer_write(&data->writer, "wanted-refs\n");
1443 for_each_string_list_item(item, &data->wanted_refs) {
1444 packet_writer_write(&data->writer, "%s %s\n",
1445 oid_to_hex(item->util),
1446 item->string);
1449 packet_writer_delim(&data->writer);
1452 static void send_shallow_info(struct upload_pack_data *data)
1454 /* No shallow info needs to be sent */
1455 if (!data->depth && !data->deepen_rev_list && !data->shallows.nr &&
1456 !is_repository_shallow(the_repository))
1457 return;
1459 packet_writer_write(&data->writer, "shallow-info\n");
1461 if (!send_shallow_list(&data->writer, data->depth,
1462 data->deepen_rev_list,
1463 data->deepen_since, &data->deepen_not,
1464 data->deepen_relative,
1465 &data->shallows, &data->want_obj) &&
1466 is_repository_shallow(the_repository))
1467 deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative,
1468 &data->shallows, &data->want_obj);
1470 packet_delim(1);
1473 enum fetch_state {
1474 FETCH_PROCESS_ARGS = 0,
1475 FETCH_SEND_ACKS,
1476 FETCH_SEND_PACK,
1477 FETCH_DONE,
1480 int upload_pack_v2(struct repository *r, struct argv_array *keys,
1481 struct packet_reader *request)
1483 enum fetch_state state = FETCH_PROCESS_ARGS;
1484 struct upload_pack_data data;
1486 clear_object_flags(ALL_FLAGS);
1488 git_config(upload_pack_config, NULL);
1490 upload_pack_data_init(&data);
1491 use_sideband = LARGE_PACKET_MAX;
1493 while (state != FETCH_DONE) {
1494 switch (state) {
1495 case FETCH_PROCESS_ARGS:
1496 process_args(request, &data);
1498 if (!data.want_obj.nr) {
1500 * Request didn't contain any 'want' lines,
1501 * guess they didn't want anything.
1503 state = FETCH_DONE;
1504 } else if (data.haves.nr) {
1506 * Request had 'have' lines, so lets ACK them.
1508 state = FETCH_SEND_ACKS;
1509 } else {
1511 * Request had 'want's but no 'have's so we can
1512 * immedietly go to construct and send a pack.
1514 state = FETCH_SEND_PACK;
1516 break;
1517 case FETCH_SEND_ACKS:
1518 if (process_haves_and_send_acks(&data))
1519 state = FETCH_SEND_PACK;
1520 else
1521 state = FETCH_DONE;
1522 break;
1523 case FETCH_SEND_PACK:
1524 send_wanted_ref_info(&data);
1525 send_shallow_info(&data);
1527 packet_writer_write(&data.writer, "packfile\n");
1528 create_pack_file(&data.have_obj,
1529 &data.want_obj,
1530 &data.filter_options);
1531 state = FETCH_DONE;
1532 break;
1533 case FETCH_DONE:
1534 continue;
1538 upload_pack_data_clear(&data);
1539 return 0;
1542 int upload_pack_advertise(struct repository *r,
1543 struct strbuf *value)
1545 if (value) {
1546 int allow_filter_value;
1547 int allow_ref_in_want;
1548 int allow_sideband_all_value;
1550 strbuf_addstr(value, "shallow");
1552 if (!repo_config_get_bool(the_repository,
1553 "uploadpack.allowfilter",
1554 &allow_filter_value) &&
1555 allow_filter_value)
1556 strbuf_addstr(value, " filter");
1558 if (!repo_config_get_bool(the_repository,
1559 "uploadpack.allowrefinwant",
1560 &allow_ref_in_want) &&
1561 allow_ref_in_want)
1562 strbuf_addstr(value, " ref-in-want");
1564 if (git_env_bool("GIT_TEST_SIDEBAND_ALL", 0) ||
1565 (!repo_config_get_bool(the_repository,
1566 "uploadpack.allowsidebandall",
1567 &allow_sideband_all_value) &&
1568 allow_sideband_all_value))
1569 strbuf_addstr(value, " sideband-all");
1572 return 1;