Skip to content

Commit

Permalink
Merge branch 'ds/disable-replace-refs' into jch
Browse files Browse the repository at this point in the history
Introduce a mechanism to disable replace refs globally and per
repository.

* ds/disable-replace-refs:
  repository: create read_replace_refs setting
  replace-objects: create wrapper around setting
  repository: create disable_replace_refs()
  pack-bitmap.c: use commit boundary during bitmap traversal
  pack-bitmap.c: extract `fill_in_bitmap()`
  object: add object_array initializer helper function
  • Loading branch information
gitster committed Jun 13, 2023
2 parents a595a9e + 9c7d1b0 commit 2c8616b
Show file tree
Hide file tree
Showing 28 changed files with 395 additions and 71 deletions.
3 changes: 3 additions & 0 deletions Documentation/config/feature.txt
Expand Up @@ -14,6 +14,9 @@ feature.experimental::
+
* `fetch.negotiationAlgorithm=skipping` may improve fetch negotiation times by
skipping more commits at a time, reducing the number of round trips.
+
* `pack.useBitmapBoundaryTraversal=true` may improve bitmap traversal times by
walking fewer objects.

feature.manyFiles::
Enable config options that optimize for repos with many files in the
Expand Down
17 changes: 17 additions & 0 deletions Documentation/config/pack.txt
Expand Up @@ -123,6 +123,23 @@ pack.useBitmaps::
true. You should not generally need to turn this off unless
you are debugging pack bitmaps.

pack.useBitmapBoundaryTraversal::
When true, Git will use an experimental algorithm for computing
reachability queries with bitmaps. Instead of building up
complete bitmaps for all of the negated tips and then OR-ing
them together, consider negated tips with existing bitmaps as
additive (i.e. OR-ing them into the result if they exist,
ignoring them otherwise), and build up a bitmap at the boundary
instead.
+
When using this algorithm, Git may include too many objects as a result
of not opening up trees belonging to certain UNINTERESTING commits. This
inexactness matches the non-bitmap traversal algorithm.
+
In many cases, this can provide a speed-up over the exact algorithm,
particularly when there is poor bitmap coverage of the negated side of
the query.

pack.useSparse::
When true, git will default to using the '--sparse' option in
'git pack-objects' when the '--revs' option is present. This
Expand Down
2 changes: 1 addition & 1 deletion builtin/cat-file.c
Expand Up @@ -804,7 +804,7 @@ static int batch_objects(struct batch_options *opt)
if (repo_has_promisor_remote(the_repository))
warning("This repository uses promisor remotes. Some objects may not be loaded.");

read_replace_refs = 0;
disable_replace_refs();

cb.opt = opt;
cb.expand = &data;
Expand Down
2 changes: 1 addition & 1 deletion builtin/commit-graph.c
Expand Up @@ -325,7 +325,7 @@ int cmd_commit_graph(int argc, const char **argv, const char *prefix)

git_config(git_default_config, NULL);

read_replace_refs = 0;
disable_replace_refs();
save_commit_buffer = 0;

argc = parse_options(argc, argv, prefix, options,
Expand Down
2 changes: 1 addition & 1 deletion builtin/fsck.c
Expand Up @@ -931,7 +931,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
fetch_if_missing = 0;

errors_found = 0;
read_replace_refs = 0;
disable_replace_refs();
save_commit_buffer = 0;

argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
Expand Down
2 changes: 1 addition & 1 deletion builtin/index-pack.c
Expand Up @@ -1753,7 +1753,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)
if (argc == 2 && !strcmp(argv[1], "-h"))
usage(index_pack_usage);

read_replace_refs = 0;
disable_replace_refs();
fsck_options.walk = mark_link;

reset_pack_idx_option(&opts);
Expand Down
2 changes: 1 addition & 1 deletion builtin/pack-objects.c
Expand Up @@ -4284,7 +4284,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
if (DFS_NUM_STATES > (1 << OE_DFS_STATE_BITS))
BUG("too many dfs states, increase OE_DFS_STATE_BITS");

read_replace_refs = 0;
disable_replace_refs();

sparse = git_env_bool("GIT_TEST_PACK_SPARSE", -1);
if (the_repository->gitdir) {
Expand Down
2 changes: 1 addition & 1 deletion builtin/prune.c
Expand Up @@ -165,7 +165,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix)

expire = TIME_MAX;
save_commit_buffer = 0;
read_replace_refs = 0;
disable_replace_refs();
repo_init_revisions(the_repository, &revs, prefix);

argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
Expand Down
2 changes: 1 addition & 1 deletion builtin/replace.c
Expand Up @@ -567,7 +567,7 @@ int cmd_replace(int argc, const char **argv, const char *prefix)
OPT_END()
};

read_replace_refs = 0;
disable_replace_refs();
git_config(git_default_config, NULL);

argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0);
Expand Down
2 changes: 1 addition & 1 deletion builtin/unpack-objects.c
Expand Up @@ -608,7 +608,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix UNUSED)
int i;
struct object_id oid;

read_replace_refs = 0;
disable_replace_refs();

git_config(git_default_config, NULL);

Expand Down
2 changes: 1 addition & 1 deletion builtin/upload-pack.c
Expand Up @@ -36,7 +36,7 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
};

packet_trace_identity("upload-pack");
read_replace_refs = 0;
disable_replace_refs();

argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);

Expand Down
1 change: 1 addition & 0 deletions ci/run-build-and-tests.sh
Expand Up @@ -29,6 +29,7 @@ linux-TEST-vars)
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
export GIT_TEST_NO_WRITE_REV_INDEX=1
export GIT_TEST_CHECKOUT_WORKERS=2
export GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL=1
;;
linux-clang)
export GIT_TEST_DEFAULT_HASH=sha1
Expand Down
4 changes: 1 addition & 3 deletions commit-graph.c
Expand Up @@ -205,14 +205,12 @@ static struct commit_graph *alloc_commit_graph(void)
return g;
}

extern int read_replace_refs;

static int commit_graph_compatible(struct repository *r)
{
if (!r->gitdir)
return 0;

if (read_replace_refs) {
if (replace_refs_enabled(r)) {
prepare_replace_object(r);
if (hashmap_get_size(&r->objects->replace_map->map))
return 0;
Expand Down
5 changes: 0 additions & 5 deletions config.c
Expand Up @@ -1844,11 +1844,6 @@ static int git_default_core_config(const char *var, const char *value, void *cb)
return 0;
}

if (!strcmp(var, "core.usereplacerefs")) {
read_replace_refs = git_config_bool(var, value);
return 0;
}

/* Add other config variables here and to Documentation/config.txt. */
return platform_core_config(var, value, cb);
}
Expand Down
3 changes: 1 addition & 2 deletions environment.c
Expand Up @@ -63,7 +63,6 @@ const char *editor_program;
const char *askpass_program;
const char *excludes_file;
enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
int read_replace_refs = 1;
enum eol core_eol = EOL_UNSET;
int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
char *check_roundtrip_encoding = "SHIFT-JIS";
Expand Down Expand Up @@ -184,7 +183,7 @@ void setup_git_env(const char *git_dir)
strvec_clear(&to_free);

if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
read_replace_refs = 0;
disable_replace_refs();
replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
: "refs/replace/");
Expand Down
2 changes: 1 addition & 1 deletion git.c
Expand Up @@ -187,7 +187,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
if (envchanged)
*envchanged = 1;
} else if (!strcmp(cmd, "--no-replace-objects")) {
read_replace_refs = 0;
disable_replace_refs();
setenv(NO_REPLACE_OBJECTS_ENVIRONMENT, "1", 1);
if (envchanged)
*envchanged = 1;
Expand Down
2 changes: 1 addition & 1 deletion log-tree.c
Expand Up @@ -158,7 +158,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,

if (starts_with(refname, git_replace_ref_base)) {
struct object_id original_oid;
if (!read_replace_refs)
if (!replace_refs_enabled(the_repository))
return 0;
if (get_oid_hex(refname + strlen(git_replace_ref_base),
&original_oid)) {
Expand Down
6 changes: 6 additions & 0 deletions object.c
Expand Up @@ -357,6 +357,12 @@ void object_list_free(struct object_list **list)
*/
static char object_array_slopbuf[1];

void object_array_init(struct object_array *array)
{
struct object_array blank = OBJECT_ARRAY_INIT;
memcpy(array, &blank, sizeof(*array));
}

void add_object_array_with_path(struct object *obj, const char *name,
struct object_array *array,
unsigned mode, const char *path)
Expand Down
2 changes: 2 additions & 0 deletions object.h
Expand Up @@ -58,6 +58,8 @@ struct object_array {

#define OBJECT_ARRAY_INIT { 0 }

void object_array_init(struct object_array *array);

/*
* object flag allocation:
* revision.h: 0---------10 15 23------27
Expand Down

0 comments on commit 2c8616b

Please sign in to comment.