]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: move `zlib_compression_level` into `struct repo_config_values`
authorOlamide Caleb Bello <belkid98@gmail.com>
Thu, 23 Apr 2026 16:54:27 +0000 (17:54 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 25 Apr 2026 10:35:41 +0000 (19:35 +0900)
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>
builtin/index-pack.c
diff.c
environment.c
environment.h
http-push.c
object-file.c

index ca7784dc2c496978322f1d7a3469013e21368c5a..3942d3e0d04a5b0f938ce13b2a6f978690e435a1 100644 (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;
 
diff --git a/diff.c b/diff.c
index 397e38b41cc6fa5cd46a460c11902c0944047988..7d17b0bf3f71021da3048eb870d9b05caadf887f 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -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;
index 8542ac31413d5ba6bb0a385a39d183ed360c3bb5..5b0e88b65cf420fab9cfa48ac63007a1cb0797fb 100644 (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;
 }
index 1d3e2e4f230a15fa249c8f240ac9ae1c7327431f..93201620afc302b4c6d8b11d6f0194b4efcb957d 100644 (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;
 
index d143fe28455623b9dfec23f98a232d62a34ea9a5..8ac107a56e08be3ac13c5e8cdc0deac7d4094975 100644 (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;
index 2acc9522df2daa8c3b0155dc9ed410a722e4c855..7c122ac419829a239b29ffec78e30427f0e0b416 100644 (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);