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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Jun 15, 2026 at 11:52 UTC c6a4629e3205fdb5af3a406477ca691de2a5ab31
65 files changed +209 -191
apply.c
+3 -3
@@ -3321,7 +3321,7 @@ static int apply_binary(struct apply_state *state,
3321 if (odb_has_object(the_repository->objects, &oid, 0)) {
3322 /* We already have the postimage */
3323 enum object_type type;
3324 - unsigned long size;
3324 + size_t size;
3325 char *result;
3326
3327 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
3384 strbuf_addf(buf, "Subproject commit %s\n", oid_to_hex(oid));
3385 } else {
3386 enum object_type type;
3387 - unsigned long sz;
3387 + size_t sz;
3388 char *result;
3389
3390 result = odb_read_object(the_repository->objects, oid,
@@ -3611,7 +3611,7 @@ static int load_preimage(struct apply_state *state,
3611
3612 static int resolve_to(struct image *image, const struct object_id *result_id)
3613 {
3614 - unsigned long size;
3614 + size_t size;
3615 enum object_type type;
3616 char *data;
3617
archive.c
+2 -2
@@ -87,7 +87,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
87 const struct object_id *oid,
88 unsigned int mode,
89 enum object_type *type,
90 - unsigned long *sizep)
90 + size_t *sizep)
91 {
92 void *buffer;
93 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,
158 write_archive_entry_fn_t write_entry = c->write_entry;
159 int err;
160 const char *path_without_prefix;
161 - unsigned long size;
161 + size_t size;
162 void *buffer;
163 enum object_type type;
164
attr.c
+1 -1
@@ -768,7 +768,7 @@ static struct attr_stack *read_attr_from_blob(struct index_state *istate,
768 const char *path, unsigned flags)
769 {
770 struct object_id oid;
771 - unsigned long sz;
771 + size_t sz;
772 enum object_type type;
773 void *buf;
774 unsigned short mode;
bisect.c
+1 -1
@@ -154,7 +154,7 @@ static void show_list(const char *debug, int counted, int nr,
154 struct commit *commit = p->item;
155 unsigned commit_flags = commit->object.flags;
156 enum object_type type;
157 - unsigned long size;
157 + size_t size;
158 char *buf = odb_read_object(the_repository->objects,
159 &commit->object.oid, &type,
160 &size);
blame.c
+11 -4
@@ -1041,10 +1041,13 @@ static void fill_origin_blob(struct diff_options *opt,
1041 textconv_object(opt->repo, o->path, o->mode,
1042 &o->blob_oid, 1, &file->ptr, &file_size))
1043 ;
1044 - else
1044 + else {
1045 + size_t file_size_st = 0;
1046 file->ptr = odb_read_object(the_repository->objects,
1047 &o->blob_oid, &type,
1047 - &file_size);
1048 + &file_size_st);
1049 + file_size = cast_size_t_to_ulong(file_size_st);
1050 + }
1051 file->size = file_size;
1052
1053 if (!file->ptr)
@@ -2869,10 +2872,14 @@ void setup_scoreboard(struct blame_scoreboard *sb,
2872 textconv_object(sb->repo, sb->path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
2873 &sb->final_buf_size))
2874 ;
2872 - else
2875 + else {
2876 + size_t final_buf_size_st = 0;
2877 sb->final_buf = odb_read_object(the_repository->objects,
2878 &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 + }
2883
2884 if (!sb->final_buf)
2885 die(_("cannot read blob %s for path %s"),
builtin/cat-file.c
+28 -33
@@ -84,7 +84,7 @@ static char *replace_idents_using_mailmap(char *object_buf, size_t *size)
84
85 static int filter_object(const char *path, unsigned mode,
86 const struct object_id *oid,
87 - char **buf, unsigned long *size)
87 + char **buf, size_t *size)
88 {
89 enum object_type type;
90
@@ -120,7 +120,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
120 struct object_id oid;
121 enum object_type type;
122 char *buf;
123 - unsigned long size;
123 + size_t size;
124 struct object_context obj_context = {0};
125 struct object_info oi = OBJECT_INFO_INIT;
126 unsigned flags = OBJECT_INFO_LOOKUP_REPLACE;
@@ -163,11 +163,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
163 if (odb_read_object_info_extended(the_repository->objects, &oid, &oi, flags) < 0)
164 die("git cat-file: could not get object info");
165
166 - if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG)) {
167 - size_t s = size;
168 - buf = replace_idents_using_mailmap(buf, &s);
169 - size = cast_size_t_to_ulong(s);
170 - }
166 + if (use_mailmap && (type == OBJ_COMMIT || type == OBJ_TAG))
167 + buf = replace_idents_using_mailmap(buf, &size);
168
169 printf("%"PRIuMAX"\n", (uintmax_t)size);
170 ret = 0;
@@ -188,9 +185,15 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
185 break;
186
187 case 'c':
191 - if (textconv_object(the_repository, path, obj_context.mode,
192 - &oid, 1, &buf, &size))
188 + {
189 + unsigned long size_ul = 0;
190 + int textconv_ret = textconv_object(the_repository, path,
191 + obj_context.mode, &oid, 1,
192 + &buf, &size_ul);
193 + size = size_ul;
194 + if (textconv_ret)
195 break;
196 + }
197 /* else fallthrough */
198
199 case 'p':
@@ -216,11 +219,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
219 if (!buf)
220 die("Cannot read object %s", obj_name);
221
219 - if (use_mailmap) {
220 - size_t s = size;
221 - buf = replace_idents_using_mailmap(buf, &s);
222 - size = cast_size_t_to_ulong(s);
223 - }
222 + if (use_mailmap)
223 + buf = replace_idents_using_mailmap(buf, &size);
224
225 /* otherwise just spit out the data */
226 break;
@@ -263,11 +263,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
263 buf = odb_read_object_peeled(the_repository->objects, &oid,
264 exp_type_id, &size, NULL);
265
266 - if (use_mailmap) {
267 - size_t s = size;
268 - buf = replace_idents_using_mailmap(buf, &s);
269 - size = cast_size_t_to_ulong(s);
270 - }
266 + if (use_mailmap)
267 + buf = replace_idents_using_mailmap(buf, &size);
268 break;
269 }
270 default:
@@ -288,7 +285,7 @@ cleanup:
285 struct expand_data {
286 struct object_id oid;
287 enum object_type type;
291 - unsigned long size;
288 + size_t size;
289 unsigned short mode;
290 off_t disk_size;
291 const char *rest;
@@ -404,7 +401,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
401 fflush(stdout);
402 if (opt->transform_mode) {
403 char *contents;
407 - unsigned long size;
404 + size_t size;
405
406 if (!data->rest)
407 die("missing path for '%s'", oid_to_hex(oid));
@@ -416,9 +413,12 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
413 oid_to_hex(oid), data->rest);
414 } else if (opt->transform_mode == 'c') {
415 enum object_type type;
419 - if (!textconv_object(the_repository,
420 - data->rest, 0100644, oid,
421 - 1, &contents, &size))
416 + unsigned long size_ul = 0;
417 + if (textconv_object(the_repository,
418 + data->rest, 0100644, oid,
419 + 1, &contents, &size_ul))
420 + size = size_ul;
421 + else
422 contents = odb_read_object(the_repository->objects,
423 oid, &type, &size);
424 if (!contents)
@@ -434,7 +434,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
434 }
435 else {
436 enum object_type type;
437 - unsigned long size;
437 + size_t size;
438 void *contents;
439
440 contents = odb_read_object(the_repository->objects, oid,
@@ -442,11 +442,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
442 if (!contents)
443 die("object %s disappeared", oid_to_hex(oid));
444
445 - if (use_mailmap) {
446 - size_t s = size;
447 - contents = replace_idents_using_mailmap(contents, &s);
448 - size = cast_size_t_to_ulong(s);
449 - }
445 + if (use_mailmap)
446 + contents = replace_idents_using_mailmap(contents, &size);
447
448 if (type != data->type)
449 die("object %s changed type!?", oid_to_hex(oid));
@@ -546,15 +543,13 @@ static void batch_object_write(const char *obj_name,
543 }
544
545 if (use_mailmap && (data->type == OBJ_COMMIT || data->type == OBJ_TAG)) {
549 - size_t s = data->size;
546 char *buf = NULL;
547
548 buf = odb_read_object(the_repository->objects, &data->oid,
549 &data->type, &data->size);
550 if (!buf)
551 die(_("unable to read %s"), oid_to_hex(&data->oid));
556 - buf = replace_idents_using_mailmap(buf, &s);
557 - data->size = cast_size_t_to_ulong(s);
552 + buf = replace_idents_using_mailmap(buf, &data->size);
553
554 free(buf);
555 }
builtin/difftool.c
+1 -1
@@ -319,7 +319,7 @@ static char *get_symlink(struct repository *repo,
319 data = strbuf_detach(&link, NULL);
320 } else {
321 enum object_type type;
322 - unsigned long size;
322 + size_t size;
323 data = odb_read_object(repo->objects, oid, &type, &size);
324 if (!data)
325 die(_("could not read object %s for symlink %s"),
builtin/fast-export.c
+5 -2
@@ -317,7 +317,10 @@ static void export_blob(const struct object_id *oid)
317 object = (struct object *)lookup_blob(the_repository, oid);
318 eaten = 0;
319 } 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);
324 if (!buf)
325 die(_("could not read blob %s"), oid_to_hex(oid));
326 if (check_object_signature(the_repository, oid, buf, size,
@@ -880,7 +883,7 @@ static char *anonymize_tag(void)
883
884 static void handle_tag(const char *name, struct tag *tag)
885 {
883 - unsigned long size;
886 + size_t size;
887 enum object_type type;
888 char *buf;
889 const char *tagger, *tagger_end, *message;
builtin/fast-import.c
+16 -6
@@ -1291,7 +1291,10 @@ static void load_tree(struct tree_entry *root)
1291 die(_("can't load tree %s"), oid_to_hex(oid));
1292 } else {
1293 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);
1298 if (!buf || type != OBJ_TREE)
1299 die(_("can't load tree %s"), oid_to_hex(oid));
1300 }
@@ -2560,7 +2563,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
2563 die(_("mark :%" PRIuMAX " not a commit"), commit_mark);
2564 oidcpy(&commit_oid, &commit_oe->idx.oid);
2565 } else if (!repo_get_oid(the_repository, p, &commit_oid)) {
2563 - unsigned long size;
2566 + size_t size;
2567 char *buf = odb_read_object_peeled(the_repository->objects,
2568 &commit_oid, OBJ_COMMIT, &size,
2569 &commit_oid);
@@ -2627,10 +2630,12 @@ static void parse_from_existing(struct branch *b)
2630 oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
2631 } else {
2632 unsigned long size;
2633 + size_t size_st = 0;
2634 char *buf;
2635
2636 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);
2639 parse_from_commit(b, buf, size);
2640 free(buf);
2641 }
@@ -2722,7 +2727,7 @@ static struct hash_list *parse_merge(unsigned int *count)
2727 die(_("mark :%" PRIuMAX " not a commit"), idnum);
2728 oidcpy(&n->oid, &oe->idx.oid);
2729 } else if (!repo_get_oid(the_repository, from, &n->oid)) {
2725 - unsigned long size;
2730 + size_t size;
2731 char *buf = odb_read_object_peeled(the_repository->objects,
2732 &n->oid, OBJ_COMMIT,
2733 &size, &n->oid);
@@ -3330,7 +3335,10 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
3335 char *buf;
3336
3337 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);
3342 } else {
3343 type = oe->type;
3344 buf = gfi_unpack_entry(oe, &size);
@@ -3438,8 +3446,10 @@ static struct object_entry *dereference(struct object_entry *oe,
3446 buf = gfi_unpack_entry(oe, &size);
3447 } else {
3448 enum object_type unused;
3449 + size_t size_st = 0;
3450 buf = odb_read_object(the_repository->objects, oid,
3442 - &unused, &size);
3451 + &unused, &size_st);
3452 + size = cast_size_t_to_ulong(size_st);
3453 }
3454 if (!buf)
3455 die(_("can't load object %s"), oid_to_hex(oid));
builtin/fsck.c
+1 -1
@@ -724,7 +724,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
724 struct for_each_loose_cb *data = cb_data;
725 struct object *obj;
726 enum object_type type = OBJ_NONE;
727 - unsigned long size;
727 + size_t size;
728 void *contents = NULL;
729 int eaten;
730 struct object_info oi = OBJECT_INFO_INIT;
builtin/grep.c
+6 -6
@@ -520,7 +520,7 @@ static int grep_submodule(struct grep_opt *opt,
520 enum object_type object_type;
521 struct tree_desc tree;
522 void *data;
523 - unsigned long size;
523 + size_t size;
524 struct strbuf base = STRBUF_INIT;
525
526 obj_read_lock();
@@ -573,7 +573,7 @@ static int grep_cache(struct grep_opt *opt,
573 enum object_type type;
574 struct tree_desc tree;
575 void *data;
576 - unsigned long size;
576 + size_t size;
577
578 data = odb_read_object(the_repository->objects, &ce->oid,
579 &type, &size);
@@ -666,7 +666,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
666 enum object_type type;
667 struct tree_desc sub;
668 void *data;
669 - unsigned long size;
669 + size_t size;
670
671 data = odb_read_object(the_repository->objects,
672 &entry.oid, &type, &size);
@@ -730,7 +730,7 @@ static void collect_blob_oids_for_tree(struct repository *repo,
730 enum object_type type;
731 struct tree_desc sub_tree;
732 void *data;
733 - unsigned long size;
733 + size_t size;
734
735 data = odb_read_object(repo->objects, &entry.oid,
736 &type, &size);
@@ -764,7 +764,7 @@ static void collect_blob_oids_for_treeish(struct grep_opt *opt,
764 {
765 struct tree_desc tree;
766 void *data;
767 - unsigned long size;
767 + size_t size;
768 struct strbuf base = STRBUF_INIT;
769 int len;
770
@@ -841,7 +841,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
841 if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {
842 struct tree_desc tree;
843 void *data;
844 - unsigned long size;
844 + size_t size;
845 struct strbuf base;
846 int hit, len;
847
builtin/index-pack.c
+3 -3
@@ -258,7 +258,7 @@ static unsigned check_object(struct object *obj)
258 return 0;
259
260 if (!(obj->flags & FLAG_CHECKED)) {
261 - unsigned long size;
261 + size_t size;
262 int type = odb_read_object_info(the_repository->objects,
263 &obj->oid, &size);
264 if (type <= 0)
@@ -905,7 +905,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
905 if (collision_test_needed) {
906 void *has_data;
907 enum object_type has_type;
908 - unsigned long has_size;
908 + size_t has_size;
909 read_lock();
910 has_type = odb_read_object_info(the_repository->objects, oid, &has_size);
911 if (has_type < 0)
@@ -1515,7 +1515,7 @@ static void fix_unresolved_deltas(struct hashfile *f)
1515 struct ref_delta_entry *d = sorted_by_pos[i];
1516 enum object_type type;
1517 void *data;
1518 - unsigned long size;
1518 + size_t size;
1519
1520 if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
1521 continue;
builtin/log.c
+1 -1
@@ -613,7 +613,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
613
614 static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
615 {
616 - unsigned long size;
616 + size_t size;
617 enum object_type type;
618 char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
619 unsigned long offset = 0;
builtin/ls-files.c
+1 -1
@@ -256,7 +256,7 @@ static void expand_objectsize(struct repository *repo, struct strbuf *line,
256 size_t len;
257
258 if (type == OBJ_BLOB) {
259 - unsigned long size;
259 + size_t size;
260 if (odb_read_object_info(repo->objects, oid, &size) < 0)
261 die(_("could not get object info about '%s'"),
262 oid_to_hex(oid));
builtin/ls-tree.c
+2 -2
@@ -32,7 +32,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
32 size_t len;
33
34 if (type == OBJ_BLOB) {
35 - unsigned long size;
35 + size_t size;
36 if (odb_read_object_info(the_repository->objects, oid, &size) < 0)
37 die(_("could not get object info about '%s'"),
38 oid_to_hex(oid));
@@ -220,7 +220,7 @@ static int show_tree_long(const struct object_id *oid, struct strbuf *base,
220 return early;
221
222 if (type == OBJ_BLOB) {
223 - unsigned long size;
223 + size_t size;
224 if (odb_read_object_info(the_repository->objects, oid, &size) == OBJ_BAD)
225 xsnprintf(size_text, sizeof(size_text), "BAD");
226 else
builtin/merge-tree.c
+3 -3
@@ -69,7 +69,7 @@ static const char *explanation(struct merge_list *entry)
69 return "removed in remote";
70 }
71
72 -static void *result(struct merge_list *entry, unsigned long *size)
72 +static void *result(struct merge_list *entry, size_t *size)
73 {
74 enum object_type type;
75 struct blob *base, *our, *their;
@@ -96,7 +96,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
96 base, our, their, size);
97 }
98
99 -static void *origin(struct merge_list *entry, unsigned long *size)
99 +static void *origin(struct merge_list *entry, size_t *size)
100 {
101 enum object_type type;
102 while (entry) {
@@ -119,7 +119,7 @@ static int show_outf(void *priv UNUSED, mmbuffer_t *mb, int nbuf)
119
120 static void show_diff(struct merge_list *entry)
121 {
122 - unsigned long size;
122 + size_t size;
123 mmfile_t src, dst;
124 xpparam_t xpp;
125 xdemitconf_t xecfg;
builtin/mktag.c
+1 -1
@@ -50,7 +50,7 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
50 {
51 int ret;
52 enum object_type type;
53 - unsigned long size;
53 + size_t size;
54 void *buffer;
55 const struct object_id *repl;
56
builtin/notes.c
+3 -3
@@ -150,7 +150,7 @@ static int list_each_note(const struct object_id *object_oid,
150
151 static void copy_obj_to_fd(int fd, const struct object_id *oid)
152 {
153 - unsigned long size;
153 + size_t size;
154 enum object_type type;
155 char *buf = odb_read_object(the_repository->objects, oid, &type, &size);
156 if (buf) {
@@ -313,7 +313,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
313 char *value;
314 struct object_id object;
315 enum object_type type;
316 - unsigned long len;
316 + size_t len;
317
318 BUG_ON_OPT_NEG(unset);
319
@@ -721,7 +721,7 @@ static int append_edit(int argc, const char **argv, const char *prefix,
721
722 if (note && !edit) {
723 /* Append buf to previous note contents */
724 - unsigned long size;
724 + size_t size;
725 enum object_type type;
726 struct strbuf buf = STRBUF_INIT;
727 char *prev_buf = odb_read_object(the_repository->objects, note, &type, &size);
builtin/pack-objects.c
+23 -10
@@ -356,14 +356,17 @@ static void *get_delta(struct object_entry *entry)
356 unsigned long size, base_size, delta_size;
357 void *buf, *base_buf, *delta_buf;
358 enum object_type type;
359 + size_t size_st = 0, base_size_st = 0;
360
361 buf = odb_read_object(the_repository->objects, &entry->idx.oid,
361 - &type, &size);
362 + &type, &size_st);
363 + size = cast_size_t_to_ulong(size_st);
364 if (!buf)
365 die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
366 base_buf = odb_read_object(the_repository->objects,
367 &DELTA(entry)->idx.oid, &type,
366 - &base_size);
368 + &base_size_st);
369 + base_size = cast_size_t_to_ulong(base_size_st);
370 if (!base_buf)
371 die("unable to read %s",
372 oid_to_hex(&DELTA(entry)->idx.oid));
@@ -528,9 +531,11 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
531 type = st->type;
532 size = st->size;
533 } else {
534 + size_t size_st = 0;
535 buf = odb_read_object(the_repository->objects,
536 &entry->idx.oid, &type,
533 - &size);
537 + &size_st);
538 + size = cast_size_t_to_ulong(size_st);
539 if (!buf)
540 die(_("unable to read %s"),
541 oid_to_hex(&entry->idx.oid));
@@ -1937,6 +1942,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
1942 struct pbase_tree_cache *ent, *nent;
1943 void *data;
1944 unsigned long size;
1945 + size_t size_st = 0;
1946 enum object_type type;
1947 int neigh;
1948 int my_ix = pbase_tree_cache_ix(oid);
@@ -1964,7 +1970,8 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
1970 /* Did not find one. Either we got a bogus request or
1971 * we need to read and perhaps cache.
1972 */
1967 - data = odb_read_object(the_repository->objects, oid, &type, &size);
1973 + data = odb_read_object(the_repository->objects, oid, &type, &size_st);
1974 + size = cast_size_t_to_ulong(size_st);
1975 if (!data)
1976 return NULL;
1977 if (type != OBJ_TREE) {
@@ -2119,13 +2126,15 @@ static void add_preferred_base(struct object_id *oid)
2126 struct pbase_tree *it;
2127 void *data;
2128 unsigned long size;
2129 + size_t size_st = 0;
2130 struct object_id tree_oid;
2131
2132 if (window <= num_preferred_base++)
2133 return;
2134
2135 data = odb_read_object_peeled(the_repository->objects, oid,
2128 - OBJ_TREE, &size, &tree_oid);
2136 + OBJ_TREE, &size_st, &tree_oid);
2137 + size = cast_size_t_to_ulong(size_st);
2138 if (!data)
2139 return;
2140
@@ -2237,7 +2246,7 @@ static void prefetch_to_pack(uint32_t object_index_start) {
2246
2247 static void check_object(struct object_entry *entry, uint32_t object_index)
2248 {
2240 - unsigned long canonical_size;
2249 + size_t canonical_size;
2250 enum object_type type;
2251 struct object_info oi = {.typep = &type, .sizep = &canonical_size};
2252
@@ -2436,7 +2445,7 @@ static void drop_reused_delta(struct object_entry *entry)
2445 unsigned *idx = &to_pack.objects[entry->delta_idx - 1].delta_child_idx;
2446 struct object_info oi = OBJECT_INFO_INIT;
2447 enum object_type type;
2439 - unsigned long size;
2448 + size_t size;
2449
2450 while (*idx) {
2451 struct object_entry *oe = &to_pack.objects[*idx - 1];
@@ -2748,7 +2757,7 @@ size_t oe_get_size_slow(struct packing_data *pack,
2757 size_t size;
2758
2759 if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) {
2751 - unsigned long sz;
2760 + size_t sz;
2761 packing_data_lock(&to_pack);
2762 if (odb_read_object_info(the_repository->objects,
2763 &e->idx.oid, &sz) < 0)
@@ -2833,10 +2842,12 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
2842
2843 /* Load data if not already done */
2844 if (!trg->data) {
2845 + size_t sz_st = 0;
2846 packing_data_lock(&to_pack);
2847 trg->data = odb_read_object(the_repository->objects,
2848 &trg_entry->idx.oid, &type,
2839 - &sz);
2849 + &sz_st);
2850 + sz = cast_size_t_to_ulong(sz_st);
2851 packing_data_unlock(&to_pack);
2852 if (!trg->data)
2853 die(_("object %s cannot be read"),
@@ -2848,10 +2859,12 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
2859 *mem_usage += sz;
2860 }
2861 if (!src->data) {
2862 + size_t sz_st = 0;
2863 packing_data_lock(&to_pack);
2864 src->data = odb_read_object(the_repository->objects,
2865 &src_entry->idx.oid, &type,
2854 - &sz);
2866 + &sz_st);
2867 + sz = cast_size_t_to_ulong(sz_st);
2868 packing_data_unlock(&to_pack);
2869 if (!src->data) {
2870 if (src_entry->preferred_base) {
builtin/repo.c
+3 -1
@@ -784,13 +784,14 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
784 for (size_t i = 0; i < oids->nr; i++) {
785 struct object_info oi = OBJECT_INFO_INIT;
786 unsigned long inflated;
787 + size_t inflated_st = 0;
788 struct commit *commit;
789 struct object *obj;
790 void *content;
791 off_t disk;
792 int eaten;
793
793 - oi.sizep = &inflated;
794 + oi.sizep = &inflated_st;
795 oi.disk_sizep = &disk;
796 oi.contentp = &content;
797
@@ -798,6 +799,7 @@ static int count_objects(const char *path UNUSED, struct oid_array *oids,
799 OBJECT_INFO_SKIP_FETCH_OBJECT |
800 OBJECT_INFO_QUICK) < 0)
801 continue;
802 + inflated = cast_size_t_to_ulong(inflated_st);
803
804 obj = parse_object_buffer(the_repository, &oids->oid[i], type,
805 inflated, content, &eaten);
builtin/tag.c
+2 -2
@@ -238,7 +238,7 @@ static int git_tag_config(const char *var, const char *value,
238
239 static void write_tag_body(int fd, const struct object_id *oid)
240 {
241 - unsigned long size;
241 + size_t size;
242 enum object_type type;
243 char *buf, *sp, *orig;
244 struct strbuf payload = STRBUF_INIT;
@@ -388,7 +388,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
388 enum object_type type;
389 struct commit *c;
390 char *buf;
391 - unsigned long size;
391 + size_t size;
392 int subject_len = 0;
393 const char *subject_start;
394
builtin/unpack-file.c
+1 -1
@@ -12,7 +12,7 @@ static char *create_temp_file(struct object_id *oid)
12 static char path[50];
13 void *buf;
14 enum object_type type;
15 - unsigned long size;
15 + size_t size;
16 int fd;
17
18 buf = odb_read_object(the_repository->objects, oid, &type, &size);
builtin/unpack-objects.c
+4 -2
@@ -231,7 +231,7 @@ static int check_object(struct object *obj, enum object_type type,
231 die("object type mismatch");
232
233 if (!(obj->flags & FLAG_OPEN)) {
234 - unsigned long size;
234 + size_t size;
235 int type = odb_read_object_info(the_repository->objects, &obj->oid, &size);
236 if (type != obj->type || type <= 0)
237 die("object of unexpected type");
@@ -436,6 +436,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
436 {
437 void *delta_data, *base;
438 unsigned long base_size;
439 + size_t base_size_st = 0;
440 struct object_id base_oid;
441
442 if (type == OBJ_REF_DELTA) {
@@ -512,7 +513,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
513 return;
514
515 base = odb_read_object(the_repository->objects, &base_oid,
515 - &type, &base_size);
516 + &type, &base_size_st);
517 + base_size = cast_size_t_to_ulong(base_size_st);
518 if (!base) {
519 error("failed to read delta-pack base object %s",
520 oid_to_hex(&base_oid));
bundle.c
+1 -1
@@ -296,7 +296,7 @@ int list_bundle_refs(struct bundle_header *header, int argc, const char **argv)
296
297 static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
298 {
299 - unsigned long size;
299 + size_t size;
300 enum object_type type;
301 char *buf = NULL, *line, *lineend;
302 timestamp_t date;
combine-diff.c
+3 -1
@@ -325,7 +325,9 @@ static char *grab_blob(struct repository *r,
325 *size = fill_textconv(r, textconv, df, &blob);
326 free_filespec(df);
327 } else {
328 - blob = odb_read_object(r->objects, oid, &type, size);
328 + size_t size_st = 0;
329 + blob = odb_read_object(r->objects, oid, &type, &size_st);
330 + *size = cast_size_t_to_ulong(size_st);
331 if (!blob)
332 die(_("unable to read %s"), oid_to_hex(oid));
333 if (type != OBJ_BLOB)
commit.c
+5 -5
@@ -395,7 +395,7 @@ const void *repo_get_commit_buffer(struct repository *r,
395 const void *ret = get_cached_commit_buffer(r, commit, sizep);
396 if (!ret) {
397 enum object_type type;
398 - unsigned long size;
398 + size_t size;
399 ret = odb_read_object(r->objects, &commit->object.oid, &type, &size);
400 if (!ret)
401 die("cannot read commit object %s",
@@ -404,7 +404,7 @@ const void *repo_get_commit_buffer(struct repository *r,
404 die("expected commit for %s, got %s",
405 oid_to_hex(&commit->object.oid), type_name(type));
406 if (sizep)
407 - *sizep = size;
407 + *sizep = cast_size_t_to_ulong(size);
408 }
409 return ret;
410 }
@@ -437,7 +437,7 @@ static inline void set_commit_tree(struct commit *c, struct tree *t)
437 static void load_tree_from_commit_contents(struct repository *r, struct commit *commit)
438 {
439 enum object_type type;
440 - unsigned long size;
440 + size_t size;
441 char *buf;
442 const char *p;
443 struct object_id tree_oid;
@@ -604,7 +604,7 @@ int repo_parse_commit_internal(struct repository *r,
604 {
605 enum object_type type;
606 void *buffer;
607 - unsigned long size;
607 + size_t size;
608 struct object_info oi = {
609 .typep = &type,
610 .sizep = &size,
@@ -1313,7 +1313,7 @@ static void handle_signed_tag(const struct commit *parent, struct commit_extra_h
1313 struct merge_remote_desc *desc;
1314 struct commit_extra_header *mergetag;
1315 char *buf;
1316 - unsigned long size;
1316 + size_t size;
1317 enum object_type type;
1318 struct strbuf payload = STRBUF_INIT;
1319 struct strbuf signature = STRBUF_INIT;
config.c
+1 -1
@@ -1442,7 +1442,7 @@ int git_config_from_blob_oid(config_fn_t fn,
1442 {
1443 enum object_type type;
1444 char *buf;
1445 - unsigned long size;
1445 + size_t size;
1446 int ret;
1447
1448 buf = odb_read_object(repo->objects, oid, &type, &size);
diff.c
+4 -1
@@ -4594,8 +4594,9 @@ int diff_populate_filespec(struct repository *r,
4594 }
4595 }
4596 else {
4597 + size_t size_st = 0;
4598 struct object_info info = {
4598 - .sizep = &s->size
4599 + .sizep = &size_st
4600 };
4601
4602 if (!(size_only || check_binary))
@@ -4617,6 +4618,7 @@ int diff_populate_filespec(struct repository *r,
4618 die("unable to read %s", oid_to_hex(&s->oid));
4619
4620 object_read:
4621 + s->size = cast_size_t_to_ulong(size_st);
4622 if (size_only || check_binary) {
4623 if (size_only)
4624 return 0;
@@ -4631,6 +4633,7 @@ object_read:
4633 if (odb_read_object_info_extended(r->objects, &s->oid, &info,
4634 OBJECT_INFO_LOOKUP_REPLACE))
4635 die("unable to read %s", oid_to_hex(&s->oid));
4636 + s->size = cast_size_t_to_ulong(size_st);
4637 }
4638 s->should_free = 1;
4639 }
dir.c
+1 -1
@@ -324,7 +324,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
324 size_t *size_out, char **data_out)
325 {
326 enum object_type type;
327 - unsigned long sz;
327 + size_t sz;
328 char *data;
329
330 *size_out = 0;
entry.c
+1 -3
@@ -92,11 +92,9 @@ static int create_file(const char *path, unsigned int mode)
92 void *read_blob_entry(const struct cache_entry *ce, size_t *size)
93 {
94 enum object_type type;
95 - unsigned long ul;
95 void *blob_data = odb_read_object(the_repository->objects, &ce->oid,
97 - &type, &ul);
96 + &type, size);
97
99 - *size = ul;
98 if (blob_data) {
99 if (type == OBJ_BLOB)
100 return blob_data;
fmt-merge-msg.c
+2 -2
@@ -528,11 +528,11 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
528 for (i = 0; i < origins.nr; i++) {
529 struct object_id *oid = origins.items[i].util;
530 enum object_type type;
531 - unsigned long size;
531 + size_t size;
532 char *buf = odb_read_object(the_repository->objects, oid,
533 &type, &size);
534 char *origbuf = buf;
535 - unsigned long len = size;
535 + size_t len = size;
536 struct signature_check sigc = { NULL };
537 struct strbuf payload = STRBUF_INIT, sig = STRBUF_INIT;
538
fsck.c
+1 -1
@@ -1328,7 +1328,7 @@ static int fsck_blobs(struct oidset *blobs_found, struct oidset *blobs_done,
1328 oidset_iter_init(blobs_found, &iter);
1329 while ((oid = oidset_iter_next(&iter))) {
1330 enum object_type type;
1331 - unsigned long size;
1331 + size_t size;
1332 char *buf;
1333
1334 if (oidset_contains(blobs_done, oid))
grep.c
+3 -1
@@ -1931,9 +1931,11 @@ void grep_source_clear_data(struct grep_source *gs)
1931 static int grep_source_load_oid(struct grep_source *gs)
1932 {
1933 enum object_type type;
1934 + size_t size_st = 0;
1935
1936 gs->buf = odb_read_object(gs->repo->objects, gs->identifier,
1936 - &type, &gs->size);
1937 + &type, &size_st);
1938 + gs->size = cast_size_t_to_ulong(size_st);
1939 if (!gs->buf)
1940 return error(_("'%s': unable to read %s"),
1941 gs->name,
http-push.c
+1 -1
@@ -365,7 +365,7 @@ static void start_put(struct transfer_request *request)
365 enum object_type type;
366 char hdr[50];
367 void *unpacked;
368 - unsigned long len;
368 + size_t len;
369 int hdrlen;
370 ssize_t size;
371 git_zstream stream;
list-objects-filter.c
+1 -1
@@ -280,7 +280,7 @@ static enum list_objects_filter_result filter_blobs_limit(
280 void *filter_data_)
281 {
282 struct filter_blobs_limit_data *filter_data = filter_data_;
283 - unsigned long object_length;
283 + size_t object_length;
284 enum object_type t;
285
286 switch (filter_situation) {
mailmap.c
+1 -1
@@ -186,7 +186,7 @@ int read_mailmap_blob(struct repository *repo, struct string_list *map,
186 {
187 struct object_id oid;
188 char *buf;
189 - unsigned long size;
189 + size_t size;
190 enum object_type type;
191
192 if (!name)
match-trees.c
+2 -2
@@ -61,7 +61,7 @@ static void *fill_tree_desc_strict(struct repository *r,
61 {
62 void *buffer;
63 enum object_type type;
64 - unsigned long size;
64 + size_t size;
65
66 buffer = odb_read_object(r->objects, hash, &type, &size);
67 if (!buffer)
@@ -186,7 +186,7 @@ static int splice_tree(struct repository *r,
186 char *subpath;
187 int toplen;
188 char *buf;
189 - unsigned long sz;
189 + size_t sz;
190 struct tree_desc desc;
191 unsigned char *rewrite_here;
192 const struct object_id *rewrite_with;
merge-blobs.c
+3 -3
@@ -9,7 +9,7 @@
9 static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
10 {
11 void *buf;
12 - unsigned long size;
12 + size_t size;
13 enum object_type type;
14
15 buf = odb_read_object(the_repository->objects, &obj->object.oid,
@@ -35,7 +35,7 @@ static void *three_way_filemerge(struct index_state *istate,
35 mmfile_t *base,
36 mmfile_t *our,
37 mmfile_t *their,
38 - unsigned long *size)
38 + size_t *size)
39 {
40 enum ll_merge_result merge_status;
41 mmbuffer_t res;
@@ -61,7 +61,7 @@ static void *three_way_filemerge(struct index_state *istate,
61
62 void *merge_blobs(struct index_state *istate, const char *path,
63 struct blob *base, struct blob *our,
64 - struct blob *their, unsigned long *size)
64 + struct blob *their, size_t *size)
65 {
66 void *res = NULL;
67 mmfile_t f1, f2, common;
merge-blobs.h
+1 -1
@@ -6,6 +6,6 @@ struct index_state;
6
7 void *merge_blobs(struct index_state *, const char *,
8 struct blob *, struct blob *,
9 - struct blob *, unsigned long *);
9 + struct blob *, size_t *);
10
11 #endif /* MERGE_BLOBS_H */
merge-ort.c
+1 -1
@@ -3716,7 +3716,7 @@ static int read_oid_strbuf(struct merge_options *opt,
3716 {
3717 void *buf;
3718 enum object_type type;
3719 - unsigned long size;
3719 + size_t size;
3720 buf = odb_read_object(opt->repo->objects, oid, &type, &size);
3721 if (!buf) {
3722 path_msg(opt, ERROR_OBJECT_READ_FAILED, 0,
notes-cache.c
+1 -1
@@ -82,7 +82,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
82 const struct object_id *value_oid;
83 enum object_type type;
84 char *value;
85 - unsigned long size;
85 + size_t size;
86
87 value_oid = get_note(&c->tree, key_oid);
88 if (!value_oid)
notes-merge.c
+1 -1
@@ -339,7 +339,7 @@ static void write_note_to_worktree(const struct object_id *obj,
339 const struct object_id *note)
340 {
341 enum object_type type;
342 - unsigned long size;
342 + size_t size;
343 void *buf = odb_read_object(the_repository->objects, note, &type, &size);
344
345 if (!buf)
notes.c
+5 -3
@@ -811,7 +811,8 @@ int combine_notes_concatenate(struct object_id *cur_oid,
811 const struct object_id *new_oid)
812 {
813 char *cur_msg = NULL, *new_msg = NULL, *buf;
814 - unsigned long cur_len, new_len, buf_len;
814 + unsigned long buf_len;
815 + size_t cur_len, new_len;
816 enum object_type cur_type, new_type;
817 int ret;
818
@@ -875,7 +876,7 @@ static int string_list_add_note_lines(struct string_list *list,
876 const struct object_id *oid)
877 {
878 char *data;
878 - unsigned long len;
879 + size_t len;
880 enum object_type t;
881
882 if (is_null_oid(oid))
@@ -1282,7 +1283,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
1283 static const char utf8[] = "utf-8";
1284 const struct object_id *oid;
1285 char *msg, *msg_p;
1285 - unsigned long linelen, msglen;
1286 + unsigned long linelen;
1287 + size_t msglen;
1288 enum object_type type;
1289
1290 if (!t)
object-file.c
+3 -3
@@ -300,7 +300,7 @@ int parse_loose_header(const char *hdr, struct object_info *oi)
300 }
301
302 if (oi->sizep)
303 - *oi->sizep = cast_size_t_to_ulong(size);
303 + *oi->sizep = size;
304
305 /*
306 * The length must be followed by a zero byte
@@ -931,7 +931,7 @@ int force_object_loose(struct odb_source *source,
931 struct odb_source_files *files = odb_source_files_downcast(source);
932 const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
933 void *buf;
934 - unsigned long len;
934 + size_t len;
935 struct object_info oi = OBJECT_INFO_INIT;
936 struct object_id compat_oid;
937 enum object_type type;
@@ -1614,7 +1614,7 @@ int read_loose_object(struct repository *repo,
1614 unsigned long mapsize;
1615 git_zstream stream;
1616 char hdr[MAX_HEADER_LEN];
1617 - unsigned long *size = oi->sizep;
1617 + size_t *size = oi->sizep;
1618
1619 fd = git_open(path);
1620 if (fd >= 0)
object.c
+1 -1
@@ -325,7 +325,7 @@ struct object *parse_object_with_flags(struct repository *r,
325 {
326 int skip_hash = !!(flags & PARSE_OBJECT_SKIP_HASH_CHECK);
327 int discard_tree = !!(flags & PARSE_OBJECT_DISCARD_TREE);
328 - unsigned long size;
328 + size_t size;
329 enum object_type type;
330 int eaten;
331 const struct object_id *repl = lookup_replace_object(r, oid);
odb.c
+6 -6
@@ -625,7 +625,7 @@ static int oid_object_info_convert(struct repository *r,
625 enum object_type type;
626 struct object_id oid, delta_base_oid;
627 struct object_info new_oi, *oi;
628 - unsigned long size;
628 + size_t size;
629 void *content;
630 int ret;
631
@@ -716,7 +716,7 @@ int odb_read_object_info_extended(struct object_database *odb,
716 /* returns enum object_type or negative */
717 int odb_read_object_info(struct object_database *odb,
718 const struct object_id *oid,
719 - unsigned long *sizep)
719 + size_t *sizep)
720 {
721 enum object_type type;
722 struct object_info oi = OBJECT_INFO_INIT;
@@ -730,7 +730,7 @@ int odb_read_object_info(struct object_database *odb,
730 }
731
732 int odb_pretend_object(struct object_database *odb,
733 - void *buf, unsigned long len, enum object_type type,
733 + void *buf, size_t len, enum object_type type,
734 struct object_id *oid)
735 {
736 hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
@@ -744,7 +744,7 @@ int odb_pretend_object(struct object_database *odb,
744 void *odb_read_object(struct object_database *odb,
745 const struct object_id *oid,
746 enum object_type *type,
747 - unsigned long *size)
747 + size_t *size)
748 {
749 struct object_info oi = OBJECT_INFO_INIT;
750 unsigned flags = OBJECT_INFO_DIE_IF_CORRUPT | OBJECT_INFO_LOOKUP_REPLACE;
@@ -762,12 +762,12 @@ void *odb_read_object(struct object_database *odb,
762 void *odb_read_object_peeled(struct object_database *odb,
763 const struct object_id *oid,
764 enum object_type required_type,
765 - unsigned long *size,
765 + size_t *size,
766 struct object_id *actual_oid_return)
767 {
768 enum object_type type;
769 void *buffer;
770 - unsigned long isize;
770 + size_t isize;
771 struct object_id actual_oid;
772
773 oidcpy(&actual_oid, oid);
odb.h
+5 -5
@@ -228,12 +228,12 @@ struct odb_source *odb_add_to_alternates_memory(struct object_database *odb,
228 void *odb_read_object(struct object_database *odb,
229 const struct object_id *oid,
230 enum object_type *type,
231 - unsigned long *size);
231 + size_t *size);
232
233 void *odb_read_object_peeled(struct object_database *odb,
234 const struct object_id *oid,
235 enum object_type required_type,
236 - unsigned long *size,
236 + size_t *size,
237 struct object_id *oid_ret);
238
239 /*
@@ -245,13 +245,13 @@ void *odb_read_object_peeled(struct object_database *odb,
245 * that reference it.
246 */
247 int odb_pretend_object(struct object_database *odb,
248 - void *buf, unsigned long len, enum object_type type,
248 + void *buf, size_t len, enum object_type type,
249 struct object_id *oid);
250
251 struct object_info {
252 /* Request */
253 enum object_type *typep;
254 - unsigned long *sizep;
254 + size_t *sizep;
255 off_t *disk_sizep;
256 struct object_id *delta_base_oid;
257 void **contentp;
@@ -356,7 +356,7 @@ int odb_read_object_info_extended(struct object_database *odb,
356 */
357 int odb_read_object_info(struct object_database *odb,
358 const struct object_id *oid,
359 - unsigned long *sizep);
359 + size_t *sizep);
360
361 enum odb_has_object_flags {
362 /* Retry packed storage after checking packed and loose storage */
odb/source-loose.c
+2 -10
@@ -72,7 +72,7 @@ static int read_object_info_from_path(struct odb_source_loose *loose,
72 void *map = NULL;
73 git_zstream stream, *stream_to_end = NULL;
74 char hdr[MAX_HEADER_LEN];
75 - unsigned long size_scratch;
75 + size_t size_scratch;
76 enum object_type type_scratch;
77 struct stat st;
78
@@ -355,7 +355,6 @@ static int odb_source_loose_read_object_stream(struct odb_read_stream **out,
355 struct object_info oi = OBJECT_INFO_INIT;
356 struct odb_loose_read_stream *st;
357 unsigned long mapsize;
358 - unsigned long size_ul;
358 void *mapped;
359
360 mapped = odb_source_loose_map_object(loose, oid, &mapsize);
@@ -379,18 +378,11 @@ static int odb_source_loose_read_object_stream(struct odb_read_stream **out,
378 goto error;
379 }
380
382 - /*
383 - * object_info.sizep is unsigned long* (32-bit on Windows), but
384 - * st->base.size is size_t (64-bit). Use temporary variable.
385 - * Note: loose objects >4GB would still truncate here, but such
386 - * large loose objects are uncommon (they'd normally be packed).
387 - */
388 - oi.sizep = &size_ul;
381 + oi.sizep = &st->base.size;
382 oi.typep = &st->base.type;
383
384 if (parse_loose_header(st->hdr, &oi) < 0 || st->base.type < 0)
385 goto error;
393 - st->base.size = size_ul;
386
387 st->mapped = mapped;
388 st->mapsize = mapsize;
odb/streaming.c
+1 -12
@@ -157,26 +157,15 @@ static int open_istream_incore(struct odb_read_stream **out,
157 .base.read = read_istream_incore,
158 };
159 struct odb_incore_read_stream *st;
160 - unsigned long size_ul;
160 int ret;
161
162 oi.typep = &stream.base.type;
164 - /*
165 - * object_info.sizep is unsigned long* (32-bit on Windows), but
166 - * stream.base.size is size_t (64-bit). We use a temporary variable
167 - * because the types are incompatible. Note: this path still truncates
168 - * for >4GB objects, but large objects should use pack streaming
169 - * (packfile_store_read_object_stream) which handles size_t properly.
170 - * This incore fallback is only used for small objects or when pack
171 - * streaming is unavailable.
172 - */
173 - oi.sizep = &size_ul;
163 + oi.sizep = &stream.base.size;
164 oi.contentp = (void **)&stream.buf;
165 ret = odb_read_object_info_extended(odb, oid, &oi,
166 OBJECT_INFO_DIE_IF_CORRUPT);
167 if (ret)
168 return ret;
179 - stream.base.size = size_ul;
169
170 CALLOC_ARRAY(st, 1);
171 *st = stream;
pack-bitmap.c
+2 -2
@@ -1856,7 +1856,7 @@ static void filter_bitmap_blob_none(struct bitmap_index *bitmap_git,
1856 static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
1857 uint32_t pos)
1858 {
1859 - unsigned long size;
1859 + size_t size;
1860 struct object_info oi = OBJECT_INFO_INIT;
1861
1862 oi.sizep = &size;
@@ -1891,7 +1891,7 @@ static unsigned long get_size_by_pos(struct bitmap_index *bitmap_git,
1891 die(_("unable to get size of %s"), oid_to_hex(&obj->oid));
1892 }
1893
1894 - return size;
1894 + return cast_size_t_to_ulong(size);
1895 }
1896
1897 static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
packfile.c
+3 -9
@@ -1607,13 +1607,10 @@ static int packed_object_info_with_index_pos(struct packed_git *p, off_t obj_off
1607 * a "real" type later if the caller is interested.
1608 */
1609 if (oi->contentp) {
1610 - size_t size_st = 0;
1610 *oi->contentp = cache_or_unpack_entry(p->repo, p, obj_offset,
1612 - &size_st, &type);
1611 + oi->sizep, &type);
1612 if (!*oi->contentp)
1613 type = OBJ_BAD;
1615 - else if (oi->sizep)
1616 - *oi->sizep = cast_size_t_to_ulong(size_st);
1614 } else if (oi->sizep || oi->typep || oi->delta_base_oid) {
1615 type = unpack_object_header(p, &w_curs, &curpos, &size);
1616 }
@@ -1633,7 +1630,7 @@ static int packed_object_info_with_index_pos(struct packed_git *p, off_t obj_off
1630 goto out;
1631 }
1632 }
1636 - *oi->sizep = (unsigned long)size;
1633 + *oi->sizep = size;
1634 }
1635
1636 if (oi->disk_sizep || (oi->mtimep && p->is_cruft)) {
@@ -1919,7 +1916,6 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
1916 struct object_id base_oid;
1917 if (!(offset_to_pack_pos(p, obj_offset, &pos))) {
1918 struct object_info oi = OBJECT_INFO_INIT;
1922 - unsigned long bsz_ul = 0;
1919
1920 nth_packed_object_id(&base_oid, p,
1921 pack_pos_to_index(p, pos));
@@ -1930,13 +1926,11 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
1926 mark_bad_packed_object(p, &base_oid);
1927
1928 oi.typep = &type;
1933 - oi.sizep = &bsz_ul;
1929 + oi.sizep = &base_size;
1930 oi.contentp = &base;
1931 if (odb_read_object_info_extended(r->objects, &base_oid,
1932 &oi, 0) < 0)
1933 base = NULL;
1938 - else
1939 - base_size = bsz_ul;
1934
1935 external_base = base;
1936 }
path-walk.c
+1 -1
@@ -368,7 +368,7 @@ static int walk_path(struct path_walk_context *ctx,
368 struct oid_array filtered = OID_ARRAY_INIT;
369
370 for (size_t i = 0; i < list->oids.nr; i++) {
371 - unsigned long size;
371 + size_t size;
372
373 if (odb_read_object_info(ctx->repo->objects,
374 &list->oids.oid[i],
protocol-caps.c
+3 -2
@@ -50,7 +50,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
50 for_each_string_list_item (item, oid_str_list) {
51 const char *oid_str = item->string;
52 struct object_id oid;
53 - unsigned long object_size;
53 + size_t object_size;
54
55 if (get_oid_hex_algop(oid_str, &oid, r->hash_algo) < 0) {
56 packet_writer_error(
@@ -66,7 +66,8 @@ static void send_info(struct repository *r, struct packet_writer *writer,
66 if (odb_read_object_info(r->objects, &oid, &object_size) < 0) {
67 strbuf_addstr(&send_buffer, " ");
68 } else {
69 - strbuf_addf(&send_buffer, " %lu", object_size);
69 + strbuf_addf(&send_buffer, " %"PRIuMAX,
70 + (uintmax_t)object_size);
71 }
72 }
73
read-cache.c
+3 -3
@@ -250,7 +250,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
250 {
251 int match = -1;
252 void *buffer;
253 - unsigned long size;
253 + size_t size;
254 enum object_type type;
255 struct strbuf sb = STRBUF_INIT;
256
@@ -3462,7 +3462,7 @@ void *read_blob_data_from_index(struct index_state *istate,
3462 const char *path, unsigned long *size)
3463 {
3464 int pos, len;
3465 - unsigned long sz;
3465 + size_t sz;
3466 enum object_type type;
3467 void *data;
3468
@@ -3490,7 +3490,7 @@ void *read_blob_data_from_index(struct index_state *istate,
3490 return NULL;
3491 }
3492 if (size)
3493 - *size = sz;
3493 + *size = cast_size_t_to_ulong(sz);
3494 return data;
3495 }
3496
ref-filter.c
+1 -1
@@ -86,7 +86,7 @@ struct ref_trailer_buf {
86 static struct expand_data {
87 struct object_id oid;
88 enum object_type type;
89 - unsigned long size;
89 + size_t size;
90 off_t disk_size;
91 struct object_id delta_base_oid;
92 void *content;
reflog.c
+1 -1
@@ -154,7 +154,7 @@ static int tree_is_complete(const struct object_id *oid)
154
155 if (!tree->buffer) {
156 enum object_type type;
157 - unsigned long size;
157 + size_t size;
158 void *data = odb_read_object(the_repository->objects, oid,
159 &type, &size);
160 if (!data) {
rerere.c
+1 -1
@@ -990,7 +990,7 @@ static int handle_cache(struct index_state *istate,
990
991 while (pos < istate->cache_nr) {
992 enum object_type type;
993 - unsigned long size;
993 + size_t size;
994
995 ce = istate->cache[pos++];
996 if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
submodule-config.c
+1 -1
@@ -694,7 +694,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
694 enum lookup_type lookup_type)
695 {
696 struct strbuf rev = STRBUF_INIT;
697 - unsigned long config_size;
697 + size_t config_size;
698 char *config = NULL;
699 struct object_id oid;
700 enum object_type type;
t/helper/test-pack-deltas.c
+2 -1
@@ -48,7 +48,8 @@ static void write_ref_delta(struct hashfile *f,
48 struct object_id *base)
49 {
50 unsigned char header[MAX_PACK_OBJECT_HEADER];
51 - unsigned long size, base_size, delta_size, compressed_size, hdrlen;
51 + unsigned long delta_size, compressed_size, hdrlen;
52 + size_t size, base_size;
53 enum object_type type;
54 void *base_buf, *delta_buf;
55 void *buf = odb_read_object(the_repository->objects,
t/helper/test-partial-clone.c
+1 -1
@@ -17,7 +17,7 @@ static void object_info(const char *gitdir, const char *oid_hex)
17 {
18 struct repository r;
19 struct object_id oid;
20 - unsigned long size;
20 + size_t size;
21 struct object_info oi = {.sizep = &size};
22 const char *p;
23
t/unit-tests/u-odb-inmemory.c
+1 -1
@@ -20,7 +20,7 @@ static void cl_assert_object_info(struct odb_source_inmemory *source,
20 const char *expected_content)
21 {
22 enum object_type actual_type;
23 - unsigned long actual_size;
23 + size_t actual_size;
24 void *actual_content;
25 struct object_info oi = {
26 .typep = &actual_type,
tag.c
+2 -2
@@ -49,7 +49,7 @@ int gpg_verify_tag(struct repository *r, const struct object_id *oid,
49 {
50 enum object_type type;
51 char *buf;
52 - unsigned long size;
52 + size_t size;
53 int ret;
54
55 type = odb_read_object_info(r->objects, oid, NULL);
@@ -207,7 +207,7 @@ int parse_tag(struct repository *r, struct tag *item)
207 {
208 enum object_type type;
209 void *data;
210 - unsigned long size;
210 + size_t size;
211 int ret;
212
213 if (item->object.parsed)
tree-walk.c
+6 -4
@@ -87,7 +87,7 @@ void *fill_tree_descriptor(struct repository *r,
87 struct tree_desc *desc,
88 const struct object_id *oid)
89 {
90 - unsigned long size = 0;
90 + size_t size = 0;
91 void *buf = NULL;
92
93 if (oid) {
@@ -610,7 +610,7 @@ int get_tree_entry(struct repository *r,
610 {
611 int retval;
612 void *tree;
613 - unsigned long size;
613 + size_t size;
614 struct object_id root;
615
616 tree = odb_read_object_peeled(r->objects, tree_oid, OBJ_TREE, &size, &root);
@@ -682,7 +682,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
682 if (!t.buffer) {
683 void *tree;
684 struct object_id root;
685 - unsigned long size;
685 + size_t size;
686 tree = odb_read_object_peeled(r->objects, &current_tree_oid,
687 OBJ_TREE, &size, &root);
688 if (!tree)
@@ -778,6 +778,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
778 } else if (S_ISLNK(*mode)) {
779 /* Follow a symlink */
780 unsigned long link_len;
781 + size_t link_len_st = 0;
782 size_t len;
783 char *contents, *contents_start;
784 struct dir_state *parent;
@@ -797,7 +798,8 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
798
799 contents = odb_read_object(r->objects,
800 &current_tree_oid, &type,
800 - &link_len);
801 + &link_len_st);
802 + link_len = cast_size_t_to_ulong(link_len_st);
803
804 if (!contents)
805 goto done;
tree.c
+1 -1
@@ -188,7 +188,7 @@ int repo_parse_tree_gently(struct repository *r, struct tree *item,
188 {
189 enum object_type type;
190 void *buffer;
191 - unsigned long size;
191 + size_t size;
192
193 if (item->object.parsed)
194 return 0;
xdiff-interface.c
+1 -1
@@ -179,7 +179,7 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
179 void read_mmblob(mmfile_t *ptr, struct object_database *odb,
180 const struct object_id *oid)
181 {
182 - unsigned long size;
182 + size_t size;
183 enum object_type type;
184
185 if (is_null_oid(oid)) {