12 #include "list-objects.h"
13 #include "list-objects-filter.h"
14 #include "list-objects-filter-options.h"
15 #include "run-command.h"
19 #include "string-list.h"
20 #include "parse-options.h"
21 #include "argv-array.h"
22 #include "prio-queue.h"
25 static const char * const upload_pack_usage[] = {
26 N_("git upload-pack [<options>] <dir>"),
30 /* Remember to update object flag allocation in object.h */
31 #define THEY_HAVE (1u << 11)
32 #define OUR_REF (1u << 12)
33 #define WANTED (1u << 13)
34 #define COMMON_KNOWN (1u << 14)
35 #define REACHABLE (1u << 15)
37 #define SHALLOW (1u << 16)
38 #define NOT_SHALLOW (1u << 17)
39 #define CLIENT_SHALLOW (1u << 18)
40 #define HIDDEN_REF (1u << 19)
42 static timestamp_t oldest_have;
44 static int deepen_relative;
47 static int use_thin_pack, use_ofs_delta, use_include_tag;
48 static int no_progress, daemon_mode;
49 /* Allow specifying sha1 if it is a ref tip. */
50 #define ALLOW_TIP_SHA1 01
51 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
52 #define ALLOW_REACHABLE_SHA1 02
53 /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
54 #define ALLOW_ANY_SHA1 07
55 static unsigned int allow_unadvertised_object_request;
56 static int shallow_nr;
57 static struct object_array have_obj;
58 static struct object_array want_obj;
59 static struct object_array extra_edge_obj;
60 static unsigned int timeout;
61 static int keepalive = 5;
63 * otherwise maximum packet size (up to 65520 bytes).
65 static int use_sideband;
66 static int advertise_refs;
67 static int stateless_rpc;
68 static const char *pack_objects_hook;
70 static int filter_capability_requested;
71 static int filter_advertise;
72 static struct list_objects_filter_options filter_options;
74 static void reset_timeout(void)
79 static void send_client_data(int fd, const char *data, ssize_t sz)
82 send_sideband(1, fd, data, sz, use_sideband);
89 /* XXX: are we happy to lose stuff here? */
93 write_or_die(fd, data, sz);
96 static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
99 if (graft->nr_parent == -1)
100 fprintf(fp, "--shallow %s\n", oid_to_hex(&graft->oid));
104 static void create_pack_file(void)
106 struct child_process pack_objects = CHILD_PROCESS_INIT;
107 char data[8193], progress[128];
108 char abort_msg[] = "aborting due to possible repository "
109 "corruption on the remote side.";
115 if (!pack_objects_hook)
116 pack_objects.git_cmd = 1;
118 argv_array_push(&pack_objects.args, pack_objects_hook);
119 argv_array_push(&pack_objects.args, "git");
120 pack_objects.use_shell = 1;
124 argv_array_push(&pack_objects.args, "--shallow-file");
125 argv_array_push(&pack_objects.args, "");
127 argv_array_push(&pack_objects.args, "pack-objects");
128 argv_array_push(&pack_objects.args, "--revs");
130 argv_array_push(&pack_objects.args, "--thin");
132 argv_array_push(&pack_objects.args, "--stdout");
134 argv_array_push(&pack_objects.args, "--shallow");
136 argv_array_push(&pack_objects.args, "--progress");
138 argv_array_push(&pack_objects.args, "--delta-base-offset");
140 argv_array_push(&pack_objects.args, "--include-tag");
141 if (filter_options.filter_spec) {
142 if (pack_objects.use_shell) {
143 struct strbuf buf = STRBUF_INIT;
144 sq_quote_buf(&buf, filter_options.filter_spec);
145 argv_array_pushf(&pack_objects.args, "--filter=%s", buf.buf);
146 strbuf_release(&buf);
148 argv_array_pushf(&pack_objects.args, "--filter=%s",
149 filter_options.filter_spec);
153 pack_objects.in = -1;
154 pack_objects.out = -1;
155 pack_objects.err = -1;
157 if (start_command(&pack_objects))
158 die("git upload-pack: unable to fork git-pack-objects");
160 pipe_fd = xfdopen(pack_objects.in, "w");
163 for_each_commit_graft(write_one_shallow, pipe_fd);
165 for (i = 0; i < want_obj.nr; i++)
166 fprintf(pipe_fd, "%s\n",
167 oid_to_hex(&want_obj.objects[i].item->oid));
168 fprintf(pipe_fd, "--not\n");
169 for (i = 0; i < have_obj.nr; i++)
170 fprintf(pipe_fd, "%s\n",
171 oid_to_hex(&have_obj.objects[i].item->oid));
172 for (i = 0; i < extra_edge_obj.nr; i++)
173 fprintf(pipe_fd, "%s\n",
174 oid_to_hex(&extra_edge_obj.objects[i].item->oid));
175 fprintf(pipe_fd, "\n");
179 /* We read from pack_objects.err to capture stderr output for
180 * progress bar, and pack_objects.out to capture the pack data.
184 struct pollfd pfd[2];
185 int pe, pu, pollsize;
193 if (0 <= pack_objects.out) {
194 pfd[pollsize].fd = pack_objects.out;
195 pfd[pollsize].events = POLLIN;
199 if (0 <= pack_objects.err) {
200 pfd[pollsize].fd = pack_objects.err;
201 pfd[pollsize].events = POLLIN;
209 ret = poll(pfd, pollsize,
210 keepalive < 0 ? -1 : 1000 * keepalive);
213 if (errno != EINTR) {
214 error_errno("poll failed, resuming");
219 if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
220 /* Status ready; we ship that in the side-band
221 * or dump to the standard error.
223 sz = xread(pack_objects.err, progress,
226 send_client_data(2, progress, sz);
228 close(pack_objects.err);
229 pack_objects.err = -1;
233 /* give priority to status messages */
236 if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
237 /* Data ready; we keep the last byte to ourselves
238 * in case we detect broken rev-list, so that we
239 * can leave the stream corrupted. This is
240 * unfortunate -- unpack-objects would happily
241 * accept a valid packdata with trailing garbage,
242 * so appending garbage after we pass all the
243 * pack data is not good enough to signal
244 * breakage to downstream.
252 sz = xread(pack_objects.out, cp,
253 sizeof(data) - outsz);
257 close(pack_objects.out);
258 pack_objects.out = -1;
264 buffered = data[sz-1] & 0xFF;
269 send_client_data(1, data, sz);
273 * We hit the keepalive timeout without saying anything; send
274 * an empty message on the data sideband just to let the other
275 * side know we're still working on it, but don't have any data
278 * If we don't have a sideband channel, there's no room in the
279 * protocol to say anything, so those clients are just out of
282 if (!ret && use_sideband) {
283 static const char buf[] = "0005\1";
284 write_or_die(1, buf, 5);
288 if (finish_command(&pack_objects)) {
289 error("git upload-pack: git-pack-objects died with error.");
296 send_client_data(1, data, 1);
297 fprintf(stderr, "flushed.\n");
304 send_client_data(3, abort_msg, sizeof(abort_msg));
305 die("git upload-pack: %s", abort_msg);
308 static int got_oid(const char *hex, struct object_id *oid)
311 int we_knew_they_have = 0;
313 if (get_oid_hex(hex, oid))
314 die("git upload-pack: expected SHA1 object, got '%s'", hex);
315 if (!has_object_file(oid))
318 o = parse_object(oid);
320 die("oops (%s)", oid_to_hex(oid));
321 if (o->type == OBJ_COMMIT) {
322 struct commit_list *parents;
323 struct commit *commit = (struct commit *)o;
324 if (o->flags & THEY_HAVE)
325 we_knew_they_have = 1;
327 o->flags |= THEY_HAVE;
328 if (!oldest_have || (commit->date < oldest_have))
329 oldest_have = commit->date;
330 for (parents = commit->parents;
332 parents = parents->next)
333 parents->item->object.flags |= THEY_HAVE;
335 if (!we_knew_they_have) {
336 add_object_array(o, NULL, &have_obj);
342 static int reachable(struct commit *want)
344 struct prio_queue work = { compare_commits_by_commit_date };
346 prio_queue_put(&work, want);
348 struct commit_list *list;
349 struct commit *commit = prio_queue_get(&work);
351 if (commit->object.flags & THEY_HAVE) {
352 want->object.flags |= COMMON_KNOWN;
355 if (!commit->object.parsed)
356 parse_object(&commit->object.oid);
357 if (commit->object.flags & REACHABLE)
359 commit->object.flags |= REACHABLE;
360 if (commit->date < oldest_have)
362 for (list = commit->parents; list; list = list->next) {
363 struct commit *parent = list->item;
364 if (!(parent->object.flags & REACHABLE))
365 prio_queue_put(&work, parent);
368 want->object.flags |= REACHABLE;
369 clear_commit_marks(want, REACHABLE);
370 clear_prio_queue(&work);
371 return (want->object.flags & COMMON_KNOWN);
374 static int ok_to_give_up(void)
381 for (i = 0; i < want_obj.nr; i++) {
382 struct object *want = want_obj.objects[i].item;
384 if (want->flags & COMMON_KNOWN)
386 want = deref_tag(want, "a want line", 0);
387 if (!want || want->type != OBJ_COMMIT) {
388 /* no way to tell if this is reachable by
389 * looking at the ancestry chain alone, so
390 * leave a note to ourselves not to worry about
391 * this object anymore.
393 want_obj.objects[i].item->flags |= COMMON_KNOWN;
396 if (!reachable((struct commit *)want))
402 static int get_common_commits(void)
404 struct object_id oid;
405 char last_hex[GIT_MAX_HEXSZ + 1];
410 save_commit_buffer = 0;
413 char *line = packet_read_line(0, NULL);
419 if (multi_ack == 2 && got_common
420 && !got_other && ok_to_give_up()) {
422 packet_write_fmt(1, "ACK %s ready\n", last_hex);
424 if (have_obj.nr == 0 || multi_ack)
425 packet_write_fmt(1, "NAK\n");
427 if (no_done && sent_ready) {
428 packet_write_fmt(1, "ACK %s\n", last_hex);
437 if (skip_prefix(line, "have ", &arg)) {
438 switch (got_oid(arg, &oid)) {
439 case -1: /* they have what we do not */
441 if (multi_ack && ok_to_give_up()) {
442 const char *hex = oid_to_hex(&oid);
443 if (multi_ack == 2) {
445 packet_write_fmt(1, "ACK %s ready\n", hex);
447 packet_write_fmt(1, "ACK %s continue\n", hex);
452 memcpy(last_hex, oid_to_hex(&oid), 41);
454 packet_write_fmt(1, "ACK %s common\n", last_hex);
456 packet_write_fmt(1, "ACK %s continue\n", last_hex);
457 else if (have_obj.nr == 1)
458 packet_write_fmt(1, "ACK %s\n", last_hex);
463 if (!strcmp(line, "done")) {
464 if (have_obj.nr > 0) {
466 packet_write_fmt(1, "ACK %s\n", last_hex);
469 packet_write_fmt(1, "NAK\n");
472 die("git upload-pack: expected SHA1 list, got '%s'", line);
476 static int is_our_ref(struct object *o)
478 int allow_hidden_ref = (allow_unadvertised_object_request &
479 (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
480 return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
484 * on successful case, it's up to the caller to close cmd->out
486 static int do_reachable_revlist(struct child_process *cmd,
487 struct object_array *src,
488 struct object_array *reachable)
490 static const char *argv[] = {
491 "rev-list", "--stdin", NULL,
494 char namebuf[42]; /* ^ + SHA-1 + LF */
504 * If the next rev-list --stdin encounters an unknown commit,
505 * it terminates, which will cause SIGPIPE in the write loop
508 sigchain_push(SIGPIPE, SIG_IGN);
510 if (start_command(cmd))
514 namebuf[GIT_SHA1_HEXSZ + 1] = '\n';
515 for (i = get_max_object_index(); 0 < i; ) {
516 o = get_indexed_object(--i);
519 if (reachable && o->type == OBJ_COMMIT)
520 o->flags &= ~TMP_MARK;
523 memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
524 if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0)
527 namebuf[GIT_SHA1_HEXSZ] = '\n';
528 for (i = 0; i < src->nr; i++) {
529 o = src->objects[i].item;
532 add_object_array(o, NULL, reachable);
535 if (reachable && o->type == OBJ_COMMIT)
536 o->flags |= TMP_MARK;
537 memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
538 if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0)
543 sigchain_pop(SIGPIPE);
548 sigchain_pop(SIGPIPE);
557 static int get_reachable_list(struct object_array *src,
558 struct object_array *reachable)
560 struct child_process cmd = CHILD_PROCESS_INIT;
563 char namebuf[42]; /* ^ + SHA-1 + LF */
565 if (do_reachable_revlist(&cmd, src, reachable) < 0)
568 while ((i = read_in_full(cmd.out, namebuf, 41)) == 41) {
569 struct object_id sha1;
571 if (namebuf[40] != '\n' || get_oid_hex(namebuf, &sha1))
574 o = lookup_object(sha1.hash);
575 if (o && o->type == OBJ_COMMIT) {
576 o->flags &= ~TMP_MARK;
579 for (i = get_max_object_index(); 0 < i; i--) {
580 o = get_indexed_object(i - 1);
581 if (o && o->type == OBJ_COMMIT &&
582 (o->flags & TMP_MARK)) {
583 add_object_array(o, NULL, reachable);
584 o->flags &= ~TMP_MARK;
589 if (finish_command(&cmd))
595 static int has_unreachable(struct object_array *src)
597 struct child_process cmd = CHILD_PROCESS_INIT;
601 if (do_reachable_revlist(&cmd, src, NULL) < 0)
605 * The commits out of the rev-list are not ancestors of
608 i = read_in_full(cmd.out, buf, 1);
615 * rev-list may have died by encountering a bad commit
616 * in the history, in which case we do want to bail out
617 * even when it showed no commit.
619 if (finish_command(&cmd))
622 /* All the non-tip ones are ancestors of what we advertised */
626 sigchain_pop(SIGPIPE);
632 static void check_non_tip(void)
637 * In the normal in-process case without
638 * uploadpack.allowReachableSHA1InWant,
639 * non-tip requests can never happen.
641 if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
643 if (!has_unreachable(&want_obj))
644 /* All the non-tip ones are ancestors of what we advertised */
648 /* Pick one of them (we know there at least is one) */
649 for (i = 0; i < want_obj.nr; i++) {
650 struct object *o = want_obj.objects[i].item;
652 die("git upload-pack: not our ref %s",
653 oid_to_hex(&o->oid));
657 static void send_shallow(struct commit_list *result)
660 struct object *object = &result->item->object;
661 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
662 packet_write_fmt(1, "shallow %s",
663 oid_to_hex(&object->oid));
664 register_shallow(&object->oid);
667 result = result->next;
671 static void send_unshallow(const struct object_array *shallows)
675 for (i = 0; i < shallows->nr; i++) {
676 struct object *object = shallows->objects[i].item;
677 if (object->flags & NOT_SHALLOW) {
678 struct commit_list *parents;
679 packet_write_fmt(1, "unshallow %s",
680 oid_to_hex(&object->oid));
681 object->flags &= ~CLIENT_SHALLOW;
683 * We want to _register_ "object" as shallow, but we
684 * also need to traverse object's parents to deepen a
685 * shallow clone. Unregister it for now so we can
686 * parse and add the parents to the want list, then
689 unregister_shallow(&object->oid);
691 parse_commit_or_die((struct commit *)object);
692 parents = ((struct commit *)object)->parents;
694 add_object_array(&parents->item->object,
696 parents = parents->next;
698 add_object_array(object, NULL, &extra_edge_obj);
700 /* make sure commit traversal conforms to client */
701 register_shallow(&object->oid);
705 static void deepen(int depth, int deepen_relative,
706 struct object_array *shallows)
708 if (depth == INFINITE_DEPTH && !is_repository_shallow()) {
711 for (i = 0; i < shallows->nr; i++) {
712 struct object *object = shallows->objects[i].item;
713 object->flags |= NOT_SHALLOW;
715 } else if (deepen_relative) {
716 struct object_array reachable_shallows = OBJECT_ARRAY_INIT;
717 struct commit_list *result;
719 get_reachable_list(shallows, &reachable_shallows);
720 result = get_shallow_commits(&reachable_shallows,
722 SHALLOW, NOT_SHALLOW);
723 send_shallow(result);
724 free_commit_list(result);
725 object_array_clear(&reachable_shallows);
727 struct commit_list *result;
729 result = get_shallow_commits(&want_obj, depth,
730 SHALLOW, NOT_SHALLOW);
731 send_shallow(result);
732 free_commit_list(result);
735 send_unshallow(shallows);
739 static void deepen_by_rev_list(int ac, const char **av,
740 struct object_array *shallows)
742 struct commit_list *result;
744 result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
745 send_shallow(result);
746 free_commit_list(result);
747 send_unshallow(shallows);
751 static void receive_needs(void)
753 struct object_array shallows = OBJECT_ARRAY_INIT;
754 struct string_list deepen_not = STRING_LIST_INIT_DUP;
757 timestamp_t deepen_since = 0;
758 int deepen_rev_list = 0;
763 const char *features;
764 struct object_id oid_buf;
765 char *line = packet_read_line(0, NULL);
772 if (skip_prefix(line, "shallow ", &arg)) {
773 struct object_id oid;
774 struct object *object;
775 if (get_oid_hex(arg, &oid))
776 die("invalid shallow line: %s", line);
777 object = parse_object(&oid);
780 if (object->type != OBJ_COMMIT)
781 die("invalid shallow object %s", oid_to_hex(&oid));
782 if (!(object->flags & CLIENT_SHALLOW)) {
783 object->flags |= CLIENT_SHALLOW;
784 add_object_array(object, NULL, &shallows);
788 if (skip_prefix(line, "deepen ", &arg)) {
790 depth = strtol(arg, &end, 0);
791 if (!end || *end || depth <= 0)
792 die("Invalid deepen: %s", line);
795 if (skip_prefix(line, "deepen-since ", &arg)) {
797 deepen_since = parse_timestamp(arg, &end, 0);
798 if (!end || *end || !deepen_since ||
799 /* revisions.c's max_age -1 is special */
801 die("Invalid deepen-since: %s", line);
805 if (skip_prefix(line, "deepen-not ", &arg)) {
807 struct object_id oid;
808 if (expand_ref(arg, strlen(arg), oid.hash, &ref) != 1)
809 die("git upload-pack: ambiguous deepen-not: %s", line);
810 string_list_append(&deepen_not, ref);
815 if (skip_prefix(line, "filter ", &arg)) {
816 if (!filter_capability_requested)
817 die("git upload-pack: filtering capability not negotiated");
818 parse_list_objects_filter(&filter_options, arg);
821 if (!skip_prefix(line, "want ", &arg) ||
822 get_oid_hex(arg, &oid_buf))
823 die("git upload-pack: protocol error, "
824 "expected to get sha, not '%s'", line);
828 if (parse_feature_request(features, "deepen-relative"))
830 if (parse_feature_request(features, "multi_ack_detailed"))
832 else if (parse_feature_request(features, "multi_ack"))
834 if (parse_feature_request(features, "no-done"))
836 if (parse_feature_request(features, "thin-pack"))
838 if (parse_feature_request(features, "ofs-delta"))
840 if (parse_feature_request(features, "side-band-64k"))
841 use_sideband = LARGE_PACKET_MAX;
842 else if (parse_feature_request(features, "side-band"))
843 use_sideband = DEFAULT_PACKET_MAX;
844 if (parse_feature_request(features, "no-progress"))
846 if (parse_feature_request(features, "include-tag"))
848 if (parse_feature_request(features, "filter"))
849 filter_capability_requested = 1;
851 o = parse_object(&oid_buf);
854 "ERR upload-pack: not our ref %s",
855 oid_to_hex(&oid_buf));
856 die("git upload-pack: not our ref %s",
857 oid_to_hex(&oid_buf));
859 if (!(o->flags & WANTED)) {
861 if (!((allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
864 add_object_array(o, NULL, &want_obj);
869 * We have sent all our refs already, and the other end
870 * should have chosen out of them. When we are operating
871 * in the stateless RPC mode, however, their choice may
872 * have been based on the set of older refs advertised
873 * by another process that handled the initial request.
878 if (!use_sideband && daemon_mode)
881 if (depth == 0 && !deepen_rev_list && shallows.nr == 0)
883 if (depth > 0 && deepen_rev_list)
884 die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together");
886 deepen(depth, deepen_relative, &shallows);
887 else if (deepen_rev_list) {
888 struct argv_array av = ARGV_ARRAY_INIT;
891 argv_array_push(&av, "rev-list");
893 argv_array_pushf(&av, "--max-age=%"PRItime, deepen_since);
895 argv_array_push(&av, "--not");
896 for (i = 0; i < deepen_not.nr; i++) {
897 struct string_list_item *s = deepen_not.items + i;
898 argv_array_push(&av, s->string);
900 argv_array_push(&av, "--not");
902 for (i = 0; i < want_obj.nr; i++) {
903 struct object *o = want_obj.objects[i].item;
904 argv_array_push(&av, oid_to_hex(&o->oid));
906 deepen_by_rev_list(av.argc, av.argv, &shallows);
907 argv_array_clear(&av);
910 if (shallows.nr > 0) {
912 for (i = 0; i < shallows.nr; i++)
913 register_shallow(&shallows.objects[i].item->oid);
916 shallow_nr += shallows.nr;
917 object_array_clear(&shallows);
920 /* return non-zero if the ref is hidden, otherwise 0 */
921 static int mark_our_ref(const char *refname, const char *refname_full,
922 const struct object_id *oid)
924 struct object *o = lookup_unknown_object(oid->hash);
926 if (ref_is_hidden(refname, refname_full)) {
927 o->flags |= HIDDEN_REF;
934 static int check_ref(const char *refname_full, const struct object_id *oid,
935 int flag, void *cb_data)
937 const char *refname = strip_namespace(refname_full);
939 mark_our_ref(refname, refname_full, oid);
943 static void format_symref_info(struct strbuf *buf, struct string_list *symref)
945 struct string_list_item *item;
949 for_each_string_list_item(item, symref)
950 strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util);
953 static int send_ref(const char *refname, const struct object_id *oid,
954 int flag, void *cb_data)
956 static const char *capabilities = "multi_ack thin-pack side-band"
957 " side-band-64k ofs-delta shallow deepen-since deepen-not"
958 " deepen-relative no-progress include-tag multi_ack_detailed";
959 const char *refname_nons = strip_namespace(refname);
960 struct object_id peeled;
962 if (mark_our_ref(refname_nons, refname, oid))
966 struct strbuf symref_info = STRBUF_INIT;
968 format_symref_info(&symref_info, cb_data);
969 packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
970 oid_to_hex(oid), refname_nons,
972 (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
973 " allow-tip-sha1-in-want" : "",
974 (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
975 " allow-reachable-sha1-in-want" : "",
976 stateless_rpc ? " no-done" : "",
978 filter_advertise ? " filter" : "",
979 git_user_agent_sanitized());
980 strbuf_release(&symref_info);
982 packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
985 if (!peel_ref(refname, peeled.hash))
986 packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
990 static int find_symref(const char *refname, const struct object_id *oid,
991 int flag, void *cb_data)
993 const char *symref_target;
994 struct string_list_item *item;
996 if ((flag & REF_ISSYMREF) == 0)
998 symref_target = resolve_ref_unsafe(refname, 0, NULL, &flag);
999 if (!symref_target || (flag & REF_ISSYMREF) == 0)
1000 die("'%s' is a symref but it is not?", refname);
1001 item = string_list_append(cb_data, refname);
1002 item->util = xstrdup(symref_target);
1006 static void upload_pack(void)
1008 struct string_list symref = STRING_LIST_INIT_DUP;
1010 head_ref_namespaced(find_symref, &symref);
1012 if (advertise_refs || !stateless_rpc) {
1014 head_ref_namespaced(send_ref, &symref);
1015 for_each_namespaced_ref(send_ref, &symref);
1016 advertise_shallow_grafts(1);
1019 head_ref_namespaced(check_ref, NULL);
1020 for_each_namespaced_ref(check_ref, NULL);
1022 string_list_clear(&symref, 1);
1028 get_common_commits();
1033 static int upload_pack_config(const char *var, const char *value, void *unused)
1035 if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
1036 if (git_config_bool(var, value))
1037 allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
1039 allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
1040 } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
1041 if (git_config_bool(var, value))
1042 allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1044 allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
1045 } else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
1046 if (git_config_bool(var, value))
1047 allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
1049 allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
1050 } else if (!strcmp("uploadpack.keepalive", var)) {
1051 keepalive = git_config_int(var, value);
1054 } else if (current_config_scope() != CONFIG_SCOPE_REPO) {
1055 if (!strcmp("uploadpack.packobjectshook", var))
1056 return git_config_string(&pack_objects_hook, var, value);
1057 } else if (!strcmp("uploadpack.allowfilter", var)) {
1058 filter_advertise = git_config_bool(var, value);
1060 return parse_hide_refs_config(var, value, "uploadpack");
1063 int cmd_main(int argc, const char **argv)
1067 struct option options[] = {
1068 OPT_BOOL(0, "stateless-rpc", &stateless_rpc,
1069 N_("quit after a single request/response exchange")),
1070 OPT_BOOL(0, "advertise-refs", &advertise_refs,
1071 N_("exit immediately after initial ref advertisement")),
1072 OPT_BOOL(0, "strict", &strict,
1073 N_("do not try <directory>/.git/ if <directory> is no Git directory")),
1074 OPT_INTEGER(0, "timeout", &timeout,
1075 N_("interrupt transfer after <n> seconds of inactivity")),
1079 packet_trace_identity("upload-pack");
1080 check_replace_refs = 0;
1082 argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0);
1085 usage_with_options(upload_pack_usage, options);
1094 if (!enter_repo(dir, strict))
1095 die("'%s' does not appear to be a git repository", dir);
1097 git_config(upload_pack_config, NULL);