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>

Olamide Caleb Bello committed Jun 2, 2026 at 18:09 UTC e0f86540abd22a98c9701d21d06e75fa2c8d34a0
6 files changed +12 -8
builtin/index-pack.c
+2 -1
@@ -1416,8 +1416,9 @@ static int write_compressed(struct hashfile *f, void *in, unsigned int size)
1416 git_zstream stream;
1417 int status;
1418 unsigned char outbuf[4096];
1419 + struct repo_config_values *cfg = repo_config_values(the_repository);
1420
1420 - git_deflate_init(&stream, zlib_compression_level);
1421 + git_deflate_init(&stream, cfg->zlib_compression_level);
1422 stream.next_in = in;
1423 stream.avail_in = size;
1424
diff.c
+2 -1
@@ -3589,8 +3589,9 @@ static unsigned char *deflate_it(char *data,
3589 int bound;
3590 unsigned char *deflated;
3591 git_zstream stream;
3592 + struct repo_config_values *cfg = repo_config_values(the_repository);
3593
3593 - git_deflate_init(&stream, zlib_compression_level);
3594 + git_deflate_init(&stream, cfg->zlib_compression_level);
3595 bound = git_deflate_bound(&stream, size);
3596 deflated = xmalloc(bound);
3597 stream.next_out = deflated;
environment.c
+3 -3
@@ -52,7 +52,6 @@ char *git_commit_encoding;
52 char *git_log_output_encoding;
53 char *apply_default_whitespace;
54 char *apply_default_ignorewhitespace;
55 -int zlib_compression_level = Z_BEST_SPEED;
55 int pack_compression_level = Z_DEFAULT_COMPRESSION;
56 int fsync_object_files = -1;
57 int use_fsync = -1;
@@ -377,7 +376,7 @@ int git_default_core_config(const char *var, const char *value,
376 level = Z_DEFAULT_COMPRESSION;
377 else if (level < 0 || level > Z_BEST_COMPRESSION)
378 die(_("bad zlib compression level %d"), level);
380 - zlib_compression_level = level;
379 + cfg->zlib_compression_level = level;
380 zlib_compression_seen = 1;
381 return 0;
382 }
@@ -389,7 +388,7 @@ int git_default_core_config(const char *var, const char *value,
388 else if (level < 0 || level > Z_BEST_COMPRESSION)
389 die(_("bad zlib compression level %d"), level);
390 if (!zlib_compression_seen)
392 - zlib_compression_level = level;
391 + cfg->zlib_compression_level = level;
392 if (!pack_compression_seen)
393 pack_compression_level = level;
394 return 0;
@@ -721,4 +720,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
720 cfg->branch_track = BRANCH_TRACK_REMOTE;
721 cfg->trust_ctime = 1;
722 cfg->check_stat = 1;
723 + cfg->zlib_compression_level = Z_BEST_SPEED;
724 }
environment.h
+1 -1
@@ -93,6 +93,7 @@ struct repo_config_values {
93 int apply_sparse_checkout;
94 int trust_ctime;
95 int check_stat;
96 + int zlib_compression_level;
97
98 /* section "branch" config values */
99 enum branch_track branch_track;
@@ -170,7 +171,6 @@ extern int assume_unchanged;
171 extern int warn_on_object_refname_ambiguity;
172 extern char *apply_default_whitespace;
173 extern char *apply_default_ignorewhitespace;
173 -extern int zlib_compression_level;
174 extern int pack_compression_level;
175 extern unsigned long pack_size_limit_cfg;
176
http-push.c
+2 -1
@@ -369,13 +369,14 @@ static void start_put(struct transfer_request *request)
369 int hdrlen;
370 ssize_t size;
371 git_zstream stream;
372 + struct repo_config_values *cfg = repo_config_values(the_repository);
373
374 unpacked = odb_read_object(the_repository->objects, &request->obj->oid,
375 &type, &len);
376 hdrlen = format_object_header(hdr, sizeof(hdr), type, len);
377
378 /* Set it up */
378 - git_deflate_init(&stream, zlib_compression_level);
379 + git_deflate_init(&stream, cfg->zlib_compression_level);
380 size = git_deflate_bound(&stream, len + hdrlen);
381 strbuf_grow(&request->buffer.buf, size);
382 request->buffer.posn = 0;
object-file.c
+2 -1
@@ -906,6 +906,7 @@ static int start_loose_object_common(struct odb_source *source,
906 const struct git_hash_algo *algo = source->odb->repo->hash_algo;
907 const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
908 int fd;
909 + struct repo_config_values *cfg = repo_config_values(the_repository);
910
911 fd = create_tmpfile(source->odb->repo, tmp_file, filename);
912 if (fd < 0) {
@@ -921,7 +922,7 @@ static int start_loose_object_common(struct odb_source *source,
922 }
923
924 /* Setup zlib stream for compression */
924 - git_deflate_init(stream, zlib_compression_level);
925 + git_deflate_init(stream, cfg->zlib_compression_level);
926 stream->next_out = buf;
927 stream->avail_out = buflen;
928 algo->init_fn(c);