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`). Note that GCC struggles a bit to figure out that `deltalen` is always initialized before it is used; To help it along, we initialize it to 0. This work-around will go away in a later patch series when `deltalen` can be widened to `size_t`. Assisted-by: Opus 4.7 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jul 9, 2026 at 16:49 UTC 6f8241eb18d810f51f1d388ae207208b17a9e79c
7 files changed +22 -15
builtin/fast-import.c
+4 -2
@@ -962,7 +962,7 @@ static int store_object(
962 struct object_entry *e;
963 unsigned char hdr[96];
964 struct object_id oid;
965 - unsigned long hdrlen, deltalen;
965 + unsigned long hdrlen, deltalen = 0;
966 struct git_hash_ctx c;
967 git_zstream s;
968 struct repo_config_values *cfg = repo_config_values(the_repository);
@@ -998,11 +998,13 @@ static int store_object(
998
999 if (last && last->data.len && last->data.buf && last->depth < max_depth
1000 && dat->len > the_hash_algo->rawsz) {
1001 + size_t deltalen_st;
1002
1003 delta_count_attempts_by_type[type]++;
1004 delta = diff_delta(last->data.buf, last->data.len,
1005 dat->buf, dat->len,
1005 - &deltalen, dat->len - the_hash_algo->rawsz);
1006 + &deltalen_st, dat->len - the_hash_algo->rawsz);
1007 + deltalen = cast_size_t_to_ulong(deltalen_st);
1008 } else
1009 delta = NULL;
1010
builtin/pack-objects.c
+4 -2
@@ -353,7 +353,8 @@ static void index_commit_for_bitmap(struct commit *commit)
353
354 static void *get_delta(struct object_entry *entry)
355 {
356 - unsigned long size, base_size, delta_size;
356 + unsigned long size, base_size;
357 + size_t delta_size;
358 void *buf, *base_buf, *delta_buf;
359 enum object_type type;
360 size_t size_st = 0, base_size_st = 0;
@@ -2791,7 +2792,8 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
2792 {
2793 struct object_entry *trg_entry = trg->entry;
2794 struct object_entry *src_entry = src->entry;
2794 - unsigned long trg_size, src_size, delta_size, sizediff, max_size, sz;
2795 + unsigned long trg_size, src_size, sizediff, max_size, sz;
2796 + size_t delta_size;
2797 unsigned ref_depth;
2798 enum object_type type;
2799 void *delta_buf;
delta.h
+5 -5
@@ -42,8 +42,8 @@ unsigned long sizeof_delta_index(struct delta_index *index);
42 */
43 void *
44 create_delta(const struct delta_index *index,
45 - const void *buf, unsigned long bufsize,
46 - unsigned long *delta_size, unsigned long max_delta_size);
45 + const void *buf, size_t bufsize,
46 + size_t *delta_size, size_t max_delta_size);
47
48 /*
49 * diff_delta: create a delta from source buffer to target buffer
@@ -54,9 +54,9 @@ create_delta(const struct delta_index *index,
54 * updated with its size. The returned buffer must be freed by the caller.
55 */
56 static inline void *
57 -diff_delta(const void *src_buf, unsigned long src_bufsize,
58 - const void *trg_buf, unsigned long trg_bufsize,
59 - unsigned long *delta_size, unsigned long max_delta_size)
57 +diff_delta(const void *src_buf, size_t src_bufsize,
58 + const void *trg_buf, size_t trg_bufsize,
59 + size_t *delta_size, size_t max_delta_size)
60 {
61 struct delta_index *index = create_delta_index(src_buf, src_bufsize);
62 if (index) {
diff-delta.c
+2 -2
@@ -318,8 +318,8 @@ unsigned long sizeof_delta_index(struct delta_index *index)
318
319 void *
320 create_delta(const struct delta_index *index,
321 - const void *trg_buf, unsigned long trg_size,
322 - unsigned long *delta_size, unsigned long max_size)
321 + const void *trg_buf, size_t trg_size,
322 + size_t *delta_size, size_t max_size)
323 {
324 unsigned int i, val;
325 off_t outpos, moff;
diff.c
+3 -1
@@ -3647,9 +3647,11 @@ static void emit_binary_diff_body(struct diff_options *o,
3647 delta = NULL;
3648 deflated = deflate_it(two->ptr, two->size, &deflate_size);
3649 if (one->size && two->size) {
3650 + size_t delta_size_st = 0;
3651 delta = diff_delta(one->ptr, one->size,
3652 two->ptr, two->size,
3652 - &delta_size, deflate_size);
3653 + &delta_size_st, deflate_size);
3654 + delta_size = cast_size_t_to_ulong(delta_size_st);
3655 if (delta) {
3656 void *to_free = delta;
3657 orig_size = delta_size;
t/helper/test-delta.c
+1 -1
@@ -32,7 +32,7 @@ int cmd__delta(int argc, const char **argv)
32 die_errno("unable to read '%s'", argv[3]);
33
34 if (argv[1][1] == 'd') {
35 - unsigned long delta_size;
35 + size_t delta_size;
36 out_buf = diff_delta(from.buf, from.len,
37 data.buf, data.len,
38 &delta_size, 0);
t/helper/test-pack-deltas.c
+3 -2
@@ -49,7 +49,7 @@ static void write_ref_delta(struct hashfile *f,
49 {
50 unsigned char header[MAX_PACK_OBJECT_HEADER];
51 unsigned long delta_size, compressed_size, hdrlen;
52 - size_t size, base_size;
52 + size_t size, base_size, delta_size_st = 0;
53 enum object_type type;
54 void *base_buf, *delta_buf;
55 void *buf = odb_read_object(the_repository->objects,
@@ -65,7 +65,8 @@ static void write_ref_delta(struct hashfile *f,
65 die("unable to read %s", oid_to_hex(base));
66
67 delta_buf = diff_delta(base_buf, base_size,
68 - buf, size, &delta_size, 0);
68 + buf, size, &delta_size_st, 0);
69 + delta_size = cast_size_t_to_ulong(delta_size_st);
70
71 compressed_size = do_compress(&delta_buf, delta_size);
72