delta: widen create_delta() and diff_delta() to size_t

Last stop in the delta-encoding API widening for >4 GiB blobs on
Windows: with create_delta_index() done in the prior commit and
create_delta()/diff_delta() finished here, every byte count that
crosses delta.h is now size_t. The struct fields they store into
have been size_t since the diff-delta struct widening.

The API change must move with all callers in the same commit (the
build only passes when every &delta_size matches the new size_t*).
Caller updates are kept minimal:

  * builtin/pack-objects.c get_delta() and try_delta(): widen only
    the local delta_size variable; the surrounding unsigned-long
    locals and their cast_size_t_to_ulong() shims are out of scope
    here and will be cleaned up in their own commits.

  * builtin/fast-import.c, diff.c, t/helper/test-pack-deltas.c:
    keep the local unsigned-long delta size (each feeds a still-
    unsigned-long downstream consumer: zlib's avail_in,
    deflate_it(), the test helper's own do_compress()), and bridge
    via a temporary size_t plus cast_size_t_to_ulong(). The new
    casts are paid back in later topics that widen those consumers.

  * t/helper/test-delta.c: widen the local outright (no downstream
    consumer beyond the test's own out_size, which is already
    size_t).

Assisted-by: Opus 4.7
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2026-06-05 09:46:26 +02:00
parent 00386ad0ce
commit 6085d619ec
7 changed files with 21 additions and 14 deletions

View File

@@ -998,11 +998,13 @@ static int store_object(
if (last && last->data.len && last->data.buf && last->depth < max_depth
&& dat->len > the_hash_algo->rawsz) {
size_t deltalen_st = 0;
delta_count_attempts_by_type[type]++;
delta = diff_delta(last->data.buf, last->data.len,
dat->buf, dat->len,
&deltalen, dat->len - the_hash_algo->rawsz);
&deltalen_st, dat->len - the_hash_algo->rawsz);
deltalen = cast_size_t_to_ulong(deltalen_st);
} else
delta = NULL;

View File

@@ -353,7 +353,8 @@ static void index_commit_for_bitmap(struct commit *commit)
static void *get_delta(struct object_entry *entry)
{
unsigned long size, base_size, delta_size;
unsigned long size, base_size;
size_t delta_size;
void *buf, *base_buf, *delta_buf;
enum object_type type;
size_t size_st = 0, base_size_st = 0;
@@ -2791,7 +2792,8 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
{
struct object_entry *trg_entry = trg->entry;
struct object_entry *src_entry = src->entry;
unsigned long trg_size, src_size, delta_size, sizediff, max_size, sz;
unsigned long trg_size, src_size, sizediff, max_size, sz;
size_t delta_size;
unsigned ref_depth;
enum object_type type;
void *delta_buf;

10
delta.h
View File

@@ -42,8 +42,8 @@ unsigned long sizeof_delta_index(struct delta_index *index);
*/
void *
create_delta(const struct delta_index *index,
const void *buf, unsigned long bufsize,
unsigned long *delta_size, unsigned long max_delta_size);
const void *buf, size_t bufsize,
size_t *delta_size, size_t max_delta_size);
/*
* diff_delta: create a delta from source buffer to target buffer
@@ -54,9 +54,9 @@ create_delta(const struct delta_index *index,
* updated with its size. The returned buffer must be freed by the caller.
*/
static inline void *
diff_delta(const void *src_buf, unsigned long src_bufsize,
const void *trg_buf, unsigned long trg_bufsize,
unsigned long *delta_size, unsigned long max_delta_size)
diff_delta(const void *src_buf, size_t src_bufsize,
const void *trg_buf, size_t trg_bufsize,
size_t *delta_size, size_t max_delta_size)
{
struct delta_index *index = create_delta_index(src_buf, src_bufsize);
if (index) {

View File

@@ -318,8 +318,8 @@ unsigned long sizeof_delta_index(struct delta_index *index)
void *
create_delta(const struct delta_index *index,
const void *trg_buf, unsigned long trg_size,
unsigned long *delta_size, unsigned long max_size)
const void *trg_buf, size_t trg_size,
size_t *delta_size, size_t max_size)
{
unsigned int i, val;
off_t outpos, moff;

4
diff.c
View File

@@ -3647,9 +3647,11 @@ static void emit_binary_diff_body(struct diff_options *o,
delta = NULL;
deflated = deflate_it(two->ptr, two->size, &deflate_size);
if (one->size && two->size) {
size_t delta_size_st = 0;
delta = diff_delta(one->ptr, one->size,
two->ptr, two->size,
&delta_size, deflate_size);
&delta_size_st, deflate_size);
delta_size = cast_size_t_to_ulong(delta_size_st);
if (delta) {
void *to_free = delta;
orig_size = delta_size;

View File

@@ -32,7 +32,7 @@ int cmd__delta(int argc, const char **argv)
die_errno("unable to read '%s'", argv[3]);
if (argv[1][1] == 'd') {
unsigned long delta_size;
size_t delta_size;
out_buf = diff_delta(from.buf, from.len,
data.buf, data.len,
&delta_size, 0);

View File

@@ -49,7 +49,7 @@ static void write_ref_delta(struct hashfile *f,
{
unsigned char header[MAX_PACK_OBJECT_HEADER];
unsigned long delta_size, compressed_size, hdrlen;
size_t size, base_size;
size_t size, base_size, delta_size_st = 0;
enum object_type type;
void *base_buf, *delta_buf;
void *buf = odb_read_object(the_repository->objects,
@@ -65,7 +65,8 @@ static void write_ref_delta(struct hashfile *f,
die("unable to read %s", oid_to_hex(base));
delta_buf = diff_delta(base_buf, base_size,
buf, size, &delta_size, 0);
buf, size, &delta_size_st, 0);
delta_size = cast_size_t_to_ulong(delta_size_st);
compressed_size = do_compress(&delta_buf, delta_size);