Skip to content

Commit 2491da9

Browse files
committed
odb: use size_t for object_info.sizep and the size APIs
When `js/objects-larger-than-4gb-on-windows` widened the streaming, index-pack and unpack-objects code paths, in the interest of keeping the patches somewhat reasonably-sized, it left the public ODB API still typed in `unsigned long`. In particular `struct object_info::sizep` and the four wrappers built on top of it (`odb_read_object`, `odb_read_object_peeled`, `odb_read_object_info`, `odb_pretend_object`) still return the unpacked size through `unsigned long *`, so on Windows `cat-file -s` and the `git add` / `git status` paths for a >4 GiB blob silently cap at 4 GiB. Widen the field and the four wrappers. The previous commits already widened the `unpack_entry()` cascade and pack-objects' in-core size accessors, so most of the cascade arrives here with no further work: the temporary shims in `packed_object_info_with_index_pos()` and in `unpack_entry()`'s delta-base recovery path go away, the two `SET_SIZE(entry, cast_size_t_to_ulong(canonical_size))` calls in `check_object()` and the matching one in `drop_reused_delta()` collapse to plain `SET_SIZE`, and `oe_get_size_slow()`'s tail `cast_size_t_to_ulong()` is gone too. What remains narrow are the boundaries this series does not intend to touch: the diff, blame, textconv and fast-import machinery. Even so, this patch is unfortunately quite large. Assisted-by: Opus 4.7 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent edcbfd2 commit 2491da9

63 files changed

