git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/8] environment: move `zlib_compression_level` into repo_config_values

From
Olamide Caleb Bello <belkid98@gmail.com>
Date
Mar 24, 2026, 12:37 UTC
Message-ID
<20260324123750.157143-4-belkid98@gmail.com>
In-Reply-To
<20260324123750.157143-1-belkid98@gmail.com>

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` so the value is associated with the repository from which it was read. This preserves existing behavior while avoiding cross-repository state leakage and continues 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>
---
 builtin/index-pack.c | 3 ++-
 diff.c               | 3 ++-
 environment.c        | 6 +++---
 environment.h        | 2 +-
 http-push.c          | 3 ++-
 object-file.c        | 3 ++-
 6 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index b67fb0256c..dd82eed76f 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -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 501648a5c4..4bc0297873 100644
--- a/diff.c
+++ b/diff.c
@@ -3365,8 +3365,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;
diff --git a/environment.c b/environment.c
index 8542ac3141..5b0e88b65c 100644
--- a/environment.c
+++ b/environment.c
@@ -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;
 }
diff --git a/environment.h b/environment.h
index 1d3e2e4f23..93201620af 100644
--- a/environment.h
+++ b/environment.h
@@ -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;
 
diff --git a/http-push.c b/http-push.c
index 9ae6062198..c6bf9ff387 100644
--- a/http-push.c
+++ b/http-push.c
@@ -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;
diff --git a/object-file.c b/object-file.c
index 3094140055..8b719a915c 100644
--- a/object-file.c
+++ b/object-file.c
@@ -891,6 +891,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) {
@@ -906,7 +907,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);
-- 
2.53.0.155.g9f36b15afa
Previous: Karthik NayakNext: Karthik Nayak
Message 11 of 72 in “repo_config_values: migrate more globals”
  1. 0/8 repo_config_values: migrate more globalsOlamide Caleb Bello, Mar 24, 2026
  2. 1/8 environment: move "trust_ctime" into `struct repo_config_values`Olamide Caleb Bello, Mar 24, 2026
  3. Karthik NayakApr 14, 2026
  4. Phillip WoodApr 14, 2026
  5. Junio C HamanoApr 14, 2026
  6. Karthik NayakApr 15, 2026
  7. Junio C HamanoApr 15, 2026
  8. Karthik NayakApr 15, 2026
  9. 2/8 environment: move "check_stat" into `struct repo_config_values`Olamide Caleb Bello, Mar 24, 2026
  10. Karthik NayakApr 14, 2026
  11. 3/8 environment: move `zlib_compression_level` into repo_config_valuesOlamide Caleb Bello, Mar 24, 2026
  12. Karthik NayakApr 14, 2026
  13. Bello OlamideApr 14, 2026
  14. 4/8 environment: move "pack_compression_level" into `struct repo_config_values`Olamide Caleb Bello, Mar 24, 2026
  15. 5/8 environment: move "precomposed_unicode" into `struct repo_config_values`Olamide Caleb Bello, Mar 24, 2026
  16. Karthik NayakApr 14, 2026
  17. 6/8 env: move "core_sparse_checkout_cone" into `struct repo_config_values`Olamide Caleb Bello, Mar 24, 2026
  18. 7/8 env: put "sparse_expect_files_outside_of_patterns" in `repo_config_values`Olamide Caleb Bello, Mar 24, 2026
  19. 8/8 env: move "warn_on_object_refname_ambiguity" into `repo_config_values`Olamide Caleb Bello, Mar 24, 2026
  20. Karthik NayakApr 14, 2026
  21. Bello OlamideApr 14, 2026
  22. 0/8 repo_config_values: migrate more globalsOlamide Caleb Bello, Apr 23, 2026
  23. 1/8 Revert "compat/posix: introduce writev(3p) wrapper"Olamide Caleb Bello, Apr 23, 2026
  24. 2/8 rust: we are way beyond 2.53Olamide Caleb Bello, Apr 23, 2026
  25. 3/8 doc: am: revert Message-ID trailer claimOlamide Caleb Bello, Apr 23, 2026
  26. 4/8 doc: am: correct to full --no-message-idOlamide Caleb Bello, Apr 23, 2026
  27. 5/8 CI: bump actions/checkout from 4 to 5 for rust-analysis jobOlamide Caleb Bello, Apr 23, 2026
  28. 6/8 gitglossary: fix indentation of sub-listsOlamide Caleb Bello, Apr 23, 2026
  29. 7/8 Hopefully the final tweak before -rc2Olamide Caleb Bello, Apr 23, 2026
  30. 8/8 Git 2.54-rc2Olamide Caleb Bello, Apr 23, 2026
  31. Bello OlamideApr 23, 2026
  32. 0/8 repo_config_values: migrate more globalsOlamide Caleb Bello, Jun 1, 2026
  33. 1/8 environment: move "trust_ctime" into `struct repo_config_values`Olamide Caleb Bello, Jun 1, 2026
  34. 2/8 environment: move "check_stat" into `struct repo_config_values`Olamide Caleb Bello, Jun 1, 2026
  35. 3/8 environment: move `zlib_compression_level` into `struct repo_config_values`Olamide Caleb Bello, Jun 1, 2026
  36. Junio C HamanoJun 2, 2026
  37. Patrick SteinhardtJun 2, 2026
  38. Christian CouderJun 2, 2026
  39. Junio C HamanoJun 2, 2026
  40. 4/8 environment: move "pack_compression_level" into `struct repo_config_values`Olamide Caleb Bello, Jun 1, 2026
  41. 5/8 environment: move "precomposed_unicode" into `struct repo_config_values`Olamide Caleb Bello, Jun 1, 2026
  42. Junio C HamanoJun 1, 2026
  43. 6/8 environment: move "core_sparse_checkout_cone" into `struct repo_config_values`Olamide Caleb Bello, Jun 1, 2026
  44. 7/8 environment: move "sparse_expect_files_outside_of_patterns" into `repo_config_values`Olamide Caleb Bello, Jun 1, 2026
  45. 8/8 environment: move "warn_on_object_refname_ambiguity" into `struct repo_config_values`Olamide Caleb Bello, Jun 1, 2026
  46. Junio C HamanoJun 2, 2026
  47. 0/8 repo_config_values: migrate more globals variablesOlamide Caleb Bello, Jun 2, 2026
  48. 1/8 environment: move "trust_ctime" into `struct repo_config_values`Olamide Caleb Bello, Jun 2, 2026
  49. 2/8 environment: move "check_stat" into `struct repo_config_values`Olamide Caleb Bello, Jun 2, 2026
  50. 3/8 environment: move `zlib_compression_level` into `struct repo_config_values`Olamide Caleb Bello, Jun 2, 2026
  51. 4/8 environment: move "pack_compression_level" into `struct repo_config_values`Olamide Caleb Bello, Jun 2, 2026
  52. 5/8 environment: move "precomposed_unicode" into `struct repo_config_values`Olamide Caleb Bello, Jun 2, 2026
  53. 6/8 environment: move "core_sparse_checkout_cone" into `struct repo_config_values`Olamide Caleb Bello, Jun 2, 2026
  54. 7/8 environment: move "sparse_expect_files_outside_of_patterns" into `struct repo_config_values`Olamide Caleb Bello, Jun 2, 2026
  55. 8/8 environment: move "warn_on_object_refname_ambiguity" into `struct repo_config_values`Olamide Caleb Bello, Jun 2, 2026
  56. 0/8 environment: move core config globals into repo_config_valuesOlamide Caleb Bello, Apr 23, 2026
  57. 1/8 environment: move "trust_ctime" into `struct repo_config_values`Olamide Caleb Bello, Apr 23, 2026
  58. Tian YuchenMay 21, 2026
  59. Bello OlamideJun 1, 2026
  60. 2/8 environment: move "check_stat" into `struct repo_config_values`Olamide Caleb Bello, Apr 23, 2026
  61. 3/8 environment: move `zlib_compression_level` into `struct repo_config_values`Olamide Caleb Bello, Apr 23, 2026
  62. 4/8 environment: move "pack_compression_level" into `struct repo_config_values`Olamide Caleb Bello, Apr 23, 2026
  63. 5/8 environment: move "precomposed_unicode" into `struct repo_config_values`Olamide Caleb Bello, Apr 23, 2026
  64. Tian YuchenMay 15, 2026
  65. 6/8 env: move "core_sparse_checkout_cone" into `struct repo_config_values`Olamide Caleb Bello, Apr 23, 2026
  66. 7/8 env: move "sparse_expect_files_outside_of_patterns" into `repo_config_values`Olamide Caleb Bello, Apr 23, 2026
  67. 8/8 env: move "warn_on_object_refname_ambiguity" into `struct repo_config_values`Olamide Caleb Bello, Apr 23, 2026
  68. Junio C HamanoApr 26, 2026
  69. Bello OlamideApr 26, 2026
  70. Junio C HamanoMay 11, 2026
  71. Junio C HamanoJun 1, 2026
  72. Junio C HamanoJun 1, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.