Skip to content

Commit e52d719

Browse files
committed
fetch-pack: objects in our alternates are available to us
Use the helper function split from the receiving end of "git push" to allow the same optimization on the receiving end of "git fetch". Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Shawn O. Pearce <spearce@spearce.org>
1 parent 36cfda1 commit e52d719

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builtin/fetch-pack.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "fetch-pack.h"
1010
#include "remote.h"
1111
#include "run-command.h"
12+
#include "transport.h"
1213

1314
static int transfer_unpack_limit = -1;
1415
static int fetch_unpack_limit = -1;
@@ -217,6 +218,16 @@ static void send_request(int fd, struct strbuf *buf)
217218
safe_write(fd, buf->buf, buf->len);
218219
}
219220

221+
static void insert_one_alternate_ref(const struct ref *ref, void *unused)
222+
{
223+
rev_list_insert_ref(NULL, ref->old_sha1, 0, NULL);
224+
}
225+
226+
static void insert_alternate_refs(void)
227+
{
228+
foreach_alt_odb(refs_from_alternate_cb, insert_one_alternate_ref);
229+
}
230+
220231
static int find_common(int fd[2], unsigned char *result_sha1,
221232
struct ref *refs)
222233
{
@@ -235,6 +246,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
235246
marked = 1;
236247

237248
for_each_ref(rev_list_insert_ref, NULL);
249+
insert_alternate_refs();
238250

239251
fetching = 0;
240252
for ( ; refs ; refs = refs->next) {

t/t5501-fetch-push-alternates.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test_expect_success 'pushing into a repository with the same alternate' '
5454
test_cmp one.count receiver.count
5555
'
5656

57-
test_expect_failure 'fetching from a repository with the same alternate' '
57+
test_expect_success 'fetching from a repository with the same alternate' '
5858
(
5959
cd fetcher &&
6060
git fetch ../one master:refs/heads/it &&

0 commit comments

Comments
 (0)