Lines changed: 203 additions & 171 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apply.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3321,7 +3321,7 @@ static int apply_binary(struct apply_state *state,
33213321
if (odb_has_object(the_repository->objects, &oid, 0)) {
33223322
/* We already have the postimage */
33233323
enum object_type type;
3324-
unsigned long size;
3324+
size_t size;
33253325
char *result;
33263326

33273327
result = odb_read_object(the_repository->objects, &oid,
@@ -3384,7 +3384,7 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
33843384
strbuf_addf(buf, "Subproject commit %s\n", oid_to_hex(oid));
33853385
} else {
33863386
enum object_type type;
3387-
unsigned long sz;
3387+
size_t sz;
33883388
char *result;
33893389

33903390
result = odb_read_object(the_repository->objects, oid,
@@ -3611,7 +3611,7 @@ static int load_preimage(struct apply_state *state,
36113611

36123612
static int resolve_to(struct image *image, const struct object_id *result_id)
36133613
{
3614-
unsigned long size;
3614+
size_t size;
36153615
enum object_type type;
36163616
char *data;
36173617

archive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
8787
const struct object_id *oid,
8888
unsigned int mode,
8989
enum object_type *type,
90-
unsigned long *sizep)
90+
size_t *sizep)
9191
{
9292
void *buffer;
9393
const struct commit *commit = args->convert ? args->commit : NULL;
@@ -158,7 +158,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base,
158158
write_archive_entry_fn_t write_entry = c->write_entry;
159159
int err;
160160
const char *path_without_prefix;
161-
unsigned long size;
161+
size_t size;
162162
void *buffer;
163163
enum object_type type;
164164

attr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
768768
const char *path, unsigned flags)
769769
{
770770
struct object_id oid;
771-
unsigned long sz;
771+
size_t sz;
772772
enum object_type type;
773773
void *buf;
774774
unsigned short mode;

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static void show_list(const char *debug, int counted, int nr,
154154
struct commit *commit = p->item;
155155
unsigned commit_flags = commit->object.flags;
156156
enum object_type type;
157-
unsigned long size;
157+
size_t size;
158158
char *buf = odb_read_object(the_repository->objects,
159159
&commit->object.oid, &type,
160160
&size);

blame.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,13 @@ static void fill_origin_blob(struct diff_options *opt,
10411041
textconv_object(opt->repo, o->path, o->mode,
10421042
&o->blob_oid, 1, &file->ptr, &file_size))
10431043
;
1044-
else
1044+
else {
1045+
size_t file_size_st = 0;
10451046
file->ptr = odb_read_object(the_repository->objects,
10461047
&o->blob_oid, &type,
1047-
&file_size);
1048+
&file_size_st);
1049+
file_size = cast_size_t_to_ulong(file_size_st);
1050+
}
10481051
file->size = file_size;
10491052

10501053
if (!file->ptr)
@@ -2869,10 +2872,14 @@ void setup_scoreboard(struct blame_scoreboard *sb,
28692872
textconv_object(sb->repo, sb->path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
28702873
&sb->final_buf_size))
28712874
;
2872-
else
2875+
else {
2876+
size_t final_buf_size_st = 0;
28732877
sb->final_buf = odb_read_object(the_repository->objects,
28742878
&o->blob_oid, &type,
2875-
&sb->final_buf_size);
2879+
&final_buf_size_st);
2880+
sb->final_buf_size =
2881+
cast_size_t_to_ulong(final_buf_size_st);
2882+
}
28762883

28772884
if (!sb->final_buf)
28782885
die(_("cannot read blob %s for path %s"),

builtin/cat-file.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static char *replace_idents_using_mailmap(char *object_buf, size_t *size)
7070

7171
static int filter_object(const char *path, unsigned mode,
7272
const struct object_id *oid,
73-
char **buf, unsigned long *size)
73+
char **buf, size_t *size)
7474
{
7575
enum object_type type;
7676

@@ -106,7 +106,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
106106
struct object_id oid;
107107
enum object_type type;
108108
char *buf;
109-
unsigned long size;
109+
size_t size;
110110
struct object_context obj_context = {0};
111111
struct object_info oi = OBJECT_INFO_INIT;
112112
unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
@@ -152,7 +152,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
152152
if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
153153
size_t s = size;
154154
buf = replace_idents_using_mailmap(buf, &s);
155-
size = cast_size_t_to_ulong(s);
155+
size = s;
156156
}
157157

158158
printf("%"PRIuMAX"\n", (uintmax_t)size);
@@ -174,9 +174,15 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
174174
break;
175175

176176
case 'c':
177-
if (textconv_object(the_repository, path, obj_context.mode,
178-
&oid, 1, &buf, &size))
177+
{
178+
unsigned long size_ul = 0;
179+
int textconv_ret = textconv_object(the_repository, path,
180+
obj_context.mode, &oid, 1,
181+
&buf, &size_ul);
182+
size = size_ul;
183+
if (textconv_ret)
179184
break;
185+
}
180186
/* else fallthrough */
181187

182188
case 'p':
@@ -205,7 +211,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
205211
if (use_mailmap) {
206212
size_t s = size;
207213
buf = replace_idents_using_mailmap(buf, &s);
208-
size = cast_size_t_to_ulong(s);
214+
size = s;
209215
}
210216

211217
/* otherwise just spit out the data */
@@ -252,7 +258,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
252258
if (use_mailmap) {
253259
size_t s = size;
254260
buf = replace_idents_using_mailmap(buf, &s);
255-
size = cast_size_t_to_ulong(s);
261+
size = s;
256262
}
257263
break;
258264
}
@@ -274,7 +280,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
274280
struct expand_data {
275281
struct object_id oid;
276282
enum object_type type;
277-
unsigned long size;
283+
size_t size;
278284
unsigned short mode;
279285
off_t disk_size;
280286
const char *rest;
@@ -391,7 +397,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
391397
fflush(stdout);
392398
if (opt->transform_mode) {
393399
char *contents;
394-
unsigned long size;
400+
size_t size;
395401

396402
if (!data->rest)
397403
die("missing path for '%s'", oid_to_hex(oid));
@@ -403,9 +409,12 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
403409
oid_to_hex(oid), data->rest);
404410
} else if (opt->transform_mode == 'c') {
405411
enum object_type type;
406-
if (!textconv_object(the_repository,
407-
data->rest, 0100644, oid,
408-
1, &contents, &size))
412+
unsigned long size_ul = 0;
413+
if (textconv_object(the_repository,
414+
data->rest, 0100644, oid,
415+
1, &contents, &size_ul))
416+
size = size_ul;
417+
else
409418
contents = odb_read_object(the_repository->objects,
410419
oid, &type, &size);
411420
if (!contents)
@@ -421,7 +430,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
421430
}
422431
else {
423432
enum object_type type;
424-
unsigned long size;
433+
size_t size;
425434
void *contents;
426435

427436
contents = odb_read_object(the_repository->objects, oid,
@@ -432,7 +441,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
432441
if (use_mailmap) {
433442
size_t s = size;
434443
contents = replace_idents_using_mailmap(contents, &s);
435-
size = cast_size_t_to_ulong(s);
444+
size = s;
436445
}
437446

438447
if (type != data->type)
@@ -541,7 +550,7 @@ static void batch_object_write(const char *obj_name,
541550
if (!buf)
542551
die(_("unable to read %s"), oid_to_hex(&data->oid));
543552
buf = replace_idents_using_mailmap(buf, &s);
544-
data->size = cast_size_t_to_ulong(s);
553+
data->size = s;
545554

546555
free(buf);
547556
}

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static char *get_symlink(struct repository *repo,
319319
data = strbuf_detach(&link, NULL);
320320
} else {
321321
enum object_type type;
322-
unsigned long size;
322+
size_t size;
323323
data = odb_read_object(repo->objects, oid, &type, &size);
324324
if (!data)
325325
die(_("could not read object %s for symlink %s"),

builtin/fast-export.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,10 @@ static void export_blob(const struct object_id *oid)
317317
object = (struct object *)lookup_blob(the_repository, oid);
318318
eaten = 0;
319319
} else {
320-
buf = odb_read_object(the_repository->objects, oid, &type, &size);
320+
size_t size_st = 0;
321+
buf = odb_read_object(the_repository->objects, oid, &type,
322+
&size_st);
323+
size = cast_size_t_to_ulong(size_st);
321324
if (!buf)
322325
die(_("could not read blob %s"), oid_to_hex(oid));
323326
if (check_object_signature(the_repository, oid, buf, size,
@@ -880,7 +883,7 @@ static char *anonymize_tag(void)
880883

881884
static void handle_tag(const char *name, struct tag *tag)
882885
{
883-
unsigned long size;
886+
size_t size;
884887
enum object_type type;
885888
char *buf;
886889
const char *tagger, *tagger_end, *message;

builtin/fast-import.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,10 @@ static void load_tree(struct tree_entry *root)
12911291
die(_("can't load tree %s"), oid_to_hex(oid));
12921292
} else {
12931293
enum object_type type;
1294-
buf = odb_read_object(the_repository->objects, oid, &type, &size);
1294+
size_t size_st = 0;
1295+
buf = odb_read_object(the_repository->objects, oid, &type,
1296+
&size_st);
1297+
size = cast_size_t_to_ulong(size_st);
12951298
if (!buf || type != OBJ_TREE)
12961299
die(_("can't load tree %s"), oid_to_hex(oid));
12971300
}
@@ -2560,7 +2563,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
25602563
die(_("mark :%" PRIuMAX " not a commit"), commit_mark);
25612564
oidcpy(&commit_oid, &commit_oe->idx.oid);
25622565
} else if (!repo_get_oid(the_repository, p, &commit_oid)) {
2563-
unsigned long size;
2566+
size_t size;
25642567
char *buf = odb_read_object_peeled(the_repository->objects,
25652568
&commit_oid, OBJ_COMMIT, &size,
25662569
&commit_oid);
@@ -2627,10 +2630,12 @@ static void parse_from_existing(struct branch *b)
26272630
oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
26282631
} else {
26292632
unsigned long size;
2633+
size_t size_st = 0;
26302634
char *buf;
26312635

26322636
buf = odb_read_object_peeled(the_repository->objects, &b->oid,
2633-
OBJ_COMMIT, &size, &b->oid);
2637+
OBJ_COMMIT, &size_st, &b->oid);
2638+
size = cast_size_t_to_ulong(size_st);
26342639
parse_from_commit(b, buf, size);
26352640
free(buf);
26362641
}
@@ -2722,7 +2727,7 @@ static struct hash_list *parse_merge(unsigned int *count)
27222727
die(_("mark :%" PRIuMAX " not a commit"), idnum);
27232728
oidcpy(&n->oid, &oe->idx.oid);
27242729
} else if (!repo_get_oid(the_repository, from, &n->oid)) {
2725-
unsigned long size;
2730+
size_t size;
27262731
char *buf = odb_read_object_peeled(the_repository->objects,
27272732
&n->oid, OBJ_COMMIT,
27282733
&size, &n->oid);
@@ -3330,7 +3335,10 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
33303335
char *buf;
33313336

33323337
if (!oe || oe->pack_id == MAX_PACK_ID) {
3333-
buf = odb_read_object(the_repository->objects, oid, &type, &size);
3338+
size_t size_st = 0;
3339+
buf = odb_read_object(the_repository->objects, oid, &type,
3340+
&size_st);
3341+
size = cast_size_t_to_ulong(size_st);
33343342
} else {
33353343
type = oe->type;
33363344
buf = gfi_unpack_entry(oe, &size);
@@ -3438,8 +3446,10 @@ static struct object_entry *dereference(struct object_entry *oe,
34383446
buf = gfi_unpack_entry(oe, &size);
34393447
} else {
34403448
enum object_type unused;
3449+
size_t size_st = 0;
34413450
buf = odb_read_object(the_repository->objects, oid,
3442-
&unused, &size);
3451+
&unused, &size_st);
3452+
size = cast_size_t_to_ulong(size_st);
34433453
}
34443454
if (!buf)
34453455
die(_("can't load object %s"), oid_to_hex(oid));

builtin/fsck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
724724
struct for_each_loose_cb *data = cb_data;
725725
struct object *obj;
726726
enum object_type type = OBJ_NONE;
727-
unsigned long size;
727+
size_t size;
728728
void *contents = NULL;
729729
int eaten;
730730
struct object_info oi = OBJECT_INFO_INIT;

0 commit comments

Comments
 (0)