9 #include "fetch-pack.h"
11 #include "run-command.h"
12 #include "transport.h"
14 #include "prio-queue.h"
16 static int transfer_unpack_limit
= -1;
17 static int fetch_unpack_limit
= -1;
18 static int unpack_limit
= 100;
19 static int prefer_ofs_delta
= 1;
21 static int fetch_fsck_objects
= -1;
22 static int transfer_fsck_objects
= -1;
23 static int agent_supported
;
24 static struct lock_file shallow_lock
;
25 static const char *alternate_shallow_file
;
27 #define COMPLETE (1U << 0)
28 #define COMMON (1U << 1)
29 #define COMMON_REF (1U << 2)
30 #define SEEN (1U << 3)
31 #define POPPED (1U << 4)
36 * After sending this many "have"s if we do not get any new ACK , we
37 * give up traversing our history.
39 #define MAX_IN_VAIN 256
41 static struct prio_queue rev_list
= { compare_commits_by_commit_date
};
42 static int non_common_revs
, multi_ack
, use_sideband
, allow_tip_sha1_in_want
;
44 static void rev_list_push(struct commit
*commit
, int mark
)
46 if (!(commit
->object
.flags
& mark
)) {
47 commit
->object
.flags
|= mark
;
49 if (parse_commit(commit
))
52 prio_queue_put(&rev_list
, commit
);
54 if (!(commit
->object
.flags
& COMMON
))
59 static int rev_list_insert_ref(const char *refname
, const unsigned char *sha1
, int flag
, void *cb_data
)
61 struct object
*o
= deref_tag(parse_object(sha1
), refname
, 0);
63 if (o
&& o
->type
== OBJ_COMMIT
)
64 rev_list_push((struct commit
*)o
, SEEN
);
69 static int clear_marks(const char *refname
, const unsigned char *sha1
, int flag
, void *cb_data
)
71 struct object
*o
= deref_tag(parse_object(sha1
), refname
, 0);
73 if (o
&& o
->type
== OBJ_COMMIT
)
74 clear_commit_marks((struct commit
*)o
,
75 COMMON
| COMMON_REF
| SEEN
| POPPED
);
80 This function marks a rev and its ancestors as common.
81 In some cases, it is desirable to mark only the ancestors (for example
82 when only the server does not yet know that they are common).
85 static void mark_common(struct commit
*commit
,
86 int ancestors_only
, int dont_parse
)
88 if (commit
!= NULL
&& !(commit
->object
.flags
& COMMON
)) {
89 struct object
*o
= (struct object
*)commit
;
94 if (!(o
->flags
& SEEN
))
95 rev_list_push(commit
, SEEN
);
97 struct commit_list
*parents
;
99 if (!ancestors_only
&& !(o
->flags
& POPPED
))
101 if (!o
->parsed
&& !dont_parse
)
102 if (parse_commit(commit
))
105 for (parents
= commit
->parents
;
107 parents
= parents
->next
)
108 mark_common(parents
->item
, 0, dont_parse
);
114 Get the next rev to send, ignoring the common.
117 static const unsigned char *get_rev(void)
119 struct commit
*commit
= NULL
;
121 while (commit
== NULL
) {
123 struct commit_list
*parents
;
125 if (rev_list
.nr
== 0 || non_common_revs
== 0)
128 commit
= prio_queue_get(&rev_list
);
129 parse_commit(commit
);
130 parents
= commit
->parents
;
132 commit
->object
.flags
|= POPPED
;
133 if (!(commit
->object
.flags
& COMMON
))
136 if (commit
->object
.flags
& COMMON
) {
137 /* do not send "have", and ignore ancestors */
139 mark
= COMMON
| SEEN
;
140 } else if (commit
->object
.flags
& COMMON_REF
)
141 /* send "have", and ignore ancestors */
142 mark
= COMMON
| SEEN
;
144 /* send "have", also for its ancestors */
148 if (!(parents
->item
->object
.flags
& SEEN
))
149 rev_list_push(parents
->item
, mark
);
151 mark_common(parents
->item
, 1, 0);
152 parents
= parents
->next
;
156 return commit
->object
.sha1
;
167 static void consume_shallow_list(struct fetch_pack_args
*args
, int fd
)
169 if (args
->stateless_rpc
&& args
->depth
> 0) {
170 /* If we sent a depth we will get back "duplicate"
171 * shallow and unshallow commands every time there
172 * is a block of have lines exchanged.
175 while ((line
= packet_read_line(fd
, NULL
))) {
176 if (!prefixcmp(line
, "shallow "))
178 if (!prefixcmp(line
, "unshallow "))
180 die("git fetch-pack: expected shallow list");
185 struct write_shallow_data
{
187 int use_pack_protocol
;
191 static int write_one_shallow(const struct commit_graft
*graft
, void *cb_data
)
193 struct write_shallow_data
*data
= cb_data
;
194 const char *hex
= sha1_to_hex(graft
->sha1
);
196 if (data
->use_pack_protocol
)
197 packet_buf_write(data
->out
, "shallow %s", hex
);
199 strbuf_addstr(data
->out
, hex
);
200 strbuf_addch(data
->out
, '\n');
205 static int write_shallow_commits(struct strbuf
*out
, int use_pack_protocol
)
207 struct write_shallow_data data
;
209 data
.use_pack_protocol
= use_pack_protocol
;
211 for_each_commit_graft(write_one_shallow
, &data
);
215 static enum ack_type
get_ack(int fd
, unsigned char *result_sha1
)
218 char *line
= packet_read_line(fd
, &len
);
221 die("git fetch-pack: expected ACK/NAK, got EOF");
222 if (!strcmp(line
, "NAK"))
224 if (!prefixcmp(line
, "ACK ")) {
225 if (!get_sha1_hex(line
+4, result_sha1
)) {
228 if (strstr(line
+45, "continue"))
230 if (strstr(line
+45, "common"))
232 if (strstr(line
+45, "ready"))
237 die("git fetch_pack: expected ACK/NAK, got '%s'", line
);
240 static void send_request(struct fetch_pack_args
*args
,
241 int fd
, struct strbuf
*buf
)
243 if (args
->stateless_rpc
) {
244 send_sideband(fd
, -1, buf
->buf
, buf
->len
, LARGE_PACKET_MAX
);
247 write_or_die(fd
, buf
->buf
, buf
->len
);
250 static void insert_one_alternate_ref(const struct ref
*ref
, void *unused
)
252 rev_list_insert_ref(NULL
, ref
->old_sha1
, 0, NULL
);
255 #define INITIAL_FLUSH 16
256 #define PIPESAFE_FLUSH 32
257 #define LARGE_FLUSH 1024
259 static int next_flush(struct fetch_pack_args
*args
, int count
)
261 int flush_limit
= args
->stateless_rpc
? LARGE_FLUSH
: PIPESAFE_FLUSH
;
263 if (count
< flush_limit
)
266 count
+= flush_limit
;
270 static int find_common(struct fetch_pack_args
*args
,
271 int fd
[2], unsigned char *result_sha1
,
275 int count
= 0, flushes
= 0, flush_at
= INITIAL_FLUSH
, retval
;
276 const unsigned char *sha1
;
277 unsigned in_vain
= 0;
278 int got_continue
= 0;
280 struct strbuf req_buf
= STRBUF_INIT
;
281 size_t state_len
= 0;
283 if (args
->stateless_rpc
&& multi_ack
== 1)
284 die("--stateless-rpc requires multi_ack_detailed");
286 for_each_ref(clear_marks
, NULL
);
289 for_each_ref(rev_list_insert_ref
, NULL
);
290 for_each_alternate_ref(insert_one_alternate_ref
, NULL
);
293 for ( ; refs
; refs
= refs
->next
) {
294 unsigned char *remote
= refs
->old_sha1
;
295 const char *remote_hex
;
299 * If that object is complete (i.e. it is an ancestor of a
300 * local ref), we tell them we have it but do not have to
301 * tell them about its ancestors, which they already know
304 * We use lookup_object here because we are only
305 * interested in the case we *know* the object is
306 * reachable and we have already scanned it.
308 if (((o
= lookup_object(remote
)) != NULL
) &&
309 (o
->flags
& COMPLETE
)) {
313 remote_hex
= sha1_to_hex(remote
);
315 struct strbuf c
= STRBUF_INIT
;
316 if (multi_ack
== 2) strbuf_addstr(&c
, " multi_ack_detailed");
317 if (multi_ack
== 1) strbuf_addstr(&c
, " multi_ack");
318 if (no_done
) strbuf_addstr(&c
, " no-done");
319 if (use_sideband
== 2) strbuf_addstr(&c
, " side-band-64k");
320 if (use_sideband
== 1) strbuf_addstr(&c
, " side-band");
321 if (args
->use_thin_pack
) strbuf_addstr(&c
, " thin-pack");
322 if (args
->no_progress
) strbuf_addstr(&c
, " no-progress");
323 if (args
->include_tag
) strbuf_addstr(&c
, " include-tag");
324 if (prefer_ofs_delta
) strbuf_addstr(&c
, " ofs-delta");
325 if (agent_supported
) strbuf_addf(&c
, " agent=%s",
326 git_user_agent_sanitized());
327 packet_buf_write(&req_buf
, "want %s%s\n", remote_hex
, c
.buf
);
330 packet_buf_write(&req_buf
, "want %s\n", remote_hex
);
335 strbuf_release(&req_buf
);
340 if (is_repository_shallow())
341 write_shallow_commits(&req_buf
, 1);
343 packet_buf_write(&req_buf
, "deepen %d", args
->depth
);
344 packet_buf_flush(&req_buf
);
345 state_len
= req_buf
.len
;
347 if (args
->depth
> 0) {
349 unsigned char sha1
[20];
351 send_request(args
, fd
[1], &req_buf
);
352 while ((line
= packet_read_line(fd
[0], NULL
))) {
353 if (!prefixcmp(line
, "shallow ")) {
354 if (get_sha1_hex(line
+ 8, sha1
))
355 die("invalid shallow line: %s", line
);
356 register_shallow(sha1
);
359 if (!prefixcmp(line
, "unshallow ")) {
360 if (get_sha1_hex(line
+ 10, sha1
))
361 die("invalid unshallow line: %s", line
);
362 if (!lookup_object(sha1
))
363 die("object not found: %s", line
);
364 /* make sure that it is parsed as shallow */
365 if (!parse_object(sha1
))
366 die("error in object: %s", line
);
367 if (unregister_shallow(sha1
))
368 die("no shallow found: %s", line
);
371 die("expected shallow/unshallow, got %s", line
);
373 } else if (!args
->stateless_rpc
)
374 send_request(args
, fd
[1], &req_buf
);
376 if (!args
->stateless_rpc
) {
377 /* If we aren't using the stateless-rpc interface
378 * we don't need to retain the headers.
380 strbuf_setlen(&req_buf
, 0);
386 while ((sha1
= get_rev())) {
387 packet_buf_write(&req_buf
, "have %s\n", sha1_to_hex(sha1
));
389 fprintf(stderr
, "have %s\n", sha1_to_hex(sha1
));
391 if (flush_at
<= ++count
) {
394 packet_buf_flush(&req_buf
);
395 send_request(args
, fd
[1], &req_buf
);
396 strbuf_setlen(&req_buf
, state_len
);
398 flush_at
= next_flush(args
, count
);
401 * We keep one window "ahead" of the other side, and
402 * will wait for an ACK only on the next one
404 if (!args
->stateless_rpc
&& count
== INITIAL_FLUSH
)
407 consume_shallow_list(args
, fd
[0]);
409 ack
= get_ack(fd
[0], result_sha1
);
410 if (args
->verbose
&& ack
)
411 fprintf(stderr
, "got ack %d %s\n", ack
,
412 sha1_to_hex(result_sha1
));
422 struct commit
*commit
=
423 lookup_commit(result_sha1
);
425 die("invalid commit %s", sha1_to_hex(result_sha1
));
426 if (args
->stateless_rpc
428 && !(commit
->object
.flags
& COMMON
)) {
429 /* We need to replay the have for this object
430 * on the next RPC request so the peer knows
431 * it is in common with us.
433 const char *hex
= sha1_to_hex(result_sha1
);
434 packet_buf_write(&req_buf
, "have %s\n", hex
);
435 state_len
= req_buf
.len
;
437 mark_common(commit
, 0, 1);
441 if (ack
== ACK_ready
) {
442 clear_prio_queue(&rev_list
);
450 if (got_continue
&& MAX_IN_VAIN
< in_vain
) {
452 fprintf(stderr
, "giving up\n");
458 if (!got_ready
|| !no_done
) {
459 packet_buf_write(&req_buf
, "done\n");
460 send_request(args
, fd
[1], &req_buf
);
463 fprintf(stderr
, "done\n");
468 strbuf_release(&req_buf
);
470 consume_shallow_list(args
, fd
[0]);
471 while (flushes
|| multi_ack
) {
472 int ack
= get_ack(fd
[0], result_sha1
);
475 fprintf(stderr
, "got ack (%d) %s\n", ack
,
476 sha1_to_hex(result_sha1
));
484 /* it is no error to fetch into a completely empty repo */
485 return count
? retval
: 0;
488 static struct commit_list
*complete
;
490 static int mark_complete(const char *refname
, const unsigned char *sha1
, int flag
, void *cb_data
)
492 struct object
*o
= parse_object(sha1
);
494 while (o
&& o
->type
== OBJ_TAG
) {
495 struct tag
*t
= (struct tag
*) o
;
497 break; /* broken repository */
498 o
->flags
|= COMPLETE
;
499 o
= parse_object(t
->tagged
->sha1
);
501 if (o
&& o
->type
== OBJ_COMMIT
) {
502 struct commit
*commit
= (struct commit
*)o
;
503 if (!(commit
->object
.flags
& COMPLETE
)) {
504 commit
->object
.flags
|= COMPLETE
;
505 commit_list_insert(commit
, &complete
);
511 static void mark_recent_complete_commits(struct fetch_pack_args
*args
,
512 unsigned long cutoff
)
514 while (complete
&& cutoff
<= complete
->item
->date
) {
516 fprintf(stderr
, "Marking %s as complete\n",
517 sha1_to_hex(complete
->item
->object
.sha1
));
518 pop_most_recent_commit(&complete
, COMPLETE
);
522 static void filter_refs(struct fetch_pack_args
*args
,
524 struct ref
**sought
, int nr_sought
)
526 struct ref
*newlist
= NULL
;
527 struct ref
**newtail
= &newlist
;
528 struct ref
*ref
, *next
;
532 for (ref
= *refs
; ref
; ref
= next
) {
536 if (!memcmp(ref
->name
, "refs/", 5) &&
537 check_refname_format(ref
->name
+ 5, 0))
540 while (i
< nr_sought
) {
541 int cmp
= strcmp(ref
->name
, sought
[i
]->name
);
543 break; /* definitely do not have it */
545 keep
= 1; /* definitely have it */
546 sought
[i
]->matched
= 1;
552 if (!keep
&& args
->fetch_all
&&
553 (!args
->depth
|| prefixcmp(ref
->name
, "refs/tags/")))
559 newtail
= &ref
->next
;
565 /* Append unmatched requests to the list */
566 if (allow_tip_sha1_in_want
) {
567 for (i
= 0; i
< nr_sought
; i
++) {
571 if (get_sha1_hex(ref
->name
, ref
->old_sha1
))
577 newtail
= &ref
->next
;
583 static void mark_alternate_complete(const struct ref
*ref
, void *unused
)
585 mark_complete(NULL
, ref
->old_sha1
, 0, NULL
);
588 static int everything_local(struct fetch_pack_args
*args
,
590 struct ref
**sought
, int nr_sought
)
594 unsigned long cutoff
= 0;
596 save_commit_buffer
= 0;
598 for (ref
= *refs
; ref
; ref
= ref
->next
) {
601 if (!has_sha1_file(ref
->old_sha1
))
604 o
= parse_object(ref
->old_sha1
);
608 /* We already have it -- which may mean that we were
609 * in sync with the other side at some time after
610 * that (it is OK if we guess wrong here).
612 if (o
->type
== OBJ_COMMIT
) {
613 struct commit
*commit
= (struct commit
*)o
;
614 if (!cutoff
|| cutoff
< commit
->date
)
615 cutoff
= commit
->date
;
620 for_each_ref(mark_complete
, NULL
);
621 for_each_alternate_ref(mark_alternate_complete
, NULL
);
622 commit_list_sort_by_date(&complete
);
624 mark_recent_complete_commits(args
, cutoff
);
628 * Mark all complete remote refs as common refs.
629 * Don't mark them common yet; the server has to be told so first.
631 for (ref
= *refs
; ref
; ref
= ref
->next
) {
632 struct object
*o
= deref_tag(lookup_object(ref
->old_sha1
),
635 if (!o
|| o
->type
!= OBJ_COMMIT
|| !(o
->flags
& COMPLETE
))
638 if (!(o
->flags
& SEEN
)) {
639 rev_list_push((struct commit
*)o
, COMMON_REF
| SEEN
);
641 mark_common((struct commit
*)o
, 1, 1);
645 filter_refs(args
, refs
, sought
, nr_sought
);
647 for (retval
= 1, ref
= *refs
; ref
; ref
= ref
->next
) {
648 const unsigned char *remote
= ref
->old_sha1
;
649 unsigned char local
[20];
652 o
= lookup_object(remote
);
653 if (!o
|| !(o
->flags
& COMPLETE
)) {
658 "want %s (%s)\n", sha1_to_hex(remote
),
663 hashcpy(ref
->new_sha1
, local
);
667 "already have %s (%s)\n", sha1_to_hex(remote
),
673 static int sideband_demux(int in
, int out
, void *data
)
677 int ret
= recv_sideband("fetch-pack", xd
[0], out
);
682 static int get_pack(struct fetch_pack_args
*args
,
683 int xd
[2], char **pack_lockfile
)
686 const char *argv
[22];
690 int do_keep
= args
->keep_pack
;
691 struct child_process cmd
;
694 memset(&demux
, 0, sizeof(demux
));
696 /* xd[] is talking with upload-pack; subprocess reads from
697 * xd[0], spits out band#2 to stderr, and feeds us band#1
698 * through demux->out.
700 demux
.proc
= sideband_demux
;
703 if (start_async(&demux
))
704 die("fetch-pack: unable to fork off sideband"
710 memset(&cmd
, 0, sizeof(cmd
));
714 if (!args
->keep_pack
&& unpack_limit
) {
715 struct pack_header header
;
717 if (read_pack_header(demux
.out
, &header
))
718 die("protocol error: bad pack header");
719 snprintf(hdr_arg
, sizeof(hdr_arg
),
720 "--pack_header=%"PRIu32
",%"PRIu32
,
721 ntohl(header
.hdr_version
), ntohl(header
.hdr_entries
));
722 if (ntohl(header
.hdr_entries
) < unpack_limit
)
728 if (alternate_shallow_file
) {
729 *av
++ = "--shallow-file";
730 *av
++ = alternate_shallow_file
;
736 *av
++ = "index-pack";
738 if (!args
->quiet
&& !args
->no_progress
)
740 if (args
->use_thin_pack
)
741 *av
++ = "--fix-thin";
742 if (args
->lock_pack
|| unpack_limit
) {
743 int s
= sprintf(keep_arg
,
744 "--keep=fetch-pack %"PRIuMAX
" on ", (uintmax_t) getpid());
745 if (gethostname(keep_arg
+ s
, sizeof(keep_arg
) - s
))
746 strcpy(keep_arg
+ s
, "localhost");
749 if (args
->check_self_contained_and_connected
)
750 *av
++ = "--check-self-contained-and-connected";
753 *av
++ = "unpack-objects";
754 if (args
->quiet
|| args
->no_progress
)
756 args
->check_self_contained_and_connected
= 0;
760 if (fetch_fsck_objects
>= 0
762 : transfer_fsck_objects
>= 0
763 ? transfer_fsck_objects
770 if (start_command(&cmd
))
771 die("fetch-pack: unable to fork off %s", argv
[0]);
772 if (do_keep
&& pack_lockfile
) {
773 *pack_lockfile
= index_pack_lockfile(cmd
.out
);
777 ret
= finish_command(&cmd
);
778 if (!ret
|| (args
->check_self_contained_and_connected
&& ret
== 1))
779 args
->self_contained_and_connected
=
780 args
->check_self_contained_and_connected
&&
783 die("%s failed", argv
[0]);
784 if (use_sideband
&& finish_async(&demux
))
785 die("error in sideband demultiplexer");
789 static int cmp_ref_by_name(const void *a_
, const void *b_
)
791 const struct ref
*a
= *((const struct ref
**)a_
);
792 const struct ref
*b
= *((const struct ref
**)b_
);
793 return strcmp(a
->name
, b
->name
);
796 static void setup_alternate_shallow(void)
798 struct strbuf sb
= STRBUF_INIT
;
801 check_shallow_file_for_update();
802 fd
= hold_lock_file_for_update(&shallow_lock
, git_path("shallow"),
804 if (write_shallow_commits(&sb
, 0)) {
805 if (write_in_full(fd
, sb
.buf
, sb
.len
) != sb
.len
)
806 die_errno("failed to write to %s", shallow_lock
.filename
);
807 alternate_shallow_file
= shallow_lock
.filename
;
810 * is_repository_shallow() sees empty string as "no
813 alternate_shallow_file
= "";
817 static struct ref
*do_fetch_pack(struct fetch_pack_args
*args
,
819 const struct ref
*orig_ref
,
820 struct ref
**sought
, int nr_sought
,
821 char **pack_lockfile
)
823 struct ref
*ref
= copy_ref_list(orig_ref
);
824 unsigned char sha1
[20];
825 const char *agent_feature
;
828 sort_ref_list(&ref
, ref_compare_name
);
829 qsort(sought
, nr_sought
, sizeof(*sought
), cmp_ref_by_name
);
831 if (is_repository_shallow() && !server_supports("shallow"))
832 die("Server does not support shallow clients");
833 if (server_supports("multi_ack_detailed")) {
835 fprintf(stderr
, "Server supports multi_ack_detailed\n");
837 if (server_supports("no-done")) {
839 fprintf(stderr
, "Server supports no-done\n");
840 if (args
->stateless_rpc
)
844 else if (server_supports("multi_ack")) {
846 fprintf(stderr
, "Server supports multi_ack\n");
849 if (server_supports("side-band-64k")) {
851 fprintf(stderr
, "Server supports side-band-64k\n");
854 else if (server_supports("side-band")) {
856 fprintf(stderr
, "Server supports side-band\n");
859 if (server_supports("allow-tip-sha1-in-want")) {
861 fprintf(stderr
, "Server supports allow-tip-sha1-in-want\n");
862 allow_tip_sha1_in_want
= 1;
864 if (!server_supports("thin-pack"))
865 args
->use_thin_pack
= 0;
866 if (!server_supports("no-progress"))
867 args
->no_progress
= 0;
868 if (!server_supports("include-tag"))
869 args
->include_tag
= 0;
870 if (server_supports("ofs-delta")) {
872 fprintf(stderr
, "Server supports ofs-delta\n");
874 prefer_ofs_delta
= 0;
876 if ((agent_feature
= server_feature_value("agent", &agent_len
))) {
878 if (args
->verbose
&& agent_len
)
879 fprintf(stderr
, "Server version is %.*s\n",
880 agent_len
, agent_feature
);
883 if (everything_local(args
, &ref
, sought
, nr_sought
)) {
887 if (find_common(args
, fd
, sha1
, ref
) < 0)
888 if (!args
->keep_pack
)
889 /* When cloning, it is not unusual to have
892 warning("no common commits");
894 if (args
->stateless_rpc
)
897 setup_alternate_shallow();
898 if (get_pack(args
, fd
, pack_lockfile
))
899 die("git fetch-pack: fetch failed.");
905 static int fetch_pack_config(const char *var
, const char *value
, void *cb
)
907 if (strcmp(var
, "fetch.unpacklimit") == 0) {
908 fetch_unpack_limit
= git_config_int(var
, value
);
912 if (strcmp(var
, "transfer.unpacklimit") == 0) {
913 transfer_unpack_limit
= git_config_int(var
, value
);
917 if (strcmp(var
, "repack.usedeltabaseoffset") == 0) {
918 prefer_ofs_delta
= git_config_bool(var
, value
);
922 if (!strcmp(var
, "fetch.fsckobjects")) {
923 fetch_fsck_objects
= git_config_bool(var
, value
);
927 if (!strcmp(var
, "transfer.fsckobjects")) {
928 transfer_fsck_objects
= git_config_bool(var
, value
);
932 return git_default_config(var
, value
, cb
);
935 static void fetch_pack_setup(void)
937 static int did_setup
;
940 git_config(fetch_pack_config
, NULL
);
941 if (0 <= transfer_unpack_limit
)
942 unpack_limit
= transfer_unpack_limit
;
943 else if (0 <= fetch_unpack_limit
)
944 unpack_limit
= fetch_unpack_limit
;
948 static int remove_duplicates_in_refs(struct ref
**ref
, int nr
)
950 struct string_list names
= STRING_LIST_INIT_NODUP
;
953 for (src
= dst
= 0; src
< nr
; src
++) {
954 struct string_list_item
*item
;
955 item
= string_list_insert(&names
, ref
[src
]->name
);
957 continue; /* already have it */
958 item
->util
= ref
[src
];
963 for (src
= dst
; src
< nr
; src
++)
965 string_list_clear(&names
, 0);
969 struct ref
*fetch_pack(struct fetch_pack_args
*args
,
970 int fd
[], struct child_process
*conn
,
971 const struct ref
*ref
,
973 struct ref
**sought
, int nr_sought
,
974 char **pack_lockfile
)
980 nr_sought
= remove_duplicates_in_refs(sought
, nr_sought
);
984 die("no matching remote head");
986 ref_cpy
= do_fetch_pack(args
, fd
, ref
, sought
, nr_sought
, pack_lockfile
);
988 if (alternate_shallow_file
) {
989 if (*alternate_shallow_file
== '\0') { /* --unshallow */
990 unlink_or_warn(git_path("shallow"));
991 rollback_lock_file(&shallow_lock
);
993 commit_lock_file(&shallow_lock
);
996 reprepare_packed_git();