packfile,delta: drop the `cast_size_t_to_ulong()` wrappers

When I started the transition from `unsigned long` to `size_t`, in the interest of keeping the patches reviewable, I introduced these calls to prevent data type narrowing from silently failing to handle large object sizes. I also introduced `*_sz()` variants that would allow most of the callers to keep using that `unsigned long` that the 90s kindly asked to be returned. After the preceding commits, the only places that called the narrow wrappers either no longer exist or already use the `_sz` form internally, so the wrappers just narrow values back through `cast_size_t_to_ulong()` for no reason. Drop them and rename the `_sz` variants back to the natural names. 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 Jun 15, 2026 at 11:52 UTC 7a3a78cc76da5e2eccf6fc2553a4803c56390ac5
4 files changed +13 -35
delta.h
+2 -12
@@ -86,11 +86,8 @@ void *patch_delta(const void *src_buf, size_t src_size,
86 * This must be called twice on the delta data buffer, first to get the
87 * expected source buffer size, and again to get the target buffer size.
88 */
89 -/*
90 - * Size_t variant that doesn't truncate - use for >4GB objects on Windows.
91 - */
92 -static inline size_t get_delta_hdr_size_sz(const unsigned char **datap,
93 - const unsigned char *top)
89 +static inline size_t get_delta_hdr_size(const unsigned char **datap,
90 + const unsigned char *top)
91 {
92 const unsigned char *data = *datap;
93 size_t cmd, size = 0;
@@ -104,11 +101,4 @@ static inline size_t get_delta_hdr_size_sz(const unsigned char **datap,
101 return size;
102 }
103
107 -static inline unsigned long get_delta_hdr_size(const unsigned char **datap,
108 - const unsigned char *top)
109 -{
110 - size_t size = get_delta_hdr_size_sz(datap, top);
111 - return cast_size_t_to_ulong(size);
112 -}
113 -
104 #endif
packfile.c
+8 -20
@@ -1164,11 +1164,12 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf,
1164 }
1165
1166 /*
1167 - * Size_t variant for >4GB delta results on Windows.
1167 + * Read a delta object's header at curpos in p (already inflated as needed)
1168 + * and return the size of the result object (the post-application target).
1169 */
1169 -static size_t get_size_from_delta_sz(struct packed_git *p,
1170 - struct pack_window **w_curs,
1171 - off_t curpos)
1170 +size_t get_size_from_delta(struct packed_git *p,
1171 + struct pack_window **w_curs,
1172 + off_t curpos)
1173 {
1174 const unsigned char *data;
1175 unsigned char delta_head[20], *in;
@@ -1215,18 +1216,10 @@ static size_t get_size_from_delta_sz(struct packed_git *p,
1216 data = delta_head;
1217
1218 /* ignore base size */
1218 - get_delta_hdr_size_sz(&data, delta_head+sizeof(delta_head));
1219 + get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1220
1221 /* Read the result size */
1221 - return get_delta_hdr_size_sz(&data, delta_head+sizeof(delta_head));
1222 -}
1223 -
1224 -unsigned long get_size_from_delta(struct packed_git *p,
1225 - struct pack_window **w_curs,
1226 - off_t curpos)
1227 -{
1228 - size_t size = get_size_from_delta_sz(p, w_curs, curpos);
1229 - return cast_size_t_to_ulong(size);
1222 + return get_delta_hdr_size(&data, delta_head+sizeof(delta_head));
1223 }
1224
1225 int unpack_object_header(struct packed_git *p,
@@ -1634,12 +1627,7 @@ static int packed_object_info_with_index_pos(struct packed_git *p, off_t obj_off
1627 ret = -1;
1628 goto out;
1629 }
1637 - /*
1638 - * Use size_t variant to avoid die() on >4GB deltas.
1639 - * oi->sizep is unsigned long, so truncation may occur,
1640 - * but streaming code uses its own size_t tracking.
1641 - */
1642 - size = get_size_from_delta_sz(p, &w_curs, tmp_pos);
1630 + size = get_size_from_delta(p, &w_curs, tmp_pos);
1631 if (size == 0) {
1632 ret = -1;
1633 goto out;
packfile.h
+1 -1
@@ -458,7 +458,7 @@ int is_pack_valid(struct packed_git *);
458 void *unpack_entry(struct repository *r, struct packed_git *, off_t,
459 enum object_type *, size_t *);
460 unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, size_t *sizep);
461 -unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
461 +size_t get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
462 int unpack_object_header(struct packed_git *, struct pack_window **, off_t *, size_t *);
463 off_t get_delta_base(struct packed_git *p, struct pack_window **w_curs,
464 off_t *curpos, enum object_type type,
patch-delta.c
+2 -2
@@ -27,12 +27,12 @@ void *patch_delta(const void *src_buf, size_t src_size,
27 top = (const unsigned char *) delta_buf + delta_size;
28
29 /* make sure the orig file size matches what we expect */
30 - size = get_delta_hdr_size_sz(&data, top);
30 + size = get_delta_hdr_size(&data, top);
31 if (size != src_size)
32 return NULL;
33
34 /* now the result size */
35 - size = get_delta_hdr_size_sz(&data, top);
35 + size = get_delta_hdr_size(&data, top);
36 dst_buf = xmallocz(size);
37
38 out = dst_buf;