9 #include "fetch-pack.h"
11 #include "run-command.h"
12 #include "transport.h"
15 static int transfer_unpack_limit = -1;
16 static int fetch_unpack_limit = -1;
17 static int unpack_limit = 100;
18 static int prefer_ofs_delta = 1;
20 static int fetch_fsck_objects = -1;
21 static int transfer_fsck_objects = -1;
22 static int agent_supported;
23 static struct fetch_pack_args args = {
24 /* .uploadpack = */ "git-upload-pack",
27 static const char fetch_pack_usage[] =
28 "git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] "
29 "[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] "
30 "[--no-progress] [-v] [<host>:]<directory> [<refs>...]";
32 #define COMPLETE (1U << 0)
33 #define COMMON (1U << 1)
34 #define COMMON_REF (1U << 2)
35 #define SEEN (1U << 3)
36 #define POPPED (1U << 4)
41 * After sending this many "have"s if we do not get any new ACK , we
42 * give up traversing our history.
44 #define MAX_IN_VAIN 256
46 static struct commit_list *rev_list;
47 static int non_common_revs, multi_ack, use_sideband;
49 static void rev_list_push(struct commit *commit, int mark)
51 if (!(commit->object.flags & mark)) {
52 commit->object.flags |= mark;
54 if (!(commit->object.parsed))
55 if (parse_commit(commit))
58 commit_list_insert_by_date(commit, &rev_list);
60 if (!(commit->object.flags & COMMON))
65 static int rev_list_insert_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
67 struct object *o = deref_tag(parse_object(sha1), refname, 0);
69 if (o && o->type == OBJ_COMMIT)
70 rev_list_push((struct commit *)o, SEEN);
75 static int clear_marks(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
77 struct object *o = deref_tag(parse_object(sha1), refname, 0);
79 if (o && o->type == OBJ_COMMIT)
80 clear_commit_marks((struct commit *)o,
81 COMMON | COMMON_REF | SEEN | POPPED);
86 This function marks a rev and its ancestors as common.
87 In some cases, it is desirable to mark only the ancestors (for example
88 when only the server does not yet know that they are common).
91 static void mark_common(struct commit *commit,
92 int ancestors_only, int dont_parse)
94 if (commit != NULL && !(commit->object.flags & COMMON)) {
95 struct object *o = (struct object *)commit;
100 if (!(o->flags & SEEN))
101 rev_list_push(commit, SEEN);
103 struct commit_list *parents;
105 if (!ancestors_only && !(o->flags & POPPED))
107 if (!o->parsed && !dont_parse)
108 if (parse_commit(commit))
111 for (parents = commit->parents;
113 parents = parents->next)
114 mark_common(parents->item, 0, dont_parse);
120 Get the next rev to send, ignoring the common.
123 static const unsigned char *get_rev(void)
125 struct commit *commit = NULL;
127 while (commit == NULL) {
129 struct commit_list *parents;
131 if (rev_list == NULL || non_common_revs == 0)
134 commit = rev_list->item;
135 if (!commit->object.parsed)
136 parse_commit(commit);
137 parents = commit->parents;
139 commit->object.flags |= POPPED;
140 if (!(commit->object.flags & COMMON))
143 if (commit->object.flags & COMMON) {
144 /* do not send "have", and ignore ancestors */
146 mark = COMMON | SEEN;
147 } else if (commit->object.flags & COMMON_REF)
148 /* send "have", and ignore ancestors */
149 mark = COMMON | SEEN;
151 /* send "have", also for its ancestors */
155 if (!(parents->item->object.flags & SEEN))
156 rev_list_push(parents->item, mark);
158 mark_common(parents->item, 1, 0);
159 parents = parents->next;
162 rev_list = rev_list->next;
165 return commit->object.sha1;
176 static void consume_shallow_list(int fd)
178 if (args.stateless_rpc && args.depth > 0) {
179 /* If we sent a depth we will get back "duplicate"
180 * shallow and unshallow commands every time there
181 * is a block of have lines exchanged.
184 while (packet_read_line(fd, line, sizeof(line))) {
185 if (!prefixcmp(line, "shallow "))
187 if (!prefixcmp(line, "unshallow "))
189 die("git fetch-pack: expected shallow list");
194 struct write_shallow_data {
196 int use_pack_protocol;
200 static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
202 struct write_shallow_data *data = cb_data;
203 const char *hex = sha1_to_hex(graft->sha1);
205 if (data->use_pack_protocol)
206 packet_buf_write(data->out, "shallow %s", hex);
208 strbuf_addstr(data->out, hex);
209 strbuf_addch(data->out, '\n');
214 static int write_shallow_commits(struct strbuf *out, int use_pack_protocol)
216 struct write_shallow_data data;
218 data.use_pack_protocol = use_pack_protocol;
220 for_each_commit_graft(write_one_shallow, &data);
224 static enum ack_type get_ack(int fd, unsigned char *result_sha1)
226 static char line[1000];
227 int len = packet_read_line(fd, line, sizeof(line));
230 die("git fetch-pack: expected ACK/NAK, got EOF");
231 if (line[len-1] == '\n')
233 if (!strcmp(line, "NAK"))
235 if (!prefixcmp(line, "ACK ")) {
236 if (!get_sha1_hex(line+4, result_sha1)) {
237 if (strstr(line+45, "continue"))
239 if (strstr(line+45, "common"))
241 if (strstr(line+45, "ready"))
246 die("git fetch_pack: expected ACK/NAK, got '%s'", line);
249 static void send_request(int fd, struct strbuf *buf)
251 if (args.stateless_rpc) {
252 send_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX);
255 safe_write(fd, buf->buf, buf->len);
258 static void insert_one_alternate_ref(const struct ref *ref, void *unused)
260 rev_list_insert_ref(NULL, ref->old_sha1, 0, NULL);
263 #define INITIAL_FLUSH 16
264 #define PIPESAFE_FLUSH 32
265 #define LARGE_FLUSH 1024
267 static int next_flush(int count)
269 int flush_limit = args.stateless_rpc ? LARGE_FLUSH : PIPESAFE_FLUSH;
271 if (count < flush_limit)
274 count += flush_limit;
278 static int find_common(int fd[2], unsigned char *result_sha1,
282 int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
283 const unsigned char *sha1;
284 unsigned in_vain = 0;
285 int got_continue = 0;
287 struct strbuf req_buf = STRBUF_INIT;
288 size_t state_len = 0;
290 if (args.stateless_rpc && multi_ack == 1)
291 die("--stateless-rpc requires multi_ack_detailed");
293 for_each_ref(clear_marks, NULL);
296 for_each_ref(rev_list_insert_ref, NULL);
297 for_each_alternate_ref(insert_one_alternate_ref, NULL);
300 for ( ; refs ; refs = refs->next) {
301 unsigned char *remote = refs->old_sha1;
302 const char *remote_hex;
306 * If that object is complete (i.e. it is an ancestor of a
307 * local ref), we tell them we have it but do not have to
308 * tell them about its ancestors, which they already know
311 * We use lookup_object here because we are only
312 * interested in the case we *know* the object is
313 * reachable and we have already scanned it.
315 if (((o = lookup_object(remote)) != NULL) &&
316 (o->flags & COMPLETE)) {
320 remote_hex = sha1_to_hex(remote);
322 struct strbuf c = STRBUF_INIT;
323 if (multi_ack == 2) strbuf_addstr(&c, " multi_ack_detailed");
324 if (multi_ack == 1) strbuf_addstr(&c, " multi_ack");
325 if (no_done) strbuf_addstr(&c, " no-done");
326 if (use_sideband == 2) strbuf_addstr(&c, " side-band-64k");
327 if (use_sideband == 1) strbuf_addstr(&c, " side-band");
328 if (args.use_thin_pack) strbuf_addstr(&c, " thin-pack");
329 if (args.no_progress) strbuf_addstr(&c, " no-progress");
330 if (args.include_tag) strbuf_addstr(&c, " include-tag");
331 if (prefer_ofs_delta) strbuf_addstr(&c, " ofs-delta");
332 if (agent_supported) strbuf_addf(&c, " agent=%s",
333 git_user_agent_sanitized());
334 packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
337 packet_buf_write(&req_buf, "want %s\n", remote_hex);
342 strbuf_release(&req_buf);
347 if (is_repository_shallow())
348 write_shallow_commits(&req_buf, 1);
350 packet_buf_write(&req_buf, "deepen %d", args.depth);
351 packet_buf_flush(&req_buf);
352 state_len = req_buf.len;
354 if (args.depth > 0) {
356 unsigned char sha1[20];
358 send_request(fd[1], &req_buf);
359 while (packet_read_line(fd[0], line, sizeof(line))) {
360 if (!prefixcmp(line, "shallow ")) {
361 if (get_sha1_hex(line + 8, sha1))
362 die("invalid shallow line: %s", line);
363 register_shallow(sha1);
366 if (!prefixcmp(line, "unshallow ")) {
367 if (get_sha1_hex(line + 10, sha1))
368 die("invalid unshallow line: %s", line);
369 if (!lookup_object(sha1))
370 die("object not found: %s", line);
371 /* make sure that it is parsed as shallow */
372 if (!parse_object(sha1))
373 die("error in object: %s", line);
374 if (unregister_shallow(sha1))
375 die("no shallow found: %s", line);
378 die("expected shallow/unshallow, got %s", line);
380 } else if (!args.stateless_rpc)
381 send_request(fd[1], &req_buf);
383 if (!args.stateless_rpc) {
384 /* If we aren't using the stateless-rpc interface
385 * we don't need to retain the headers.
387 strbuf_setlen(&req_buf, 0);
393 while ((sha1 = get_rev())) {
394 packet_buf_write(&req_buf, "have %s\n", sha1_to_hex(sha1));
396 fprintf(stderr, "have %s\n", sha1_to_hex(sha1));
398 if (flush_at <= ++count) {
401 packet_buf_flush(&req_buf);
402 send_request(fd[1], &req_buf);
403 strbuf_setlen(&req_buf, state_len);
405 flush_at = next_flush(count);
408 * We keep one window "ahead" of the other side, and
409 * will wait for an ACK only on the next one
411 if (!args.stateless_rpc && count == INITIAL_FLUSH)
414 consume_shallow_list(fd[0]);
416 ack = get_ack(fd[0], result_sha1);
417 if (args.verbose && ack)
418 fprintf(stderr, "got ack %d %s\n", ack,
419 sha1_to_hex(result_sha1));
429 struct commit *commit =
430 lookup_commit(result_sha1);
432 die("invalid commit %s", sha1_to_hex(result_sha1));
433 if (args.stateless_rpc
435 && !(commit->object.flags & COMMON)) {
436 /* We need to replay the have for this object
437 * on the next RPC request so the peer knows
438 * it is in common with us.
440 const char *hex = sha1_to_hex(result_sha1);
441 packet_buf_write(&req_buf, "have %s\n", hex);
442 state_len = req_buf.len;
444 mark_common(commit, 0, 1);
448 if (ack == ACK_ready) {
457 if (got_continue && MAX_IN_VAIN < in_vain) {
459 fprintf(stderr, "giving up\n");
465 if (!got_ready || !no_done) {
466 packet_buf_write(&req_buf, "done\n");
467 send_request(fd[1], &req_buf);
470 fprintf(stderr, "done\n");
475 strbuf_release(&req_buf);
477 consume_shallow_list(fd[0]);
478 while (flushes || multi_ack) {
479 int ack = get_ack(fd[0], result_sha1);
482 fprintf(stderr, "got ack (%d) %s\n", ack,
483 sha1_to_hex(result_sha1));
491 /* it is no error to fetch into a completely empty repo */
492 return count ? retval : 0;
495 static struct commit_list *complete;
497 static int mark_complete(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
499 struct object *o = parse_object(sha1);
501 while (o && o->type == OBJ_TAG) {
502 struct tag *t = (struct tag *) o;
504 break; /* broken repository */
505 o->flags |= COMPLETE;
506 o = parse_object(t->tagged->sha1);
508 if (o && o->type == OBJ_COMMIT) {
509 struct commit *commit = (struct commit *)o;
510 if (!(commit->object.flags & COMPLETE)) {
511 commit->object.flags |= COMPLETE;
512 commit_list_insert_by_date(commit, &complete);
518 static void mark_recent_complete_commits(unsigned long cutoff)
520 while (complete && cutoff <= complete->item->date) {
522 fprintf(stderr, "Marking %s as complete\n",
523 sha1_to_hex(complete->item->object.sha1));
524 pop_most_recent_commit(&complete, COMPLETE);
528 static int non_matching_ref(struct string_list_item *item, void *unused)
538 static void filter_refs(struct ref **refs, struct string_list *sought)
540 struct ref **return_refs;
541 struct ref *newlist = NULL;
542 struct ref **newtail = &newlist;
543 struct ref *ref, *next;
544 struct ref *fastarray[32];
547 if (sought->nr && !args.fetch_all) {
548 if (ARRAY_SIZE(fastarray) < sought->nr)
549 return_refs = xcalloc(sought->nr, sizeof(struct ref *));
551 return_refs = fastarray;
552 memset(return_refs, 0, sizeof(struct ref *) * sought->nr);
559 for (ref = *refs; ref; ref = next) {
561 if (!memcmp(ref->name, "refs/", 5) &&
562 check_refname_format(ref->name + 5, 0))
564 else if (args.fetch_all &&
565 (!args.depth || prefixcmp(ref->name, "refs/tags/") )) {
568 newtail = &ref->next;
573 while (sought_pos < sought->nr) {
574 cmp = strcmp(ref->name, sought->items[sought_pos].string);
575 if (cmp < 0) /* definitely do not have it */
577 else if (cmp == 0) { /* definitely have it */
578 return_refs[sought_pos] = ref;
579 sought->items[sought_pos++].util = "matched";
582 else /* might have it; keep looking */
586 continue; /* we will link it later */
591 if (!args.fetch_all) {
593 for (i = 0; i < sought->nr; i++) {
594 ref = return_refs[i];
598 newtail = &ref->next;
601 if (return_refs != fastarray)
603 filter_string_list(sought, 0, non_matching_ref, NULL);
608 static void mark_alternate_complete(const struct ref *ref, void *unused)
610 mark_complete(NULL, ref->old_sha1, 0, NULL);
613 static int everything_local(struct ref **refs, struct string_list *sought)
617 unsigned long cutoff = 0;
619 save_commit_buffer = 0;
621 for (ref = *refs; ref; ref = ref->next) {
624 o = parse_object(ref->old_sha1);
628 /* We already have it -- which may mean that we were
629 * in sync with the other side at some time after
630 * that (it is OK if we guess wrong here).
632 if (o->type == OBJ_COMMIT) {
633 struct commit *commit = (struct commit *)o;
634 if (!cutoff || cutoff < commit->date)
635 cutoff = commit->date;
640 for_each_ref(mark_complete, NULL);
641 for_each_alternate_ref(mark_alternate_complete, NULL);
643 mark_recent_complete_commits(cutoff);
647 * Mark all complete remote refs as common refs.
648 * Don't mark them common yet; the server has to be told so first.
650 for (ref = *refs; ref; ref = ref->next) {
651 struct object *o = deref_tag(lookup_object(ref->old_sha1),
654 if (!o || o->type != OBJ_COMMIT || !(o->flags & COMPLETE))
657 if (!(o->flags & SEEN)) {
658 rev_list_push((struct commit *)o, COMMON_REF | SEEN);
660 mark_common((struct commit *)o, 1, 1);
664 filter_refs(refs, sought);
666 for (retval = 1, ref = *refs; ref ; ref = ref->next) {
667 const unsigned char *remote = ref->old_sha1;
668 unsigned char local[20];
671 o = lookup_object(remote);
672 if (!o || !(o->flags & COMPLETE)) {
677 "want %s (%s)\n", sha1_to_hex(remote),
682 hashcpy(ref->new_sha1, local);
686 "already have %s (%s)\n", sha1_to_hex(remote),
692 static int sideband_demux(int in, int out, void *data)
696 int ret = recv_sideband("fetch-pack", xd[0], out);
701 static int get_pack(int xd[2], char **pack_lockfile)
704 const char *argv[20];
708 int do_keep = args.keep_pack;
709 struct child_process cmd;
711 memset(&demux, 0, sizeof(demux));
713 /* xd[] is talking with upload-pack; subprocess reads from
714 * xd[0], spits out band#2 to stderr, and feeds us band#1
715 * through demux->out.
717 demux.proc = sideband_demux;
720 if (start_async(&demux))
721 die("fetch-pack: unable to fork off sideband"
727 memset(&cmd, 0, sizeof(cmd));
731 if (!args.keep_pack && unpack_limit) {
732 struct pack_header header;
734 if (read_pack_header(demux.out, &header))
735 die("protocol error: bad pack header");
736 snprintf(hdr_arg, sizeof(hdr_arg),
737 "--pack_header=%"PRIu32",%"PRIu32,
738 ntohl(header.hdr_version), ntohl(header.hdr_entries));
739 if (ntohl(header.hdr_entries) < unpack_limit)
748 *av++ = "index-pack";
750 if (!args.quiet && !args.no_progress)
752 if (args.use_thin_pack)
753 *av++ = "--fix-thin";
754 if (args.lock_pack || unpack_limit) {
755 int s = sprintf(keep_arg,
756 "--keep=fetch-pack %"PRIuMAX " on ", (uintmax_t) getpid());
757 if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
758 strcpy(keep_arg + s, "localhost");
763 *av++ = "unpack-objects";
764 if (args.quiet || args.no_progress)
769 if (fetch_fsck_objects >= 0
771 : transfer_fsck_objects >= 0
772 ? transfer_fsck_objects
779 if (start_command(&cmd))
780 die("fetch-pack: unable to fork off %s", argv[0]);
781 if (do_keep && pack_lockfile) {
782 *pack_lockfile = index_pack_lockfile(cmd.out);
786 if (finish_command(&cmd))
787 die("%s failed", argv[0]);
788 if (use_sideband && finish_async(&demux))
789 die("error in sideband demultiplexer");
793 static struct ref *do_fetch_pack(int fd[2],
794 const struct ref *orig_ref,
795 struct string_list *sought,
796 char **pack_lockfile)
798 struct ref *ref = copy_ref_list(orig_ref);
799 unsigned char sha1[20];
800 const char *agent_feature;
803 sort_ref_list(&ref, ref_compare_name);
805 if (is_repository_shallow() && !server_supports("shallow"))
806 die("Server does not support shallow clients");
807 if (server_supports("multi_ack_detailed")) {
809 fprintf(stderr, "Server supports multi_ack_detailed\n");
811 if (server_supports("no-done")) {
813 fprintf(stderr, "Server supports no-done\n");
814 if (args.stateless_rpc)
818 else if (server_supports("multi_ack")) {
820 fprintf(stderr, "Server supports multi_ack\n");
823 if (server_supports("side-band-64k")) {
825 fprintf(stderr, "Server supports side-band-64k\n");
828 else if (server_supports("side-band")) {
830 fprintf(stderr, "Server supports side-band\n");
833 if (!server_supports("thin-pack"))
834 args.use_thin_pack = 0;
835 if (!server_supports("no-progress"))
836 args.no_progress = 0;
837 if (!server_supports("include-tag"))
838 args.include_tag = 0;
839 if (server_supports("ofs-delta")) {
841 fprintf(stderr, "Server supports ofs-delta\n");
843 prefer_ofs_delta = 0;
845 if ((agent_feature = server_feature_value("agent", &agent_len))) {
847 if (args.verbose && agent_len)
848 fprintf(stderr, "Server version is %.*s\n",
849 agent_len, agent_feature);
852 if (everything_local(&ref, sought)) {
856 if (find_common(fd, sha1, ref) < 0)
858 /* When cloning, it is not unusual to have
861 warning("no common commits");
863 if (args.stateless_rpc)
865 if (get_pack(fd, pack_lockfile))
866 die("git fetch-pack: fetch failed.");
872 static int fetch_pack_config(const char *var, const char *value, void *cb)
874 if (strcmp(var, "fetch.unpacklimit") == 0) {
875 fetch_unpack_limit = git_config_int(var, value);
879 if (strcmp(var, "transfer.unpacklimit") == 0) {
880 transfer_unpack_limit = git_config_int(var, value);
884 if (strcmp(var, "repack.usedeltabaseoffset") == 0) {
885 prefer_ofs_delta = git_config_bool(var, value);
889 if (!strcmp(var, "fetch.fsckobjects")) {
890 fetch_fsck_objects = git_config_bool(var, value);
894 if (!strcmp(var, "transfer.fsckobjects")) {
895 transfer_fsck_objects = git_config_bool(var, value);
899 return git_default_config(var, value, cb);
902 static struct lock_file lock;
904 static void fetch_pack_setup(void)
906 static int did_setup;
909 git_config(fetch_pack_config, NULL);
910 if (0 <= transfer_unpack_limit)
911 unpack_limit = transfer_unpack_limit;
912 else if (0 <= fetch_unpack_limit)
913 unpack_limit = fetch_unpack_limit;
917 int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
920 struct ref *ref = NULL;
921 const char *dest = NULL;
922 struct string_list sought = STRING_LIST_INIT_DUP;
924 char *pack_lockfile = NULL;
925 char **pack_lockfile_ptr = NULL;
926 struct child_process *conn;
928 packet_trace_identity("fetch-pack");
930 for (i = 1; i < argc && *argv[i] == '-'; i++) {
931 const char *arg = argv[i];
933 if (!prefixcmp(arg, "--upload-pack=")) {
934 args.uploadpack = arg + 14;
937 if (!prefixcmp(arg, "--exec=")) {
938 args.uploadpack = arg + 7;
941 if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
945 if (!strcmp("--keep", arg) || !strcmp("-k", arg)) {
946 args.lock_pack = args.keep_pack;
950 if (!strcmp("--thin", arg)) {
951 args.use_thin_pack = 1;
954 if (!strcmp("--include-tag", arg)) {
955 args.include_tag = 1;
958 if (!strcmp("--all", arg)) {
962 if (!strcmp("--stdin", arg)) {
966 if (!strcmp("-v", arg)) {
970 if (!prefixcmp(arg, "--depth=")) {
971 args.depth = strtol(arg + 8, NULL, 0);
974 if (!strcmp("--no-progress", arg)) {
975 args.no_progress = 1;
978 if (!strcmp("--stateless-rpc", arg)) {
979 args.stateless_rpc = 1;
982 if (!strcmp("--lock-pack", arg)) {
984 pack_lockfile_ptr = &pack_lockfile;
987 usage(fetch_pack_usage);
993 usage(fetch_pack_usage);
996 * Copy refs from cmdline to growable list, then append any
997 * refs from the standard input:
999 for (; i < argc; i++)
1000 string_list_append(&sought, xstrdup(argv[i]));
1001 if (args.stdin_refs) {
1002 if (args.stateless_rpc) {
1003 /* in stateless RPC mode we use pkt-line to read
1004 * from stdin, until we get a flush packet
1006 static char line[1000];
1008 int n = packet_read_line(0, line, sizeof(line));
1011 if (line[n-1] == '\n')
1013 string_list_append(&sought, xmemdupz(line, n));
1017 /* read from stdin one ref per line, until EOF */
1018 struct strbuf line = STRBUF_INIT;
1019 while (strbuf_getline(&line, stdin, '\n') != EOF)
1020 string_list_append(&sought, strbuf_detach(&line, NULL));
1021 strbuf_release(&line);
1025 if (args.stateless_rpc) {
1030 conn = git_connect(fd, dest, args.uploadpack,
1031 args.verbose ? CONNECT_VERBOSE : 0);
1034 get_remote_heads(fd[0], &ref, 0, NULL);
1036 ref = fetch_pack(&args, fd, conn, ref, dest,
1037 &sought, pack_lockfile_ptr);
1038 if (pack_lockfile) {
1039 printf("lock %s\n", pack_lockfile);
1044 if (finish_connect(conn))
1048 if (!ret && sought.nr) {
1049 /* If the heads to pull were given, we should have
1050 * consumed all of them by matching the remote.
1051 * Otherwise, 'git fetch remote no-such-ref' would
1052 * silently succeed without issuing an error.
1054 for (i = 0; i < sought.nr; i++)
1055 error("no such remote ref %s", sought.items[i].string);
1060 sha1_to_hex(ref->old_sha1), ref->name);
1067 struct ref *fetch_pack(struct fetch_pack_args *my_args,
1068 int fd[], struct child_process *conn,
1069 const struct ref *ref,
1071 struct string_list *sought,
1072 char **pack_lockfile)
1075 struct ref *ref_cpy;
1078 if (&args != my_args)
1079 memcpy(&args, my_args, sizeof(args));
1080 if (args.depth > 0) {
1081 if (stat(git_path("shallow"), &st))
1086 sort_string_list(sought);
1087 string_list_remove_duplicates(sought, 0);
1091 packet_flush(fd[1]);
1092 die("no matching remote head");
1094 ref_cpy = do_fetch_pack(fd, ref, sought, pack_lockfile);
1096 if (args.depth > 0) {
1097 struct cache_time mtime;
1098 struct strbuf sb = STRBUF_INIT;
1099 char *shallow = git_path("shallow");
1102 mtime.sec = st.st_mtime;
1103 mtime.nsec = ST_MTIME_NSEC(st);
1104 if (stat(shallow, &st)) {
1106 die("shallow file was removed during fetch");
1107 } else if (st.st_mtime != mtime.sec
1109 || ST_MTIME_NSEC(st) != mtime.nsec
1112 die("shallow file was changed during fetch");
1114 fd = hold_lock_file_for_update(&lock, shallow,
1116 if (!write_shallow_commits(&sb, 0)
1117 || write_in_full(fd, sb.buf, sb.len) != sb.len) {
1118 unlink_or_warn(shallow);
1119 rollback_lock_file(&lock);
1121 commit_lock_file(&lock);
1123 strbuf_release(&sb);
1126 reprepare_packed_git();