Cheaper receive pack connectivity check by newren · Pull Request #2136 · gitgitgadget/git · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin/receive-pack.c
22 changes: 16 additions & 6 deletions connected.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
#include "sigchain.h"
#include "connected.h"
#include "transport.h"
#include "object-name.h"
#include "packfile.h"
#include "promisor-remote.h"

/*
* If we feed all the commits we want to verify to this command
*
* $ git rev-list --objects --stdin --not --all
* $ git rev-list --objects --stdin --not ${main_branches}
*
* and if it does not error out, that means everything reachable from
* these commits locally exists and is connected to our existing refs.
Expand Down Expand Up @@ -93,13 +94,22 @@ int check_connected(oid_iterate_fn fn, void *cb_data,
strvec_push(&rev_list.args, "--exclude-promisor-objects");
if (!opt->is_deepening_fetch) {
strvec_push(&rev_list.args, "--not");
if (opt->exclude_hidden_refs_section)
strvec_pushf(&rev_list.args, "--exclude-hidden=%s",
opt->exclude_hidden_refs_section);
strvec_push(&rev_list.args, "--all");
if (opt->use_toplevel_branches_for_reachability) {
struct object_id head_oid;
strvec_push(&rev_list.args, "--exclude=*/*");
strvec_push(&rev_list.args, "--branches");
if (!repo_get_oid(the_repository, "HEAD", &head_oid))
strvec_push(&rev_list.args, "HEAD");
} else {
if (opt->exclude_hidden_refs_section)
strvec_pushf(&rev_list.args, "--exclude-hidden=%s",
opt->exclude_hidden_refs_section);
strvec_push(&rev_list.args, "--all");
}
}
strvec_push(&rev_list.args, "--quiet");
strvec_push(&rev_list.args, "--alternate-refs");
if (!opt->use_toplevel_branches_for_reachability)
strvec_push(&rev_list.args, "--alternate-refs");
if (opt->progress)
strvec_pushf(&rev_list.args, "--progress=%s",
_("Checking connectivity"));
Expand Down
15 changes: 14 additions & 1 deletion connected.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,22 @@ struct check_connected_options {
/*
* If not NULL, use `--exclude-hidden=$section` to exclude all refs
* hidden via the `$section.hideRefs` config from the set of
* already-reachable refs.
* already-reachable refs; irrelevant if
* use_toplevel_branches_for_reachability is set.
*/
const char *exclude_hidden_refs_section;

/*
* If set, use only toplevel branches (and HEAD) for the
* reachability check, and skip the `--alternate-refs` stoppers
* that the fetch/clone code path relies on. This avoids the
* linear-in-refcount enumeration of every visible ref in
* repositories with many branches/tags (and the analogous
* expansion of the alternate's ref set in fork-network
* setups), at the cost of walking a little further into
* already-reachable history.
*/
unsigned use_toplevel_branches_for_reachability : 1;
};

#define CHECK_CONNECTED_INIT { 0 }
Expand Down
58 changes: 58 additions & 0 deletions t/t5410-receive-pack.sh
Loading