Skip to content

Commit 26b974b

Browse files
peffgitster
authored andcommitted
check_connected(): delay opening new_pack
In check_connected(), if the transport tells us we got a single packfile that has already been verified as self-contained and connected, then we can skip checking connectivity for any tips that are mentioned in that pack. This goes back to c6807a4 (clone: open a shortcut for connectivity check, 2013-05-26). We don't need to open that pack until we are about to start sending oids to our child rev-list process, since that's when we check whether they are in the self-contained pack. Let's push the opening of that pack further down in the function. That saves us from having to clean it up when we leave the function early (and by the time have opened the rev-list process, we never leave the function early, since we have to clean up the child process). Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 67ad421 commit 26b974b

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

connected.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,6 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
4545
return err;
4646
}
4747

48-
if (transport && transport->smart_options &&
49-
transport->smart_options->self_contained_and_connected &&
50-
transport->pack_lockfiles.nr == 1 &&
51-
strip_suffix(transport->pack_lockfiles.items[0].string,
52-
".keep", &base_len)) {
53-
struct strbuf idx_file = STRBUF_INIT;
54-
strbuf_add(&idx_file, transport->pack_lockfiles.items[0].string,
55-
base_len);
56-
strbuf_addstr(&idx_file, ".idx");
57-
new_pack = add_packed_git(the_repository, idx_file.buf,
58-
idx_file.len, 1);
59-
strbuf_release(&idx_file);
60-
}
61-
6248
if (repo_has_promisor_remote(the_repository)) {
6349
/*
6450
* For partial clones, we don't want to have to do a regular
@@ -90,7 +76,6 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
9076
promisor_pack_found:
9177
;
9278
} while ((oid = fn(cb_data)) != NULL);
93-
free(new_pack);
9479
return 0;
9580
}
9681

@@ -127,15 +112,27 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
127112
else
128113
rev_list.no_stderr = opt->quiet;
129114

130-
if (start_command(&rev_list)) {
131-
free(new_pack);
115+
if (start_command(&rev_list))
132116
return error(_("Could not run 'git rev-list'"));
133-
}
134117

135118
sigchain_push(SIGPIPE, SIG_IGN);
136119

137120
rev_list_in = xfdopen(rev_list.in, "w");
138121

122+
if (transport && transport->smart_options &&
123+
transport->smart_options->self_contained_and_connected &&
124+
transport->pack_lockfiles.nr == 1 &&
125+
strip_suffix(transport->pack_lockfiles.items[0].string,
126+
".keep", &base_len)) {
127+
struct strbuf idx_file = STRBUF_INIT;
128+
strbuf_add(&idx_file, transport->pack_lockfiles.items[0].string,
129+
base_len);
130+
strbuf_addstr(&idx_file, ".idx");
131+
new_pack = add_packed_git(the_repository, idx_file.buf,
132+
idx_file.len, 1);
133+
strbuf_release(&idx_file);
134+
}
135+
139136
do {
140137
/*
141138
* If index-pack already checked that:

0 commit comments

Comments
 (0)