Skip to content

Commit

Permalink
fetch-pack: objects in our alternates are available to us
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Mar 17, 2011
1 parent 36cfda1 commit e52d719
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions builtin/fetch-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "run-command.h"
#include "transport.h"

static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
Expand Down Expand Up @@ -217,6 +218,16 @@ static void send_request(int fd, struct strbuf *buf)
safe_write(fd, buf->buf, buf->len);
}

static void insert_one_alternate_ref(const struct ref *ref, void *unused)
{
rev_list_insert_ref(NULL, ref->old_sha1, 0, NULL);
}

static void insert_alternate_refs(void)
{
foreach_alt_odb(refs_from_alternate_cb, insert_one_alternate_ref);
}

static int find_common(int fd[2], unsigned char *result_sha1,
struct ref *refs)
{
Expand All @@ -235,6 +246,7 @@ static int find_common(int fd[2], unsigned char *result_sha1,
marked = 1;

for_each_ref(rev_list_insert_ref, NULL);
insert_alternate_refs();

fetching = 0;
for ( ; refs ; refs = refs->next) {
Expand Down
2 changes: 1 addition & 1 deletion t/t5501-fetch-push-alternates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test_expect_success 'pushing into a repository with the same alternate' '
test_cmp one.count receiver.count
'

test_expect_failure 'fetching from a repository with the same alternate' '
test_expect_success 'fetching from a repository with the same alternate' '
(
cd fetcher &&
git fetch ../one master:refs/heads/it &&
Expand Down

0 comments on commit e52d719

Please sign in to comment.