Skip to content

Commit

Permalink
Merge branch 'js/partial-clone-connectivity-check'
Browse files Browse the repository at this point in the history
During an initial "git clone --depth=..." partial clone, it is
pointless to spend cycles for a large portion of the connectivity
check that enumerates and skips promisor objects (which by
definition is all objects fetched from the other side).  This has
been optimized out.

* js/partial-clone-connectivity-check:
  t/perf: add perf script for partial clones
  clone: do faster object check for partial clones
  • Loading branch information
gitster committed May 13, 2019
2 parents 5b2d1c0 + 1bb10d4 commit 5b51f0d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
6 changes: 4 additions & 2 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ static void update_remote_refs(const struct ref *refs,
const char *branch_top,
const char *msg,
struct transport *transport,
int check_connectivity)
int check_connectivity,
int check_refs_only)
{
const struct ref *rm = mapped_refs;

Expand All @@ -669,6 +670,7 @@ static void update_remote_refs(const struct ref *refs,

opt.transport = transport;
opt.progress = transport->progress;
opt.check_refs_only = !!check_refs_only;

if (check_connected(iterate_ref_map, &rm, &opt))
die(_("remote did not send all necessary objects"));
Expand Down Expand Up @@ -1230,7 +1232,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)

update_remote_refs(refs, mapped_refs, remote_head_points_at,
branch_top.buf, reflog_msg.buf, transport,
!is_local);
!is_local, filter_options.choice);

update_head(our_head_points_at, remote_head, reflog_msg.buf);

Expand Down
17 changes: 17 additions & 0 deletions connected.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "cache.h"
#include "object-store.h"
#include "run-command.h"
#include "sigchain.h"
#include "connected.h"
Expand Down Expand Up @@ -49,6 +50,22 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
strbuf_release(&idx_file);
}

if (opt->check_refs_only) {
/*
* For partial clones, we don't want to have to do a regular
* connectivity check because we have to enumerate and exclude
* all promisor objects (slow), and then the connectivity check
* itself becomes a no-op because in a partial clone every
* object is a promisor object. Instead, just make sure we
* received the objects pointed to by each wanted ref.
*/
do {
if (!repo_has_object_file(the_repository, &oid))
return 1;
} while (!fn(cb_data, &oid));
return 0;
}

if (opt->shallow_file) {
argv_array_push(&rev_list.args, "--shallow-file");
argv_array_push(&rev_list.args, opt->shallow_file);
Expand Down
8 changes: 8 additions & 0 deletions connected.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ struct check_connected_options {
* during a fetch.
*/
unsigned is_deepening_fetch : 1;

/*
* If non-zero, only check the top-level objects referenced by the
* wanted refs (passed in as cb_data). This is useful for partial
* clones, where enumerating and excluding all promisor objects is very
* slow and the commit-walk itself becomes a no-op.
*/
unsigned check_refs_only : 1;
};

#define CHECK_CONNECTED_INIT { 0 }
Expand Down
26 changes: 26 additions & 0 deletions t/perf/p5600-partial-clone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

test_description='performance of partial clones'
. ./perf-lib.sh

test_perf_default_repo

test_expect_success 'enable server-side config' '
git config uploadpack.allowFilter true &&
git config uploadpack.allowAnySHA1InWant true
'

test_perf 'clone without blobs' '
rm -rf bare.git &&
git clone --no-local --bare --filter=blob:none . bare.git
'

test_perf 'checkout of result' '
rm -rf worktree &&
mkdir -p worktree/.git &&
tar -C bare.git -cf - . | tar -C worktree/.git -xf - &&
git -C worktree config core.bare false &&
git -C worktree checkout -f
'

test_done

0 comments on commit 5b51f0d

Please sign in to comment.