From: Olamide Caleb Bello <belkid98@gmail.com>
To: git@vger.kernel.org
Cc: phillip.wood123@gmail.com, gitster@pobox.com,
christian.couder@gmail.com, usmanakinyemi202@gmail.com,
kaartic.sivaraam@gmail.com, me@ttaylorr.com,
karthik.188@gmail.com, Olamide Caleb Bello <belkid98@gmail.com>
Subject: [PATCH v2 4/8] environment: move "pack_compression_level" into `struct repo_config_values`
Date: Tue, 24 Mar 2026 13:37:46 +0100 [thread overview]
Message-ID: <20260324123750.157143-5-belkid98@gmail.com> (raw)
In-Reply-To: <20260324123750.157143-1-belkid98@gmail.com>
The `pack_compression_level` configuration is currently stored in the
global variable `pack_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 is another
step toward eliminating repository-dependent global 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/fast-import.c | 8 +++++---
builtin/pack-objects.c | 17 ++++++++++-------
environment.c | 8 +++++---
environment.h | 2 +-
object-file.c | 3 ++-
5 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b8a7757cfd..6475cdae85 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -963,6 +963,7 @@ static int store_object(
unsigned long hdrlen, deltalen;
struct git_hash_ctx c;
git_zstream s;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
hdrlen = format_object_header((char *)hdr, sizeof(hdr), type,
dat->len);
@@ -1001,7 +1002,7 @@ static int store_object(
} else
delta = NULL;
- git_deflate_init(&s, pack_compression_level);
+ git_deflate_init(&s, cfg->pack_compression_level);
if (delta) {
s.next_in = delta;
s.avail_in = deltalen;
@@ -1028,7 +1029,7 @@ static int store_object(
if (delta) {
FREE_AND_NULL(delta);
- git_deflate_init(&s, pack_compression_level);
+ git_deflate_init(&s, cfg->pack_compression_level);
s.next_in = (void *)dat->buf;
s.avail_in = dat->len;
s.avail_out = git_deflate_bound(&s, s.avail_in);
@@ -1111,6 +1112,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
struct git_hash_ctx c;
git_zstream s;
struct hashfile_checkpoint checkpoint;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
int status = Z_OK;
/* Determine if we should auto-checkpoint. */
@@ -1130,7 +1132,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
crc32_begin(pack_file);
- git_deflate_init(&s, pack_compression_level);
+ git_deflate_init(&s, cfg->pack_compression_level);
hdrlen = encode_in_pack_object_header(out_buf, out_sz, OBJ_BLOB, len);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index c1ee4d5ed7..7c5bc96916 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -383,8 +383,9 @@ static unsigned long do_compress(void **pptr, unsigned long size)
git_zstream stream;
void *in, *out;
unsigned long maxsize;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
- git_deflate_init(&stream, pack_compression_level);
+ git_deflate_init(&stream, cfg->pack_compression_level);
maxsize = git_deflate_bound(&stream, size);
in = *pptr;
@@ -410,8 +411,9 @@ static unsigned long write_large_blob_data(struct odb_read_stream *st, struct ha
unsigned char ibuf[1024 * 16];
unsigned char obuf[1024 * 16];
unsigned long olen = 0;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
- git_deflate_init(&stream, pack_compression_level);
+ git_deflate_init(&stream, cfg->pack_compression_level);
for (;;) {
ssize_t readlen;
@@ -4868,6 +4870,7 @@ int cmd_pack_objects(int argc,
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
struct list_objects_filter_options filter_options =
LIST_OBJECTS_FILTER_INIT;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
struct option pack_objects_options[] = {
OPT_CALLBACK_F('q', "quiet", &progress, NULL,
@@ -4951,7 +4954,7 @@ int cmd_pack_objects(int argc,
N_("ignore packs that have companion .keep file")),
OPT_STRING_LIST(0, "keep-pack", &keep_pack_list, N_("name"),
N_("ignore this pack")),
- OPT_INTEGER(0, "compression", &pack_compression_level,
+ OPT_INTEGER(0, "compression", &cfg->pack_compression_level,
N_("pack compression level")),
OPT_BOOL(0, "keep-true-parents", &grafts_keep_true_parents,
N_("do not hide commits by grafts")),
@@ -5110,10 +5113,10 @@ int cmd_pack_objects(int argc,
if (!reuse_object)
reuse_delta = 0;
- if (pack_compression_level == -1)
- pack_compression_level = Z_DEFAULT_COMPRESSION;
- else if (pack_compression_level < 0 || pack_compression_level > Z_BEST_COMPRESSION)
- die(_("bad pack compression level %d"), pack_compression_level);
+ if (cfg->pack_compression_level == -1)
+ cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
+ else if (cfg->pack_compression_level < 0 || cfg->pack_compression_level > Z_BEST_COMPRESSION)
+ die(_("bad pack compression level %d"), cfg->pack_compression_level);
if (!delta_search_threads) /* --threads=0 means autodetect */
delta_search_threads = online_cpus();
diff --git a/environment.c b/environment.c
index 5b0e88b65c..d0d3a4b7d2 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 pack_compression_level = Z_DEFAULT_COMPRESSION;
int fsync_object_files = -1;
int use_fsync = -1;
enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
@@ -390,7 +389,7 @@ int git_default_core_config(const char *var, const char *value,
if (!zlib_compression_seen)
cfg->zlib_compression_level = level;
if (!pack_compression_seen)
- pack_compression_level = level;
+ cfg->pack_compression_level = level;
return 0;
}
@@ -662,6 +661,8 @@ static int git_default_attr_config(const char *var, const char *value)
int git_default_config(const char *var, const char *value,
const struct config_context *ctx, void *cb)
{
+ struct repo_config_values *cfg = repo_config_values(the_repository);
+
if (starts_with(var, "core."))
return git_default_core_config(var, value, ctx, cb);
@@ -701,7 +702,7 @@ int git_default_config(const char *var, const char *value,
level = Z_DEFAULT_COMPRESSION;
else if (level < 0 || level > Z_BEST_COMPRESSION)
die(_("bad pack compression level %d"), level);
- pack_compression_level = level;
+ cfg->pack_compression_level = level;
pack_compression_seen = 1;
return 0;
}
@@ -721,4 +722,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
cfg->trust_ctime = 1;
cfg->check_stat = 1;
cfg->zlib_compression_level = Z_BEST_SPEED;
+ cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
}
diff --git a/environment.h b/environment.h
index 93201620af..514576b67a 100644
--- a/environment.h
+++ b/environment.h
@@ -94,6 +94,7 @@ struct repo_config_values {
int trust_ctime;
int check_stat;
int zlib_compression_level;
+ int pack_compression_level;
/* section "branch" config values */
enum branch_track branch_track;
@@ -171,7 +172,6 @@ extern int assume_unchanged;
extern int warn_on_object_refname_ambiguity;
extern char *apply_default_whitespace;
extern char *apply_default_ignorewhitespace;
-extern int pack_compression_level;
extern unsigned long pack_size_limit_cfg;
extern int precomposed_unicode;
diff --git a/object-file.c b/object-file.c
index 8b719a915c..87179fc667 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1420,8 +1420,9 @@ static int stream_blob_to_pack(struct transaction_packfile *state,
int status = Z_OK;
int write_object = (flags & INDEX_WRITE_OBJECT);
off_t offset = 0;
+ struct repo_config_values *cfg = repo_config_values(the_repository);
- git_deflate_init(&s, pack_compression_level);
+ git_deflate_init(&s, cfg->pack_compression_level);
hdrlen = encode_in_pack_object_header(obuf, sizeof(obuf), OBJ_BLOB, size);
s.next_out = obuf + hdrlen;
--
2.53.0.155.g9f36b15afa
next prev parent reply other threads:[~2026-03-24 12:39 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 12:37 [PATCH v2 0/8] repo_config_values: migrate more globals Olamide Caleb Bello
2026-03-24 12:37 ` [PATCH v2 1/8] environment: move "trust_ctime" into `struct repo_config_values` Olamide Caleb Bello
2026-04-14 8:52 ` Karthik Nayak
2026-04-14 9:35 ` Phillip Wood
2026-04-14 17:15 ` Junio C Hamano
2026-04-15 11:16 ` Karthik Nayak
2026-04-15 15:49 ` Junio C Hamano
2026-04-15 19:09 ` Karthik Nayak
2026-03-24 12:37 ` [PATCH v2 2/8] environment: move "check_stat" " Olamide Caleb Bello
2026-04-14 8:55 ` Karthik Nayak
2026-03-24 12:37 ` [PATCH v2 3/8] environment: move `zlib_compression_level` into repo_config_values Olamide Caleb Bello
2026-04-14 8:58 ` Karthik Nayak
2026-04-14 14:32 ` Bello Olamide
2026-03-24 12:37 ` Olamide Caleb Bello [this message]
2026-03-24 12:37 ` [PATCH v2 5/8] environment: move "precomposed_unicode" into `struct repo_config_values` Olamide Caleb Bello
2026-04-14 9:07 ` Karthik Nayak
2026-03-24 12:37 ` [PATCH v2 6/8] env: move "core_sparse_checkout_cone" " Olamide Caleb Bello
2026-03-24 12:37 ` [PATCH v2 7/8] env: put "sparse_expect_files_outside_of_patterns" in `repo_config_values` Olamide Caleb Bello
2026-03-24 12:37 ` [PATCH v2 8/8] env: move "warn_on_object_refname_ambiguity" into `repo_config_values` Olamide Caleb Bello
2026-04-14 9:10 ` [PATCH v2 0/8] repo_config_values: migrate more globals Karthik Nayak
2026-04-14 14:26 ` Bello Olamide
2026-04-23 16:08 ` [PATCH v3 " Olamide Caleb Bello
2026-04-23 16:08 ` [PATCH v3 1/8] Revert "compat/posix: introduce writev(3p) wrapper" Olamide Caleb Bello
2026-04-23 16:08 ` [PATCH v3 2/8] rust: we are way beyond 2.53 Olamide Caleb Bello
2026-04-23 16:08 ` [PATCH v3 3/8] doc: am: revert Message-ID trailer claim Olamide Caleb Bello
2026-04-23 16:08 ` [PATCH v3 4/8] doc: am: correct to full --no-message-id Olamide Caleb Bello
2026-04-23 16:08 ` [PATCH v3 5/8] CI: bump actions/checkout from 4 to 5 for rust-analysis job Olamide Caleb Bello
2026-04-23 16:08 ` [PATCH v3 6/8] gitglossary: fix indentation of sub-lists Olamide Caleb Bello
2026-04-23 16:08 ` [PATCH v3 7/8] Hopefully the final tweak before -rc2 Olamide Caleb Bello
2026-04-23 16:08 ` [PATCH v3 8/8] Git 2.54-rc2 Olamide Caleb Bello
2026-04-23 16:37 ` [PATCH v3 0/8] repo_config_values: migrate more globals Bello Olamide
2026-04-23 16:54 ` [PATCH v3 0/8] environment: move core config globals into repo_config_values Olamide Caleb Bello
2026-04-23 16:54 ` [PATCH v3 1/8] environment: move "trust_ctime" into `struct repo_config_values` Olamide Caleb Bello
2026-04-23 16:54 ` [PATCH v3 2/8] environment: move "check_stat" " Olamide Caleb Bello
2026-04-23 16:54 ` [PATCH v3 3/8] environment: move `zlib_compression_level` " Olamide Caleb Bello
2026-04-23 16:54 ` [PATCH v3 4/8] environment: move "pack_compression_level" " Olamide Caleb Bello
2026-04-23 16:54 ` [PATCH v3 5/8] environment: move "precomposed_unicode" " Olamide Caleb Bello
2026-05-15 17:15 ` Tian Yuchen
2026-04-23 16:54 ` [PATCH v3 6/8] env: move "core_sparse_checkout_cone" " Olamide Caleb Bello
2026-04-23 16:54 ` [PATCH v3 7/8] env: move "sparse_expect_files_outside_of_patterns" into `repo_config_values` Olamide Caleb Bello
2026-04-23 16:54 ` [PATCH v3 8/8] env: move "warn_on_object_refname_ambiguity" into `struct repo_config_values` Olamide Caleb Bello
2026-04-26 0:01 ` [PATCH v3 0/8] environment: move core config globals into repo_config_values Junio C Hamano
2026-04-26 0:31 ` Bello Olamide
2026-05-11 2:56 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260324123750.157143-5-belkid98@gmail.com \
--to=belkid98@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=kaartic.sivaraam@gmail.com \
--cc=karthik.188@gmail.com \
--cc=me@ttaylorr.com \
--cc=phillip.wood123@gmail.com \
--cc=usmanakinyemi202@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.