pkt-line: teach packet_read_line to chomp newlines
[git/mingw.git] / upload-pack.c
blob6e6d16687640e561cbaa745a2d851a83f3630681
1 #include "cache.h"
2 #include "refs.h"
3 #include "pkt-line.h"
4 #include "sideband.h"
5 #include "tag.h"
6 #include "object.h"
7 #include "commit.h"
8 #include "exec_cmd.h"
9 #include "diff.h"
10 #include "revision.h"
11 #include "list-objects.h"
12 #include "run-command.h"
13 #include "sigchain.h"
14 #include "version.h"
15 #include "string-list.h"
17 static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>";
19 /* bits #0..7 in revision.h, #8..10 in commit.c */
20 #define THEY_HAVE (1u << 11)
21 #define OUR_REF (1u << 12)
22 #define WANTED (1u << 13)
23 #define COMMON_KNOWN (1u << 14)
24 #define REACHABLE (1u << 15)
26 #define SHALLOW (1u << 16)
27 #define NOT_SHALLOW (1u << 17)
28 #define CLIENT_SHALLOW (1u << 18)
30 static unsigned long oldest_have;
32 static int multi_ack;
33 static int no_done;
34 static int use_thin_pack, use_ofs_delta, use_include_tag;
35 static int no_progress, daemon_mode;
36 static int shallow_nr;
37 static struct object_array have_obj;
38 static struct object_array want_obj;
39 static struct object_array extra_edge_obj;
40 static unsigned int timeout;
41 /* 0 for no sideband,
42 * otherwise maximum packet size (up to 65520 bytes).
44 static int use_sideband;
45 static int advertise_refs;
46 static int stateless_rpc;
48 static void reset_timeout(void)
50 alarm(timeout);
53 static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
55 if (use_sideband)
56 return send_sideband(1, fd, data, sz, use_sideband);
57 if (fd == 3)
58 /* emergency quit */
59 fd = 2;
60 if (fd == 2) {
61 /* XXX: are we happy to lose stuff here? */
62 xwrite(fd, data, sz);
63 return sz;
65 write_or_die(fd, data, sz);
66 return sz;
69 static FILE *pack_pipe = NULL;
70 static void show_commit(struct commit *commit, void *data)
72 if (commit->object.flags & BOUNDARY)
73 fputc('-', pack_pipe);
74 if (fputs(sha1_to_hex(commit->object.sha1), pack_pipe) < 0)
75 die("broken output pipe");
76 fputc('\n', pack_pipe);
77 fflush(pack_pipe);
78 free(commit->buffer);
79 commit->buffer = NULL;
82 static void show_object(struct object *obj,
83 const struct name_path *path, const char *component,
84 void *cb_data)
86 show_object_with_name(pack_pipe, obj, path, component);
89 static void show_edge(struct commit *commit)
91 fprintf(pack_pipe, "-%s\n", sha1_to_hex(commit->object.sha1));
94 static int do_rev_list(int in, int out, void *user_data)
96 int i;
97 struct rev_info revs;
99 pack_pipe = xfdopen(out, "w");
100 init_revisions(&revs, NULL);
101 revs.tag_objects = 1;
102 revs.tree_objects = 1;
103 revs.blob_objects = 1;
104 if (use_thin_pack)
105 revs.edge_hint = 1;
107 for (i = 0; i < want_obj.nr; i++) {
108 struct object *o = want_obj.objects[i].item;
109 /* why??? */
110 o->flags &= ~UNINTERESTING;
111 add_pending_object(&revs, o, NULL);
113 for (i = 0; i < have_obj.nr; i++) {
114 struct object *o = have_obj.objects[i].item;
115 o->flags |= UNINTERESTING;
116 add_pending_object(&revs, o, NULL);
118 setup_revisions(0, NULL, &revs, NULL);
119 if (prepare_revision_walk(&revs))
120 die("revision walk setup failed");
121 mark_edges_uninteresting(revs.commits, &revs, show_edge);
122 if (use_thin_pack)
123 for (i = 0; i < extra_edge_obj.nr; i++)
124 fprintf(pack_pipe, "-%s\n", sha1_to_hex(
125 extra_edge_obj.objects[i].item->sha1));
126 traverse_commit_list(&revs, show_commit, show_object, NULL);
127 fflush(pack_pipe);
128 fclose(pack_pipe);
129 return 0;
132 static void create_pack_file(void)
134 struct async rev_list;
135 struct child_process pack_objects;
136 char data[8193], progress[128];
137 char abort_msg[] = "aborting due to possible repository "
138 "corruption on the remote side.";
139 int buffered = -1;
140 ssize_t sz;
141 const char *argv[10];
142 int arg = 0;
144 argv[arg++] = "pack-objects";
145 if (!shallow_nr) {
146 argv[arg++] = "--revs";
147 if (use_thin_pack)
148 argv[arg++] = "--thin";
151 argv[arg++] = "--stdout";
152 if (!no_progress)
153 argv[arg++] = "--progress";
154 if (use_ofs_delta)
155 argv[arg++] = "--delta-base-offset";
156 if (use_include_tag)
157 argv[arg++] = "--include-tag";
158 argv[arg++] = NULL;
160 memset(&pack_objects, 0, sizeof(pack_objects));
161 pack_objects.in = -1;
162 pack_objects.out = -1;
163 pack_objects.err = -1;
164 pack_objects.git_cmd = 1;
165 pack_objects.argv = argv;
167 if (start_command(&pack_objects))
168 die("git upload-pack: unable to fork git-pack-objects");
170 if (shallow_nr) {
171 memset(&rev_list, 0, sizeof(rev_list));
172 rev_list.proc = do_rev_list;
173 rev_list.out = pack_objects.in;
174 if (start_async(&rev_list))
175 die("git upload-pack: unable to fork git-rev-list");
177 else {
178 FILE *pipe_fd = xfdopen(pack_objects.in, "w");
179 int i;
181 for (i = 0; i < want_obj.nr; i++)
182 fprintf(pipe_fd, "%s\n",
183 sha1_to_hex(want_obj.objects[i].item->sha1));
184 fprintf(pipe_fd, "--not\n");
185 for (i = 0; i < have_obj.nr; i++)
186 fprintf(pipe_fd, "%s\n",
187 sha1_to_hex(have_obj.objects[i].item->sha1));
188 fprintf(pipe_fd, "\n");
189 fflush(pipe_fd);
190 fclose(pipe_fd);
194 /* We read from pack_objects.err to capture stderr output for
195 * progress bar, and pack_objects.out to capture the pack data.
198 while (1) {
199 struct pollfd pfd[2];
200 int pe, pu, pollsize;
202 reset_timeout();
204 pollsize = 0;
205 pe = pu = -1;
207 if (0 <= pack_objects.out) {
208 pfd[pollsize].fd = pack_objects.out;
209 pfd[pollsize].events = POLLIN;
210 pu = pollsize;
211 pollsize++;
213 if (0 <= pack_objects.err) {
214 pfd[pollsize].fd = pack_objects.err;
215 pfd[pollsize].events = POLLIN;
216 pe = pollsize;
217 pollsize++;
220 if (!pollsize)
221 break;
223 if (poll(pfd, pollsize, -1) < 0) {
224 if (errno != EINTR) {
225 error("poll failed, resuming: %s",
226 strerror(errno));
227 sleep(1);
229 continue;
231 if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
232 /* Status ready; we ship that in the side-band
233 * or dump to the standard error.
235 sz = xread(pack_objects.err, progress,
236 sizeof(progress));
237 if (0 < sz)
238 send_client_data(2, progress, sz);
239 else if (sz == 0) {
240 close(pack_objects.err);
241 pack_objects.err = -1;
243 else
244 goto fail;
245 /* give priority to status messages */
246 continue;
248 if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
249 /* Data ready; we keep the last byte to ourselves
250 * in case we detect broken rev-list, so that we
251 * can leave the stream corrupted. This is
252 * unfortunate -- unpack-objects would happily
253 * accept a valid packdata with trailing garbage,
254 * so appending garbage after we pass all the
255 * pack data is not good enough to signal
256 * breakage to downstream.
258 char *cp = data;
259 ssize_t outsz = 0;
260 if (0 <= buffered) {
261 *cp++ = buffered;
262 outsz++;
264 sz = xread(pack_objects.out, cp,
265 sizeof(data) - outsz);
266 if (0 < sz)
268 else if (sz == 0) {
269 close(pack_objects.out);
270 pack_objects.out = -1;
272 else
273 goto fail;
274 sz += outsz;
275 if (1 < sz) {
276 buffered = data[sz-1] & 0xFF;
277 sz--;
279 else
280 buffered = -1;
281 sz = send_client_data(1, data, sz);
282 if (sz < 0)
283 goto fail;
287 if (finish_command(&pack_objects)) {
288 error("git upload-pack: git-pack-objects died with error.");
289 goto fail;
291 if (shallow_nr && finish_async(&rev_list))
292 goto fail; /* error was already reported */
294 /* flush the data */
295 if (0 <= buffered) {
296 data[0] = buffered;
297 sz = send_client_data(1, data, 1);
298 if (sz < 0)
299 goto fail;
300 fprintf(stderr, "flushed.\n");
302 if (use_sideband)
303 packet_flush(1);
304 return;
306 fail:
307 send_client_data(3, abort_msg, sizeof(abort_msg));
308 die("git upload-pack: %s", abort_msg);
311 static int got_sha1(char *hex, unsigned char *sha1)
313 struct object *o;
314 int we_knew_they_have = 0;
316 if (get_sha1_hex(hex, sha1))
317 die("git upload-pack: expected SHA1 object, got '%s'", hex);
318 if (!has_sha1_file(sha1))
319 return -1;
321 o = lookup_object(sha1);
322 if (!(o && o->parsed))
323 o = parse_object(sha1);
324 if (!o)
325 die("oops (%s)", sha1_to_hex(sha1));
326 if (o->type == OBJ_COMMIT) {
327 struct commit_list *parents;
328 struct commit *commit = (struct commit *)o;
329 if (o->flags & THEY_HAVE)
330 we_knew_they_have = 1;
331 else
332 o->flags |= THEY_HAVE;
333 if (!oldest_have || (commit->date < oldest_have))
334 oldest_have = commit->date;
335 for (parents = commit->parents;
336 parents;
337 parents = parents->next)
338 parents->item->object.flags |= THEY_HAVE;
340 if (!we_knew_they_have) {
341 add_object_array(o, NULL, &have_obj);
342 return 1;
344 return 0;
347 static int reachable(struct commit *want)
349 struct commit_list *work = NULL;
351 commit_list_insert_by_date(want, &work);
352 while (work) {
353 struct commit_list *list = work->next;
354 struct commit *commit = work->item;
355 free(work);
356 work = list;
358 if (commit->object.flags & THEY_HAVE) {
359 want->object.flags |= COMMON_KNOWN;
360 break;
362 if (!commit->object.parsed)
363 parse_object(commit->object.sha1);
364 if (commit->object.flags & REACHABLE)
365 continue;
366 commit->object.flags |= REACHABLE;
367 if (commit->date < oldest_have)
368 continue;
369 for (list = commit->parents; list; list = list->next) {
370 struct commit *parent = list->item;
371 if (!(parent->object.flags & REACHABLE))
372 commit_list_insert_by_date(parent, &work);
375 want->object.flags |= REACHABLE;
376 clear_commit_marks(want, REACHABLE);
377 free_commit_list(work);
378 return (want->object.flags & COMMON_KNOWN);
381 static int ok_to_give_up(void)
383 int i;
385 if (!have_obj.nr)
386 return 0;
388 for (i = 0; i < want_obj.nr; i++) {
389 struct object *want = want_obj.objects[i].item;
391 if (want->flags & COMMON_KNOWN)
392 continue;
393 want = deref_tag(want, "a want line", 0);
394 if (!want || want->type != OBJ_COMMIT) {
395 /* no way to tell if this is reachable by
396 * looking at the ancestry chain alone, so
397 * leave a note to ourselves not to worry about
398 * this object anymore.
400 want_obj.objects[i].item->flags |= COMMON_KNOWN;
401 continue;
403 if (!reachable((struct commit *)want))
404 return 0;
406 return 1;
409 static int get_common_commits(void)
411 static char line[1000];
412 unsigned char sha1[20];
413 char last_hex[41];
414 int got_common = 0;
415 int got_other = 0;
416 int sent_ready = 0;
418 save_commit_buffer = 0;
420 for (;;) {
421 int len = packet_read_line(0, line, sizeof(line));
422 reset_timeout();
424 if (!len) {
425 if (multi_ack == 2 && got_common
426 && !got_other && ok_to_give_up()) {
427 sent_ready = 1;
428 packet_write(1, "ACK %s ready\n", last_hex);
430 if (have_obj.nr == 0 || multi_ack)
431 packet_write(1, "NAK\n");
433 if (no_done && sent_ready) {
434 packet_write(1, "ACK %s\n", last_hex);
435 return 0;
437 if (stateless_rpc)
438 exit(0);
439 got_common = 0;
440 got_other = 0;
441 continue;
443 if (!prefixcmp(line, "have ")) {
444 switch (got_sha1(line+5, sha1)) {
445 case -1: /* they have what we do not */
446 got_other = 1;
447 if (multi_ack && ok_to_give_up()) {
448 const char *hex = sha1_to_hex(sha1);
449 if (multi_ack == 2) {
450 sent_ready = 1;
451 packet_write(1, "ACK %s ready\n", hex);
452 } else
453 packet_write(1, "ACK %s continue\n", hex);
455 break;
456 default:
457 got_common = 1;
458 memcpy(last_hex, sha1_to_hex(sha1), 41);
459 if (multi_ack == 2)
460 packet_write(1, "ACK %s common\n", last_hex);
461 else if (multi_ack)
462 packet_write(1, "ACK %s continue\n", last_hex);
463 else if (have_obj.nr == 1)
464 packet_write(1, "ACK %s\n", last_hex);
465 break;
467 continue;
469 if (!strcmp(line, "done")) {
470 if (have_obj.nr > 0) {
471 if (multi_ack)
472 packet_write(1, "ACK %s\n", last_hex);
473 return 0;
475 packet_write(1, "NAK\n");
476 return -1;
478 die("git upload-pack: expected SHA1 list, got '%s'", line);
482 static void check_non_tip(void)
484 static const char *argv[] = {
485 "rev-list", "--stdin", NULL,
487 static struct child_process cmd;
488 struct object *o;
489 char namebuf[42]; /* ^ + SHA-1 + LF */
490 int i;
492 /* In the normal in-process case non-tip request can never happen */
493 if (!stateless_rpc)
494 goto error;
496 cmd.argv = argv;
497 cmd.git_cmd = 1;
498 cmd.no_stderr = 1;
499 cmd.in = -1;
500 cmd.out = -1;
502 if (start_command(&cmd))
503 goto error;
506 * If rev-list --stdin encounters an unknown commit, it
507 * terminates, which will cause SIGPIPE in the write loop
508 * below.
510 sigchain_push(SIGPIPE, SIG_IGN);
512 namebuf[0] = '^';
513 namebuf[41] = '\n';
514 for (i = get_max_object_index(); 0 < i; ) {
515 o = get_indexed_object(--i);
516 if (!o)
517 continue;
518 if (!(o->flags & OUR_REF))
519 continue;
520 memcpy(namebuf + 1, sha1_to_hex(o->sha1), 40);
521 if (write_in_full(cmd.in, namebuf, 42) < 0)
522 goto error;
524 namebuf[40] = '\n';
525 for (i = 0; i < want_obj.nr; i++) {
526 o = want_obj.objects[i].item;
527 if (o->flags & OUR_REF)
528 continue;
529 memcpy(namebuf, sha1_to_hex(o->sha1), 40);
530 if (write_in_full(cmd.in, namebuf, 41) < 0)
531 goto error;
533 close(cmd.in);
535 sigchain_pop(SIGPIPE);
538 * The commits out of the rev-list are not ancestors of
539 * our ref.
541 i = read_in_full(cmd.out, namebuf, 1);
542 if (i)
543 goto error;
544 close(cmd.out);
547 * rev-list may have died by encountering a bad commit
548 * in the history, in which case we do want to bail out
549 * even when it showed no commit.
551 if (finish_command(&cmd))
552 goto error;
554 /* All the non-tip ones are ancestors of what we advertised */
555 return;
557 error:
558 /* Pick one of them (we know there at least is one) */
559 for (i = 0; i < want_obj.nr; i++) {
560 o = want_obj.objects[i].item;
561 if (!(o->flags & OUR_REF))
562 die("git upload-pack: not our ref %s",
563 sha1_to_hex(o->sha1));
567 static void receive_needs(void)
569 struct object_array shallows = OBJECT_ARRAY_INIT;
570 static char line[1000];
571 int len, depth = 0;
572 int has_non_tip = 0;
574 shallow_nr = 0;
575 for (;;) {
576 struct object *o;
577 const char *features;
578 unsigned char sha1_buf[20];
579 len = packet_read_line(0, line, sizeof(line));
580 reset_timeout();
581 if (!len)
582 break;
584 if (!prefixcmp(line, "shallow ")) {
585 unsigned char sha1[20];
586 struct object *object;
587 if (get_sha1_hex(line + 8, sha1))
588 die("invalid shallow line: %s", line);
589 object = parse_object(sha1);
590 if (!object)
591 die("did not find object for %s", line);
592 if (object->type != OBJ_COMMIT)
593 die("invalid shallow object %s", sha1_to_hex(sha1));
594 if (!(object->flags & CLIENT_SHALLOW)) {
595 object->flags |= CLIENT_SHALLOW;
596 add_object_array(object, NULL, &shallows);
598 continue;
600 if (!prefixcmp(line, "deepen ")) {
601 char *end;
602 depth = strtol(line + 7, &end, 0);
603 if (end == line + 7 || depth <= 0)
604 die("Invalid deepen: %s", line);
605 continue;
607 if (prefixcmp(line, "want ") ||
608 get_sha1_hex(line+5, sha1_buf))
609 die("git upload-pack: protocol error, "
610 "expected to get sha, not '%s'", line);
612 features = line + 45;
614 if (parse_feature_request(features, "multi_ack_detailed"))
615 multi_ack = 2;
616 else if (parse_feature_request(features, "multi_ack"))
617 multi_ack = 1;
618 if (parse_feature_request(features, "no-done"))
619 no_done = 1;
620 if (parse_feature_request(features, "thin-pack"))
621 use_thin_pack = 1;
622 if (parse_feature_request(features, "ofs-delta"))
623 use_ofs_delta = 1;
624 if (parse_feature_request(features, "side-band-64k"))
625 use_sideband = LARGE_PACKET_MAX;
626 else if (parse_feature_request(features, "side-band"))
627 use_sideband = DEFAULT_PACKET_MAX;
628 if (parse_feature_request(features, "no-progress"))
629 no_progress = 1;
630 if (parse_feature_request(features, "include-tag"))
631 use_include_tag = 1;
633 o = lookup_object(sha1_buf);
634 if (!o)
635 die("git upload-pack: not our ref %s",
636 sha1_to_hex(sha1_buf));
637 if (!(o->flags & WANTED)) {
638 o->flags |= WANTED;
639 if (!(o->flags & OUR_REF))
640 has_non_tip = 1;
641 add_object_array(o, NULL, &want_obj);
646 * We have sent all our refs already, and the other end
647 * should have chosen out of them. When we are operating
648 * in the stateless RPC mode, however, their choice may
649 * have been based on the set of older refs advertised
650 * by another process that handled the initial request.
652 if (has_non_tip)
653 check_non_tip();
655 if (!use_sideband && daemon_mode)
656 no_progress = 1;
658 if (depth == 0 && shallows.nr == 0)
659 return;
660 if (depth > 0) {
661 struct commit_list *result = NULL, *backup = NULL;
662 int i;
663 if (depth == INFINITE_DEPTH)
664 for (i = 0; i < shallows.nr; i++) {
665 struct object *object = shallows.objects[i].item;
666 object->flags |= NOT_SHALLOW;
668 else
669 backup = result =
670 get_shallow_commits(&want_obj, depth,
671 SHALLOW, NOT_SHALLOW);
672 while (result) {
673 struct object *object = &result->item->object;
674 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
675 packet_write(1, "shallow %s",
676 sha1_to_hex(object->sha1));
677 register_shallow(object->sha1);
678 shallow_nr++;
680 result = result->next;
682 free_commit_list(backup);
683 for (i = 0; i < shallows.nr; i++) {
684 struct object *object = shallows.objects[i].item;
685 if (object->flags & NOT_SHALLOW) {
686 struct commit_list *parents;
687 packet_write(1, "unshallow %s",
688 sha1_to_hex(object->sha1));
689 object->flags &= ~CLIENT_SHALLOW;
690 /* make sure the real parents are parsed */
691 unregister_shallow(object->sha1);
692 object->parsed = 0;
693 if (parse_commit((struct commit *)object))
694 die("invalid commit");
695 parents = ((struct commit *)object)->parents;
696 while (parents) {
697 add_object_array(&parents->item->object,
698 NULL, &want_obj);
699 parents = parents->next;
701 add_object_array(object, NULL, &extra_edge_obj);
703 /* make sure commit traversal conforms to client */
704 register_shallow(object->sha1);
706 packet_flush(1);
707 } else
708 if (shallows.nr > 0) {
709 int i;
710 for (i = 0; i < shallows.nr; i++)
711 register_shallow(shallows.objects[i].item->sha1);
714 shallow_nr += shallows.nr;
715 free(shallows.objects);
718 /* return non-zero if the ref is hidden, otherwise 0 */
719 static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
721 struct object *o = lookup_unknown_object(sha1);
723 if (ref_is_hidden(refname))
724 return 1;
725 if (!o)
726 die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
727 o->flags |= OUR_REF;
728 return 0;
731 static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
733 static const char *capabilities = "multi_ack thin-pack side-band"
734 " side-band-64k ofs-delta shallow no-progress"
735 " include-tag multi_ack_detailed";
736 const char *refname_nons = strip_namespace(refname);
737 unsigned char peeled[20];
739 if (mark_our_ref(refname, sha1, flag, cb_data))
740 return 0;
742 if (capabilities)
743 packet_write(1, "%s %s%c%s%s agent=%s\n",
744 sha1_to_hex(sha1), refname_nons,
745 0, capabilities,
746 stateless_rpc ? " no-done" : "",
747 git_user_agent_sanitized());
748 else
749 packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons);
750 capabilities = NULL;
751 if (!peel_ref(refname, peeled))
752 packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
753 return 0;
756 static void upload_pack(void)
758 if (advertise_refs || !stateless_rpc) {
759 reset_timeout();
760 head_ref_namespaced(send_ref, NULL);
761 for_each_namespaced_ref(send_ref, NULL);
762 packet_flush(1);
763 } else {
764 head_ref_namespaced(mark_our_ref, NULL);
765 for_each_namespaced_ref(mark_our_ref, NULL);
767 if (advertise_refs)
768 return;
770 receive_needs();
771 if (want_obj.nr) {
772 get_common_commits();
773 create_pack_file();
777 static int upload_pack_config(const char *var, const char *value, void *unused)
779 return parse_hide_refs_config(var, value, "uploadpack");
782 int main(int argc, char **argv)
784 char *dir;
785 int i;
786 int strict = 0;
788 git_setup_gettext();
790 packet_trace_identity("upload-pack");
791 git_extract_argv0_path(argv[0]);
792 read_replace_refs = 0;
794 for (i = 1; i < argc; i++) {
795 char *arg = argv[i];
797 if (arg[0] != '-')
798 break;
799 if (!strcmp(arg, "--advertise-refs")) {
800 advertise_refs = 1;
801 continue;
803 if (!strcmp(arg, "--stateless-rpc")) {
804 stateless_rpc = 1;
805 continue;
807 if (!strcmp(arg, "--strict")) {
808 strict = 1;
809 continue;
811 if (!prefixcmp(arg, "--timeout=")) {
812 timeout = atoi(arg+10);
813 daemon_mode = 1;
814 continue;
816 if (!strcmp(arg, "--")) {
817 i++;
818 break;
822 if (i != argc-1)
823 usage(upload_pack_usage);
825 setup_path();
827 dir = argv[i];
829 if (!enter_repo(dir, strict))
830 die("'%s' does not appear to be a git repository", dir);
831 if (is_repository_shallow())
832 die("attempt to fetch/clone from a shallow repository");
833 git_config(upload_pack_config, NULL);
834 upload_pack();
835 return 0;