From: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH v2 03/12] pack-objects: widen delta-cache accounting to `size_t`
Date: Wed, 05 Aug 2026 16:14:30 +0000 [thread overview]
Message-ID: <5b54041bafca1de826ddb4466b3d5d8fcceba3af.1785946479.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2175.v2.git.1785946479.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>
These three are a single accounting tuple (the globals tracking
cumulative cached-delta bytes, plus the helper that compares them
against an incoming delta size) and are latently 32-bit on Windows where
`unsigned long` != `size_t`: a pack with many large cached deltas could
wrap silently.
The widening is internally consistent on its own: the additions and
subtractions against delta_cache_size already come from `size_t` sources
(`DELTA_SIZE()` returns `size_t`), and `delta_cacheable()`'s sole caller
in `try_delta()` still passes `unsigned long`, which promotes.
Prerequisite for dropping `try_delta()`'s `cast_size_t_to_ulong()`
shims, which becomes possible once 1create_delta()` and `diff_delta()`
are widened in a later commit.
Note: since `max_delta_cache_size` changes data type to `size_t`, a pair
of new helpers is introduced to parse config values of that type, too.
Assisted-by: Opus 4.7
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
builtin/pack-objects.c | 10 +++++-----
config.c | 9 +++++++++
config.h | 3 +++
parse.c | 9 +++++++++
parse.h | 1 +
5 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index e3760b3492..97246c69ae 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -260,8 +260,8 @@ static int exclude_promisor_objects_best_effort;
static int use_delta_islands;
-static unsigned long delta_cache_size = 0;
-static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
+static size_t delta_cache_size = 0;
+static size_t max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE;
static unsigned long cache_max_small_delta_size = 1000;
static unsigned long window_memory_limit = 0;
@@ -2688,8 +2688,8 @@ struct unpacked {
unsigned depth;
};
-static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
- unsigned long delta_size)
+static int delta_cacheable(size_t src_size, size_t trg_size,
+ size_t delta_size)
{
if (max_delta_cache_size && delta_cache_size + delta_size > max_delta_cache_size)
return 0;
@@ -3701,7 +3701,7 @@ static int git_pack_config(const char *k, const char *v,
return 0;
}
if (!strcmp(k, "pack.deltacachesize")) {
- max_delta_cache_size = git_config_int(k, v, ctx->kvi);
+ max_delta_cache_size = git_config_size_t(k, v, ctx->kvi);
return 0;
}
if (!strcmp(k, "pack.deltacachelimit")) {
diff --git a/config.c b/config.c
index 6a0de86e3a..010a58d307 100644
--- a/config.c
+++ b/config.c
@@ -1268,6 +1268,15 @@ ssize_t git_config_ssize_t(const char *name, const char *value,
return ret;
}
+size_t git_config_size_t(const char *name, const char *value,
+ const struct key_value_info *kvi)
+{
+ size_t ret;
+ if (!git_parse_size_t(value, &ret))
+ die_bad_number(name, value, kvi);
+ return ret;
+}
+
double git_config_double(const char *name, const char *value,
const struct key_value_info *kvi)
{
diff --git a/config.h b/config.h
index 31fe3e2961..b66dd08007 100644
--- a/config.h
+++ b/config.h
@@ -282,6 +282,9 @@ unsigned long git_config_ulong(const char *, const char *,
ssize_t git_config_ssize_t(const char *, const char *,
const struct key_value_info *);
+size_t git_config_size_t(const char *, const char *,
+ const struct key_value_info *);
+
/**
* Identically to `git_config_double`, but for double-precision floating point
* values.
diff --git a/parse.c b/parse.c
index d77f28046a..266bbd539b 100644
--- a/parse.c
+++ b/parse.c
@@ -134,6 +134,15 @@ int git_parse_ssize_t(const char *value, ssize_t *ret)
return 1;
}
+int git_parse_size_t(const char *value, size_t *ret)
+{
+ uintmax_t tmp;
+ if (!git_parse_unsigned(value, &tmp, maximum_signed_value_of_type(size_t)))
+ return 0;
+ *ret = tmp;
+ return 1;
+}
+
int git_parse_double(const char *value, double *ret)
{
char *end;
diff --git a/parse.h b/parse.h
index a6dd37c4cb..db742f35fb 100644
--- a/parse.h
+++ b/parse.h
@@ -4,6 +4,7 @@
int git_parse_signed(const char *value, intmax_t *ret, intmax_t max);
int git_parse_unsigned(const char *value, uintmax_t *ret, uintmax_t max);
int git_parse_ssize_t(const char *, ssize_t *);
+int git_parse_size_t(const char *, size_t *);
int git_parse_ulong(const char *, unsigned long *);
int git_parse_uint(const char *value, unsigned int *ret);
int git_parse_int(const char *value, int *ret);
--
gitgitgadget
next prev parent reply other threads:[~2026-08-05 16:14 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 16:49 [PATCH 00/12] Next size_t stop: pack-objects/delta Johannes Schindelin via GitGitGadget
2026-07-09 16:49 ` [PATCH 01/12] diff-delta: widen `struct delta_index`' size fields to `size_t` Johannes Schindelin via GitGitGadget
2026-08-05 9:22 ` Patrick Steinhardt
2026-08-05 13:51 ` Johannes Schindelin
2026-07-09 16:49 ` [PATCH 02/12] delta: widen `create_delta_index()` parameter " Johannes Schindelin via GitGitGadget
2026-07-09 16:49 ` [PATCH 03/12] pack-objects: widen delta-cache accounting " Johannes Schindelin via GitGitGadget
2026-08-05 9:23 ` Patrick Steinhardt
2026-08-05 13:52 ` Johannes Schindelin
2026-07-09 16:49 ` [PATCH 04/12] pack-objects: widen `free_unpacked()` return " Johannes Schindelin via GitGitGadget
2026-08-05 9:23 ` Patrick Steinhardt
2026-07-09 16:49 ` [PATCH 05/12] pack-objects: widen `mem_usage` and `try_delta()`'s out-param " Johannes Schindelin via GitGitGadget
2026-07-09 16:49 ` [PATCH 06/12] delta: widen `create_delta()` and `diff_delta()` " Johannes Schindelin via GitGitGadget
2026-08-05 9:23 ` Patrick Steinhardt
2026-07-09 16:49 ` [PATCH 07/12] packfile, git-zlib: widen `use_pack()` and zstream avail fields " Johannes Schindelin via GitGitGadget
2026-07-09 16:49 ` [PATCH 08/12] archive-zip: widen `zlib_deflate_raw()`'s maxsize local " Johannes Schindelin via GitGitGadget
2026-07-09 16:49 ` [PATCH 09/12] diff: widen `deflate_it()`'s bound local from int " Johannes Schindelin via GitGitGadget
2026-07-09 16:49 ` [PATCH 10/12] http-push: widen `start_put()`'s size local from `ssize_t` " Johannes Schindelin via GitGitGadget
2026-07-09 16:49 ` [PATCH 11/12] t/helper/test-pack-deltas: widen `do_compress()`'s maxsize local " Johannes Schindelin via GitGitGadget
2026-07-09 16:49 ` [PATCH 12/12] git-zlib: widen `git_deflate_bound()` " Johannes Schindelin via GitGitGadget
2026-08-05 9:23 ` Patrick Steinhardt
2026-08-05 13:58 ` Johannes Schindelin
2026-08-05 16:14 ` [PATCH v2 00/12] Next size_t stop: pack-objects/delta Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` [PATCH v2 01/12] diff-delta: widen `struct delta_index`' size fields to `size_t` Johannes Schindelin via GitGitGadget
2026-08-06 6:15 ` Patrick Steinhardt
2026-08-05 16:14 ` [PATCH v2 02/12] delta: widen `create_delta_index()` parameter " Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` Johannes Schindelin via GitGitGadget [this message]
2026-08-05 16:14 ` [PATCH v2 04/12] pack-objects: widen `free_unpacked()` return " Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` [PATCH v2 05/12] pack-objects: widen `mem_usage` and `try_delta()`'s out-param " Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` [PATCH v2 06/12] delta: widen `create_delta()` and `diff_delta()` " Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` [PATCH v2 07/12] packfile, git-zlib: widen `use_pack()` and zstream avail fields " Johannes Schindelin via GitGitGadget
2026-08-07 21:41 ` Junio C Hamano
2026-08-07 22:06 ` Junio C Hamano
2026-08-05 16:14 ` [PATCH v2 08/12] archive-zip: widen `zlib_deflate_raw()`'s maxsize local " Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` [PATCH v2 09/12] diff: widen `deflate_it()`'s bound local from int " Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` [PATCH v2 10/12] http-push: widen `start_put()`'s size local from `ssize_t` " Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` [PATCH v2 11/12] t/helper/test-pack-deltas: widen `do_compress()`'s maxsize local " Johannes Schindelin via GitGitGadget
2026-08-05 16:14 ` [PATCH v2 12/12] git-zlib: widen `git_deflate_bound()` " Johannes Schindelin via GitGitGadget
2026-08-06 6:15 ` [PATCH v2 00/12] Next size_t stop: pack-objects/delta Patrick Steinhardt
2026-08-06 17:30 ` Junio C Hamano
2026-08-10 23:15 ` 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=5b54041bafca1de826ddb4466b3d5d8fcceba3af.1785946479.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=ps@pks.im \
/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.