fast-import: drop the six size casts in the object-read paths

Continue the size_t evacuation. fast-import's helper
gfi_unpack_entry() and the five size-handling sites that feed off
it (store_object()'s deltalen, load_tree(), parse_from_existing(),
the inline gfi_unpack_entry() caller in parse_objectish(),
cat_blob(), and dereference()) all carry size_t-shaped values from
the odb / unpack_entry() APIs through cast_size_t_to_ulong()
bridges into unsigned long locals.

With the producers (odb_read_object(), odb_read_object_peeled(),
unpack_entry()) and the consumers it feeds (the zlib avail_in
field from a prior commit, encode_in_pack_object_header()'s
uintmax_t parameter, parse_from_commit()'s widened size parameter)
all size_t-ready, the bridges and casts go away in one pass.
gfi_unpack_entry() now writes into the caller's size_t directly,
and the six locals collapse to plain size_t declarations.

Assisted-by: Opus 4.7
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2026-06-05 22:37:32 +02:00
parent 8849de1945
commit e9aa08fde6

View File

@@ -962,7 +962,7 @@ static int store_object(
struct object_entry *e;
unsigned char hdr[96];
struct object_id oid;
unsigned long hdrlen, deltalen;
size_t hdrlen, deltalen;
struct git_hash_ctx c;
git_zstream s;
struct repo_config_values *cfg = repo_config_values(the_repository);
@@ -998,13 +998,10 @@ 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_st, dat->len - the_hash_algo->rawsz);
deltalen = cast_size_t_to_ulong(deltalen_st);
&deltalen, dat->len - the_hash_algo->rawsz);
} else
delta = NULL;
@@ -1240,10 +1237,9 @@ out:
*/
static void *gfi_unpack_entry(
struct object_entry *oe,
unsigned long *sizep)
size_t *sizep)
{
enum object_type type;
size_t size_st = 0;
void *data;
struct packed_git *p = all_packs[oe->pack_id];
if (p == pack_data && p->pack_size < (pack_size + the_hash_algo->rawsz)) {
@@ -1266,9 +1262,7 @@ static void *gfi_unpack_entry(
*/
p->pack_size = pack_size + the_hash_algo->rawsz;
}
data = unpack_entry(the_repository, p, oe->idx.offset, &type, &size_st);
if (sizep)
*sizep = cast_size_t_to_ulong(size_st);
data = unpack_entry(the_repository, p, oe->idx.offset, &type, sizep);
return data;
}
@@ -1277,7 +1271,7 @@ static void load_tree(struct tree_entry *root)
struct object_id *oid = &root->versions[1].oid;
struct object_entry *myoe;
struct tree_content *t;
unsigned long size;
size_t size;
char *buf;
const char *c;
@@ -1295,10 +1289,8 @@ static void load_tree(struct tree_entry *root)
die(_("can't load tree %s"), oid_to_hex(oid));
} else {
enum object_type type;
size_t size_st = 0;
buf = odb_read_object(the_repository->objects, oid, &type,
&size_st);
size = cast_size_t_to_ulong(size_st);
&size);
if (!buf || type != OBJ_TREE)
die(_("can't load tree %s"), oid_to_hex(oid));
}
@@ -2616,7 +2608,7 @@ static void file_change_deleteall(struct branch *b)
b->num_notes = 0;
}
static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
static void parse_from_commit(struct branch *b, char *buf, size_t size)
{
if (!buf || size < the_hash_algo->hexsz + 6)
die(_("not a valid commit: %s"), oid_to_hex(&b->oid));
@@ -2633,13 +2625,11 @@ static void parse_from_existing(struct branch *b)
oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
} else {
unsigned long size;
size_t size_st = 0;
size_t size;
char *buf;
buf = odb_read_object_peeled(the_repository->objects, &b->oid,
OBJ_COMMIT, &size_st, &b->oid);
size = cast_size_t_to_ulong(size_st);
OBJ_COMMIT, &size, &b->oid);
parse_from_commit(b, buf, size);
free(buf);
}
@@ -2668,7 +2658,7 @@ static int parse_objectish(struct branch *b, const char *objectish)
if (!oideq(&b->oid, &oe->idx.oid)) {
oidcpy(&b->oid, &oe->idx.oid);
if (oe->pack_id != MAX_PACK_ID) {
unsigned long size;
size_t size;
char *buf = gfi_unpack_entry(oe, &size);
parse_from_commit(b, buf, size);
free(buf);
@@ -3334,15 +3324,13 @@ static void cat_blob_write(const char *buf, unsigned long size)
static void cat_blob(struct object_entry *oe, struct object_id *oid)
{
struct strbuf line = STRBUF_INIT;
unsigned long size;
size_t size;
enum object_type type = 0;
char *buf;
if (!oe || oe->pack_id == MAX_PACK_ID) {
size_t size_st = 0;
buf = odb_read_object(the_repository->objects, oid, &type,
&size_st);
size = cast_size_t_to_ulong(size_st);
&size);
} else {
type = oe->type;
buf = gfi_unpack_entry(oe, &size);
@@ -3421,7 +3409,7 @@ static void parse_cat_blob(const char *p)
static struct object_entry *dereference(struct object_entry *oe,
struct object_id *oid)
{
unsigned long size;
size_t size;
char *buf = NULL;
const unsigned hexsz = the_hash_algo->hexsz;
@@ -3450,10 +3438,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size);
} else {
enum object_type unused;
size_t size_st = 0;
buf = odb_read_object(the_repository->objects, oid,
&unused, &size_st);
size = cast_size_t_to_ulong(size_st);
&unused, &size);
}
if (!buf)
die(_("can't load object %s"), oid_to_hex(oid));