12 #include "list-objects.h"
13 #include "run-command.h"
17 #include "string-list.h"
18 #include "parse-options.h"
19 #include "argv-array.h"
20 #include "prio-queue.h"
22 static const char * const upload_pack_usage[] = {
23 N_("git upload-pack [<options>] <dir>"),
27 /* Remember to update object flag allocation in object.h */
28 #define THEY_HAVE (1u << 11)
29 #define OUR_REF (1u << 12)
30 #define WANTED (1u << 13)
31 #define COMMON_KNOWN (1u << 14)
32 #define REACHABLE (1u << 15)
34 #define SHALLOW (1u << 16)
35 #define NOT_SHALLOW (1u << 17)
36 #define CLIENT_SHALLOW (1u << 18)
37 #define HIDDEN_REF (1u << 19)
39 static timestamp_t oldest_have;
41 static int deepen_relative;
44 static int use_thin_pack, use_ofs_delta, use_include_tag;
45 static int no_progress, daemon_mode;
46 /* Allow specifying sha1 if it is a ref tip. */
47 #define ALLOW_TIP_SHA1 01
48 /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
49 #define ALLOW_REACHABLE_SHA1 02
50 /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
51 #define ALLOW_ANY_SHA1 07
52 static unsigned int allow_unadvertised_object_request;
53 static int shallow_nr;
54 static struct object_array have_obj;
55 static struct object_array want_obj;
56 static struct object_array extra_edge_obj;
57 static unsigned int timeout;
58 static int keepalive = 5;
60 * otherwise maximum packet size (up to 65520 bytes).
62 static int use_sideband;
63 static int advertise_refs;
64 static int stateless_rpc;
65 static const char *pack_objects_hook;
67 static void reset_timeout(void)
72 static void send_client_data(int fd, const char *data, ssize_t sz)
75 send_sideband(1, fd, data, sz, use_sideband);
82 /* XXX: are we happy to lose stuff here? */
86 write_or_die(fd, data, sz);
89 static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
92 if (graft->nr_parent == -1)
93 fprintf(fp, "--shallow %s\n", oid_to_hex(&graft->oid));
97 static void create_pack_file(void)
99 struct child_process pack_objects = CHILD_PROCESS_INIT;
100 char data[8193], progress[128];
101 char abort_msg[] = "aborting due to possible repository "
102 "corruption on the remote side.";
108 if (!pack_objects_hook)
109 pack_objects.git_cmd = 1;
111 argv_array_push(&pack_objects.args, pack_objects_hook);
112 argv_array_push(&pack_objects.args, "git");
113 pack_objects.use_shell = 1;
117 argv_array_push(&pack_objects.args, "--shallow-file");
118 argv_array_push(&pack_objects.args, "");
120 argv_array_push(&pack_objects.args, "pack-objects");
121 argv_array_push(&pack_objects.args, "--revs");
123 argv_array_push(&pack_objects.args, "--thin");
125 argv_array_push(&pack_objects.args, "--stdout");
127 argv_array_push(&pack_objects.args, "--shallow");
129 argv_array_push(&pack_objects.args, "--progress");
131 argv_array_push(&pack_objects.args, "--delta-base-offset");
133 argv_array_push(&pack_objects.args, "--include-tag");
135 pack_objects.in = -1;
136 pack_objects.out = -1;
137 pack_objects.err = -1;
139 if (start_command(&pack_objects))
140 die("git upload-pack: unable to fork git-pack-objects");
142 pipe_fd = xfdopen(pack_objects.in, "w");
145 for_each_commit_graft(write_one_shallow, pipe_fd);
147 for (i = 0; i < want_obj.nr; i++)
148 fprintf(pipe_fd, "%s\n",
149 oid_to_hex(&want_obj.objects[i].item->oid));
150 fprintf(pipe_fd, "--not\n");
151 for (i = 0; i < have_obj.nr; i++)
152 fprintf(pipe_fd, "%s\n",
153 oid_to_hex(&have_obj.objects[i].item->oid));
154 for (i = 0; i < extra_edge_obj.nr; i++)
155 fprintf(pipe_fd, "%s\n",
156 oid_to_hex(&extra_edge_obj.objects[i].item->oid));
157 fprintf(pipe_fd, "\n");
161 /* We read from pack_objects.err to capture stderr output for
162 * progress bar, and pack_objects.out to capture the pack data.
166 struct pollfd pfd[2];
167 int pe, pu, pollsize;
175 if (0 <= pack_objects.out) {
176 pfd[pollsize].fd = pack_objects.out;
177 pfd[pollsize].events = POLLIN;
181 if (0 <= pack_objects.err) {
182 pfd[pollsize].fd = pack_objects.err;
183 pfd[pollsize].events = POLLIN;
191 ret = poll(pfd, pollsize,
192 keepalive < 0 ? -1 : 1000 * keepalive);
195 if (errno != EINTR) {
196 error_errno("poll failed, resuming");
201 if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
202 /* Status ready; we ship that in the side-band
203 * or dump to the standard error.
205 sz = xread(pack_objects.err, progress,
208 send_client_data(2, progress, sz);
210 close(pack_objects.err);
211 pack_objects.err = -1;
215 /* give priority to status messages */
218 if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
219 /* Data ready; we keep the last byte to ourselves
220 * in case we detect broken rev-list, so that we
221 * can leave the stream corrupted. This is
222 * unfortunate -- unpack-objects would happily
223 * accept a valid packdata with trailing garbage,
224 * so appending garbage after we pass all the
225 * pack data is not good enough to signal
226 * breakage to downstream.
234 sz = xread(pack_objects.out, cp,
235 sizeof(data) - outsz);
239 close(pack_objects.out);
240 pack_objects.out = -1;
246 buffered = data[sz-1] & 0xFF;
251 send_client_data(1, data, sz);
255 * We hit the keepalive timeout without saying anything; send
256 * an empty message on the data sideband just to let the other
257 * side know we're still working on it, but don't have any data
260 * If we don't have a sideband channel, there's no room in the
261 * protocol to say anything, so those clients are just out of
264 if (!ret && use_sideband) {
265 static const char buf[] = "0005\1";
266 write_or_die(1, buf, 5);
270 if (finish_command(&pack_objects)) {
271 error("git upload-pack: git-pack-objects died with error.");
278 send_client_data(1, data, 1);
279 fprintf(stderr, "flushed.\n");
286 send_client_data(3, abort_msg, sizeof(abort_msg));
287 die("git upload-pack: %s", abort_msg);
290 static int got_oid(const char *hex, struct object_id *oid)
293 int we_knew_they_have = 0;
295 if (get_oid_hex(hex, oid))
296 die("git upload-pack: expected SHA1 object, got '%s'", hex);
297 if (!has_object_file(oid))
300 o = parse_object(oid);
302 die("oops (%s)", oid_to_hex(oid));
303 if (o->type == OBJ_COMMIT) {
304 struct commit_list *parents;
305 struct commit *commit = (struct commit *)o;
306 if (o->flags & THEY_HAVE)
307 we_knew_they_have = 1;
309 o->flags |= THEY_HAVE;
310 if (!oldest_have || (commit->date < oldest_have))
311 oldest_have = commit->date;
312 for (parents = commit->parents;
314 parents = parents->next)
315 parents->item->object.flags |= THEY_HAVE;
317 if (!we_knew_they_have) {
318 add_object_array(o, NULL, &have_obj);
324 static int reachable(struct commit *want)
326 struct prio_queue work = { compare_commits_by_commit_date };
328 prio_queue_put(&work, want);
330 struct commit_list *list;
331 struct commit *commit = prio_queue_get(&work);
333 if (commit->object.flags & THEY_HAVE) {
334 want->object.flags |= COMMON_KNOWN;
337 if (!commit->object.parsed)
338 parse_object(&commit->object.oid);
339 if (commit->object.flags & REACHABLE)
341 commit->object.flags |= REACHABLE;
342 if (commit->date < oldest_have)
344 for (list = commit->parents; list; list = list->next) {
345 struct commit *parent = list->item;
346 if (!(parent->object.flags & REACHABLE))
347 prio_queue_put(&work, parent);
350 want->object.flags |= REACHABLE;
351 clear_commit_marks(want, REACHABLE);
352 clear_prio_queue(&work);
353 return (want->object.flags & COMMON_KNOWN);
356 static int ok_to_give_up(void)
363 for (i = 0; i < want_obj.nr; i++) {
364 struct object *want = want_obj.objects[i].item;
366 if (want->flags & COMMON_KNOWN)
368 want = deref_tag(want, "a want line", 0);
369 if (!want || want->type != OBJ_COMMIT) {
370 /* no way to tell if this is reachable by
371 * looking at the ancestry chain alone, so
372 * leave a note to ourselves not to worry about
373 * this object anymore.
375 want_obj.objects[i].item->flags |= COMMON_KNOWN;
378 if (!reachable((struct commit *)want))
384 static int get_common_commits(void)
386 struct object_id oid;
387 char last_hex[GIT_MAX_HEXSZ + 1];
392 save_commit_buffer = 0;
395 char *line = packet_read_line(0, NULL);
401 if (multi_ack == 2 && got_common
402 && !got_other && ok_to_give_up()) {
404 packet_write_fmt(1, "ACK %s ready\n", last_hex);
406 if (have_obj.nr == 0 || multi_ack)
407 packet_write_fmt(1, "NAK\n");
409 if (no_done && sent_ready) {
410 packet_write_fmt(1, "ACK %s\n", last_hex);
419 if (skip_prefix(line, "have ", &arg)) {
420 switch (got_oid(arg, &oid)) {
421 case -1: /* they have what we do not */
423 if (multi_ack && ok_to_give_up()) {
424 const char *hex = oid_to_hex(&oid);
425 if (multi_ack == 2) {
427 packet_write_fmt(1, "ACK %s ready\n", hex);
429 packet_write_fmt(1, "ACK %s continue\n", hex);
434 memcpy(last_hex, oid_to_hex(&oid), 41);
436 packet_write_fmt(1, "ACK %s common\n", last_hex);
438 packet_write_fmt(1, "ACK %s continue\n", last_hex);
439 else if (have_obj.nr == 1)
440 packet_write_fmt(1, "ACK %s\n", last_hex);
445 if (!strcmp(line, "done")) {
446 if (have_obj.nr > 0) {
448 packet_write_fmt(1, "ACK %s\n", last_hex);
451 packet_write_fmt(1, "NAK\n");
454 die("git upload-pack: expected SHA1 list, got '%s'", line);
458 static int is_our_ref(struct object *o)
460 int allow_hidden_ref = (allow_unadvertised_object_request &
461 (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
462 return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
466 * on successful case, it's up to the caller to close cmd->out
468 static int do_reachable_revlist(struct child_process *cmd,
469 struct object_array *src,
470 struct object_array *reachable)
472 static const char *argv[] = {
473 "rev-list", "--stdin", NULL,
476 char namebuf[42]; /* ^ + SHA-1 + LF */
486 * If the next rev-list --stdin encounters an unknown commit,
487 * it terminates, which will cause SIGPIPE in the write loop
490 sigchain_push(SIGPIPE, SIG_IGN);
492 if (start_command(cmd))
496 namebuf[GIT_SHA1_HEXSZ + 1] = '\n';
497 for (i = get_max_object_index(); 0 < i; ) {
498 o = get_indexed_object(--i);
501 if (reachable && o->type == OBJ_COMMIT)
502 o->flags &= ~TMP_MARK;
505 memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
506 if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0)
509 namebuf[GIT_SHA1_HEXSZ] = '\n';
510 for (i = 0; i < src->nr; i++) {
511 o = src->objects[i].item;
514 add_object_array(o, NULL, reachable);
517 if (reachable && o->type == OBJ_COMMIT)
518 o->flags |= TMP_MARK;
519 memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
520 if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0)
525 sigchain_pop(SIGPIPE);
530 sigchain_pop(SIGPIPE);
539 static int get_reachable_list(struct object_array *src,
540 struct object_array *reachable)
542 struct child_process cmd = CHILD_PROCESS_INIT;
545 char namebuf[42]; /* ^ + SHA-1 + LF */
547 if (do_reachable_revlist(&cmd, src, reachable) < 0)
550 while ((i = read_in_full(cmd.out, namebuf, 41)) == 41) {
551 struct object_id sha1;
553 if (namebuf[40] != '\n' || get_oid_hex(namebuf, &sha1))
556 o = lookup_object(sha1.hash);
557 if (o && o->type == OBJ_COMMIT) {
558 o->flags &= ~TMP_MARK;
561 for (i = get_max_object_index(); 0 < i; i--) {
562 o = get_indexed_object(i - 1);
563 if (o && o->type == OBJ_COMMIT &&
564 (o->flags & TMP_MARK)) {
565 add_object_array(o, NULL, reachable);
566 o->flags &= ~TMP_MARK;
571 if (finish_command(&cmd))
577 static int has_unreachable(struct object_array *src)
579 struct child_process cmd = CHILD_PROCESS_INIT;
583 if (do_reachable_revlist(&cmd, src, NULL) < 0)
587 * The commits out of the rev-list are not ancestors of
590 i = read_in_full(cmd.out, buf, 1);
597 * rev-list may have died by encountering a bad commit
598 * in the history, in which case we do want to bail out
599 * even when it showed no commit.
601 if (finish_command(&cmd))
604 /* All the non-tip ones are ancestors of what we advertised */
608 sigchain_pop(SIGPIPE);
614 static void check_non_tip(void)
619 * In the normal in-process case without
620 * uploadpack.allowReachableSHA1InWant,
621 * non-tip requests can never happen.
623 if (!stateless_rpc && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
625 if (!has_unreachable(&want_obj))
626 /* All the non-tip ones are ancestors of what we advertised */
630 /* Pick one of them (we know there at least is one) */
631 for (i = 0; i < want_obj.nr; i++) {
632 struct object *o = want_obj.objects[i].item;
634 die("git upload-pack: not our ref %s",
635 oid_to_hex(&o->oid));
639 static void send_shallow(struct commit_list *result)
642 struct object *object = &result->item->object;
643 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
644 packet_write_fmt(1, "shallow %s",
645 oid_to_hex(&object->oid));
646 register_shallow(&object->oid);
649 result = result->next;
653 static void send_unshallow(const struct object_array *shallows)
657 for (i = 0; i < shallows->nr; i++) {
658 struct object *object = shallows->objects[i].item;
659 if (object->flags & NOT_SHALLOW) {
660 struct commit_list *parents;
661 packet_write_fmt(1, "unshallow %s",
662 oid_to_hex(&object->oid));
663 object->flags &= ~CLIENT_SHALLOW;
665 * We want to _register_ "object" as shallow, but we
666 * also need to traverse object's parents to deepen a
667 * shallow clone. Unregister it for now so we can
668 * parse and add the parents to the want list, then
671 unregister_shallow(&object->oid);
673 parse_commit_or_die((struct commit *)object);
674 parents = ((struct commit *)object)->parents;
676 add_object_array(&parents->item->object,
678 parents = parents->next;
680 add_object_array(object, NULL, &extra_edge_obj);
682 /* make sure commit traversal conforms to client */
683 register_shallow(&object->oid);
687 static void deepen(int depth, int deepen_relative,
688 struct object_array *shallows)
690 if (depth == INFINITE_DEPTH && !is_repository_shallow()) {
693 for (i = 0; i < shallows->nr; i++) {
694 struct object *object = shallows->objects[i].item;
695 object->flags |= NOT_SHALLOW;
697 } else if (deepen_relative) {
698 struct object_array reachable_shallows = OBJECT_ARRAY_INIT;
699 struct commit_list *result;
701 get_reachable_list(shallows, &reachable_shallows);
702 result = get_shallow_commits(&reachable_shallows,
704 SHALLOW, NOT_SHALLOW);
705 send_shallow(result);
706 free_commit_list(result);
707 object_array_clear(&reachable_shallows);
709 struct commit_list *result;
711 result = get_shallow_commits(&want_obj, depth,
712 SHALLOW, NOT_SHALLOW);
713 send_shallow(result);
714 free_commit_list(result);
717 send_unshallow(shallows);
721 static void deepen_by_rev_list(int ac, const char **av,
722 struct object_array *shallows)
724 struct commit_list *result;
726 result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
727 send_shallow(result);
728 free_commit_list(result);
729 send_unshallow(shallows);
733 static void receive_needs(void)
735 struct object_array shallows = OBJECT_ARRAY_INIT;
736 struct string_list deepen_not = STRING_LIST_INIT_DUP;
739 timestamp_t deepen_since = 0;
740 int deepen_rev_list = 0;
745 const char *features;
746 struct object_id oid_buf;
747 char *line = packet_read_line(0, NULL);
754 if (skip_prefix(line, "shallow ", &arg)) {
755 struct object_id oid;
756 struct object *object;
757 if (get_oid_hex(arg, &oid))
758 die("invalid shallow line: %s", line);
759 object = parse_object(&oid);
762 if (object->type != OBJ_COMMIT)
763 die("invalid shallow object %s", oid_to_hex(&oid));
764 if (!(object->flags & CLIENT_SHALLOW)) {
765 object->flags |= CLIENT_SHALLOW;
766 add_object_array(object, NULL, &shallows);
770 if (skip_prefix(line, "deepen ", &arg)) {
772 depth = strtol(arg, &end, 0);
773 if (!end || *end || depth <= 0)
774 die("Invalid deepen: %s", line);
777 if (skip_prefix(line, "deepen-since ", &arg)) {
779 deepen_since = parse_timestamp(arg, &end, 0);
780 if (!end || *end || !deepen_since ||
781 /* revisions.c's max_age -1 is special */
783 die("Invalid deepen-since: %s", line);
787 if (skip_prefix(line, "deepen-not ", &arg)) {
789 struct object_id oid;
790 if (expand_ref(arg, strlen(arg), &oid, &ref) != 1)
791 die("git upload-pack: ambiguous deepen-not: %s", line);
792 string_list_append(&deepen_not, ref);
797 if (!skip_prefix(line, "want ", &arg) ||
798 get_oid_hex(arg, &oid_buf))
799 die("git upload-pack: protocol error, "
800 "expected to get sha, not '%s'", line);
804 if (parse_feature_request(features, "deepen-relative"))
806 if (parse_feature_request(features, "multi_ack_detailed"))
808 else if (parse_feature_request(features, "multi_ack"))
810 if (parse_feature_request(features, "no-done"))
812 if (parse_feature_request(features, "thin-pack"))
814 if (parse_feature_request(features, "ofs-delta"))
816 if (parse_feature_request(features, "side-band-64k"))
817 use_sideband = LARGE_PACKET_MAX;
818 else if (parse_feature_request(features, "side-band"))
819 use_sideband = DEFAULT_PACKET_MAX;
820 if (parse_feature_request(features, "no-progress"))
822 if (parse_feature_request(features, "include-tag"))
825 o = parse_object(&oid_buf);
828 "ERR upload-pack: not our ref %s",
829 oid_to_hex(&oid_buf));
830 die("git upload-pack: not our ref %s",
831 oid_to_hex(&oid_buf));
833 if (!(o->flags & WANTED)) {
835 if (!((allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
838 add_object_array(o, NULL, &want_obj);
843 * We have sent all our refs already, and the other end
844 * should have chosen out of them. When we are operating
845 * in the stateless RPC mode, however, their choice may
846 * have been based on the set of older refs advertised
847 * by another process that handled the initial request.
852 if (!use_sideband && daemon_mode)
855 if (depth == 0 && !deepen_rev_list && shallows.nr == 0)
857 if (depth > 0 && deepen_rev_list)
858 die("git upload-pack: deepen and deepen-since (or deepen-not) cannot be used together");
860 deepen(depth, deepen_relative, &shallows);
861 else if (deepen_rev_list) {
862 struct argv_array av = ARGV_ARRAY_INIT;
865 argv_array_push(&av, "rev-list");
867 argv_array_pushf(&av, "--max-age=%"PRItime, deepen_since);
869 argv_array_push(&av, "--not");
870 for (i = 0; i < deepen_not.nr; i++) {
871 struct string_list_item *s = deepen_not.items + i;
872 argv_array_push(&av, s->string);
874 argv_array_push(&av, "--not");
876 for (i = 0; i < want_obj.nr; i++) {
877 struct object *o = want_obj.objects[i].item;
878 argv_array_push(&av, oid_to_hex(&o->oid));
880 deepen_by_rev_list(av.argc, av.argv, &shallows);
881 argv_array_clear(&av);
884 if (shallows.nr > 0) {
886 for (i = 0; i < shallows.nr; i++)
887 register_shallow(&shallows.objects[i].item->oid);
890 shallow_nr += shallows.nr;
891 object_array_clear(&shallows);
894 /* return non-zero if the ref is hidden, otherwise 0 */
895 static int mark_our_ref(const char *refname, const char *refname_full,
896 const struct object_id *oid)
898 struct object *o = lookup_unknown_object(oid->hash);
900 if (ref_is_hidden(refname, refname_full)) {
901 o->flags |= HIDDEN_REF;
908 static int check_ref(const char *refname_full, const struct object_id *oid,
909 int flag, void *cb_data)
911 const char *refname = strip_namespace(refname_full);
913 mark_our_ref(refname, refname_full, oid);
917 static void format_symref_info(struct strbuf *buf, struct string_list *symref)
919 struct string_list_item *item;
923 for_each_string_list_item(item, symref)
924 strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util);
927 static int send_ref(const char *refname, const struct object_id *oid,
928 int flag, void *cb_data)
930 static const char *capabilities = "multi_ack thin-pack side-band"
931 " side-band-64k ofs-delta shallow deepen-since deepen-not"
932 " deepen-relative no-progress include-tag multi_ack_detailed";
933 const char *refname_nons = strip_namespace(refname);
934 struct object_id peeled;
936 if (mark_our_ref(refname_nons, refname, oid))
940 struct strbuf symref_info = STRBUF_INIT;
942 format_symref_info(&symref_info, cb_data);
943 packet_write_fmt(1, "%s %s%c%s%s%s%s%s agent=%s\n",
944 oid_to_hex(oid), refname_nons,
946 (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
947 " allow-tip-sha1-in-want" : "",
948 (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
949 " allow-reachable-sha1-in-want" : "",
950 stateless_rpc ? " no-done" : "",
952 git_user_agent_sanitized());
953 strbuf_release(&symref_info);
955 packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
958 if (!peel_ref(refname, &peeled))
959 packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
963 static int find_symref(const char *refname, const struct object_id *oid,
964 int flag, void *cb_data)
966 const char *symref_target;
967 struct string_list_item *item;
969 if ((flag & REF_ISSYMREF) == 0)
971 symref_target = resolve_ref_unsafe(refname, 0, NULL, &flag);
972 if (!symref_target || (flag & REF_ISSYMREF) == 0)
973 die("'%s' is a symref but it is not?", refname);
974 item = string_list_append(cb_data, refname);
975 item->util = xstrdup(symref_target);
979 static void upload_pack(void)
981 struct string_list symref = STRING_LIST_INIT_DUP;
983 head_ref_namespaced(find_symref, &symref);
985 if (advertise_refs || !stateless_rpc) {
987 head_ref_namespaced(send_ref, &symref);
988 for_each_namespaced_ref(send_ref, &symref);
989 advertise_shallow_grafts(1);
992 head_ref_namespaced(check_ref, NULL);
993 for_each_namespaced_ref(check_ref, NULL);
995 string_list_clear(&symref, 1);
1001 get_common_commits();
1006 static int upload_pack_config(const char *var, const char *value, void *unused)
1008 if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
1009 if (git_config_bool(var, value))
1010 allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
1012 allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
1013 } else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
1014 if (git_config_bool(var, value))
1015 allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1017 allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
1018 } else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
1019 if (git_config_bool(var, value))
1020 allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
1022 allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
1023 } else if (!strcmp("uploadpack.keepalive", var)) {
1024 keepalive = git_config_int(var, value);
1027 } else if (current_config_scope() != CONFIG_SCOPE_REPO) {
1028 if (!strcmp("uploadpack.packobjectshook", var))
1029 return git_config_string(&pack_objects_hook, var, value);
1031 return parse_hide_refs_config(var, value, "uploadpack");
1034 int cmd_main(int argc, const char **argv)
1038 struct option options[] = {
1039 OPT_BOOL(0, "stateless-rpc", &stateless_rpc,
1040 N_("quit after a single request/response exchange")),
1041 OPT_BOOL(0, "advertise-refs", &advertise_refs,
1042 N_("exit immediately after initial ref advertisement")),
1043 OPT_BOOL(0, "strict", &strict,
1044 N_("do not try <directory>/.git/ if <directory> is no Git directory")),
1045 OPT_INTEGER(0, "timeout", &timeout,
1046 N_("interrupt transfer after <n> seconds of inactivity")),
1050 packet_trace_identity("upload-pack");
1051 check_replace_refs = 0;
1053 argc = parse_options(argc, argv, NULL, options, upload_pack_usage, 0);
1056 usage_with_options(upload_pack_usage, options);
1065 if (!enter_repo(dir, strict))
1066 die("'%s' does not appear to be a git repository", dir);
1068 git_config(upload_pack_config, NULL);