environment: move zlib_compression_level into struct repo_config_values

The `zlib_compression_level` configuration is currently stored in the
global variable `zlib_compression_level`, which makes it shared across
repository instances within a single process.

Store it instead in `repo_config_values`, where eagerly‑parsed
repository configuration lives. `zlib_compression_level` is parsed
eagerly because it determines compression behaviour for objects and
packs – core operations where a lazy parse could lead to unpredictable
results and hinder libification. This preserves the existing
eager‑parsing behavior while tying the value to the repository it
was read from, avoiding cross‑repository state leakage and continuing
the effort to reduce reliance on global configuration state.

Update all references to use `repo_config_values()`.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Olamide Caleb Bello
2026-06-02 18:09:16 +01:00
committed by Junio C Hamano
parent 88505ed637
commit e0f86540ab
6 changed files with 12 additions and 8 deletions

View File

@@ -1416,8 +1416,9 @@ static int write_compressed(struct hashfile *f, void *in, unsigned int size)
git_zstream stream;
int status;
unsigned char outbuf[4096];
struct repo_config_values *cfg = repo_config_values(the_repository);
git_deflate_init(&stream, zlib_compression_level);
git_deflate_init(&stream, cfg->zlib_compression_level);
stream.next_in = in;
stream.avail_in = size;

3
diff.c
View File

@@ -3589,8 +3589,9 @@ static unsigned char *deflate_it(char *data,
int bound;
unsigned char *deflated;
git_zstream stream;
struct repo_config_values *cfg = repo_config_values(the_repository);
git_deflate_init(&stream, zlib_compression_level);
git_deflate_init(&stream, cfg->zlib_compression_level);
bound = git_deflate_bound(&stream, size);
deflated = xmalloc(bound);
stream.next_out = deflated;

View File

@@ -52,7 +52,6 @@ char *git_commit_encoding;
char *git_log_output_encoding;
char *apply_default_whitespace;
char *apply_default_ignorewhitespace;
int zlib_compression_level = Z_BEST_SPEED;
int pack_compression_level = Z_DEFAULT_COMPRESSION;
int fsync_object_files = -1;
int use_fsync = -1;
@@ -377,7 +376,7 @@ int git_default_core_config(const char *var, const char *value,
level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION)
die(_("bad zlib compression level %d"), level);
zlib_compression_level = level;
cfg->zlib_compression_level = level;
zlib_compression_seen = 1;
return 0;
}
@@ -389,7 +388,7 @@ int git_default_core_config(const char *var, const char *value,
else if (level < 0 || level > Z_BEST_COMPRESSION)
die(_("bad zlib compression level %d"), level);
if (!zlib_compression_seen)
zlib_compression_level = level;
cfg->zlib_compression_level = level;
if (!pack_compression_seen)
pack_compression_level = level;
return 0;
@@ -721,4 +720,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
cfg->branch_track = BRANCH_TRACK_REMOTE;
cfg->trust_ctime = 1;
cfg->check_stat = 1;
cfg->zlib_compression_level = Z_BEST_SPEED;
}

View File

@@ -93,6 +93,7 @@ struct repo_config_values {
int apply_sparse_checkout;
int trust_ctime;
int check_stat;
int zlib_compression_level;
/* section "branch" config values */
enum branch_track branch_track;
@@ -170,7 +171,6 @@ extern int assume_unchanged;
extern int warn_on_object_refname_ambiguity;
extern char *apply_default_whitespace;
extern char *apply_default_ignorewhitespace;
extern int zlib_compression_level;
extern int pack_compression_level;
extern unsigned long pack_size_limit_cfg;

View File

@@ -369,13 +369,14 @@ static void start_put(struct transfer_request *request)
int hdrlen;
ssize_t size;
git_zstream stream;
struct repo_config_values *cfg = repo_config_values(the_repository);
unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
&type, &len);
hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
/* Set it up */
git_deflate_init(&stream, zlib_compression_level);
git_deflate_init(&stream, cfg->zlib_compression_level);
size = git_deflate_bound(&stream, len + hdrlen);
strbuf_grow(&request->buffer.buf, size);
request->buffer.posn = 0;

View File

@@ -906,6 +906,7 @@ static int start_loose_object_common(struct odb_source *source,
const struct git_hash_algo *algo = source->odb->repo->hash_algo;
const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
int fd;
struct repo_config_values *cfg = repo_config_values(the_repository);
fd = create_tmpfile(source->odb->repo, tmp_file, filename);
if (fd < 0) {
@@ -921,7 +922,7 @@ static int start_loose_object_common(struct odb_source *source,
}
/* Setup zlib stream for compression */
git_deflate_init(stream, zlib_compression_level);
git_deflate_init(stream, cfg->zlib_compression_level);
stream->next_out = buf;
stream->avail_out = buflen;
algo->init_fn(c);