unpack-objects: widen the size-passing infrastructure to size_t

Drop the last cast_size_t_to_ulong() in builtin/unpack-objects.c.
With size_t-typed object sizes already coming in via odb_read_object()
and the per-byte varint decode in unpack_one() (widened by
f2063855fb), the rest of the file was the only thing left that still
threaded sizes through unsigned long: struct obj_buffer.size and
struct delta_info.size, get_data() and add_object_buffer(),
add_delta_to_list(), resolve_delta(), resolve_against_held(),
added_object(), write_object(), unpack_non_delta_entry(),
unpack_delta_entry(), and stream_blob().

Widen all of them together. None of those types had a downstream
narrow consumer once odb_write_object() and patch_delta() were
widened earlier, so the change is mechanical: parameter and field
types change, the base_size_st bridge in unpack_delta_entry() and
its cast go away, and odb_read_object() now writes into base_size
directly.

Assisted-by: Opus 4.7
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2026-06-05 23:05:52 +02:00
committed by Git for Windows Build Agent
parent 68eaa6e75b
commit fa930f9e06

View File

@@ -40,7 +40,7 @@ static struct progress *progress;
*/
struct obj_buffer {
char *buffer;
unsigned long size;
size_t size;
};
static struct decoration obj_decorate;
@@ -50,7 +50,7 @@ static struct obj_buffer *lookup_object_buffer(struct object *base)
return lookup_decoration(&obj_decorate, base);
}
static void add_object_buffer(struct object *object, char *buffer, unsigned long size)
static void add_object_buffer(struct object *object, char *buffer, size_t size)
{
struct obj_buffer *obj;
CALLOC_ARRAY(obj, 1);
@@ -114,10 +114,10 @@ static void use(int bytes)
* allocated buffer which is reused to hold temporary zstream output
* and return NULL instead of returning garbage data.
*/
static void *get_data(unsigned long size)
static void *get_data(size_t size)
{
git_zstream stream;
unsigned long bufsize = dry_run && size > 8192 ? 8192 : size;
size_t bufsize = dry_run && size > 8192 ? 8192 : size;
void *buf = xmallocz(bufsize);
memset(&stream, 0, sizeof(stream));
@@ -161,7 +161,7 @@ struct delta_info {
struct object_id base_oid;
unsigned nr;
off_t base_offset;
unsigned long size;
size_t size;
void *delta;
struct delta_info *next;
};
@@ -170,7 +170,7 @@ static struct delta_info *delta_list;
static void add_delta_to_list(unsigned nr, const struct object_id *base_oid,
off_t base_offset,
void *delta, unsigned long size)
void *delta, size_t size)
{
struct delta_info *info = xmalloc(sizeof(*info));
@@ -261,7 +261,7 @@ static void write_rest(void)
}
static void added_object(unsigned nr, enum object_type type,
void *data, unsigned long size);
void *data, size_t size);
/*
* Write out nr-th object from the list, now we know the contents
@@ -269,7 +269,7 @@ static void added_object(unsigned nr, enum object_type type,
* to be checked at the end.
*/
static void write_object(unsigned nr, enum object_type type,
void *buf, unsigned long size)
void *buf, size_t size)
{
if (!strict) {
if (odb_write_object(the_repository->objects, buf, size, type,
@@ -310,8 +310,8 @@ static void write_object(unsigned nr, enum object_type type,
}
static void resolve_delta(unsigned nr, enum object_type type,
void *base, unsigned long base_size,
void *delta, unsigned long delta_size)
void *base, size_t base_size,
void *delta, size_t delta_size)
{
void *result;
size_t result_size;
@@ -330,7 +330,7 @@ static void resolve_delta(unsigned nr, enum object_type type,
* resolve all the deltified objects that are based on it.
*/
static void added_object(unsigned nr, enum object_type type,
void *data, unsigned long size)
void *data, size_t size)
{
struct delta_info **p = &delta_list;
struct delta_info *info;
@@ -349,7 +349,7 @@ static void added_object(unsigned nr, enum object_type type,
}
}
static void unpack_non_delta_entry(enum object_type type, unsigned long size,
static void unpack_non_delta_entry(enum object_type type, size_t size,
unsigned nr)
{
void *buf = get_data(size);
@@ -385,7 +385,7 @@ static ssize_t feed_input_zstream(struct odb_write_stream *in_stream,
return buf_len - zstream->avail_out;
}
static void stream_blob(unsigned long size, unsigned nr)
static void stream_blob(size_t size, unsigned nr)
{
git_zstream zstream = { 0 };
struct input_zstream_data data = { 0 };
@@ -416,7 +416,7 @@ static void stream_blob(unsigned long size, unsigned nr)
}
static int resolve_against_held(unsigned nr, const struct object_id *base,
void *delta_data, unsigned long delta_size)
void *delta_data, size_t delta_size)
{
struct object *obj;
struct obj_buffer *obj_buffer;
@@ -431,12 +431,11 @@ static int resolve_against_held(unsigned nr, const struct object_id *base,
return 1;
}
static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
static void unpack_delta_entry(enum object_type type, size_t delta_size,
unsigned nr)
{
void *delta_data, *base;
unsigned long base_size;
size_t base_size_st = 0;
size_t base_size;
struct object_id base_oid;
if (type == OBJ_REF_DELTA) {
@@ -513,8 +512,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
return;
base = odb_read_object(the_repository->objects, &base_oid,
&type, &base_size_st);
base_size = cast_size_t_to_ulong(base_size_st);
&type, &base_size);
if (!base) {
error("failed to read delta-pack base object %s",
oid_to_hex(&base_oid));