Skip to content

Commit b391157

Browse files
committed
Merge branch 'topic/size-t-followups' (size_t followups depending on seen topics)
2 parents 38d2054 + bd09298 commit b391157

6 files changed

Lines changed: 31 additions & 68 deletions

File tree

blame.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,20 +2861,18 @@ void setup_scoreboard(struct blame_scoreboard *sb,
28612861
sb->final_buf_size = o->file.size;
28622862
}
28632863
else {
2864-
size_t final_buf_size_st = 0;
28652864
o = get_origin(sb->final, sb->path);
28662865
if (fill_blob_sha1_and_mode(sb->repo, o))
28672866
die(_("no such path %s in %s"), sb->path, final_commit_name);
28682867

28692868
if (sb->revs->diffopt.flags.allow_textconv &&
28702869
textconv_object(sb->repo, sb->path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
2871-
&final_buf_size_st))
2870+
&sb->final_buf_size))
28722871
;
28732872
else
28742873
sb->final_buf = odb_read_object(the_repository->objects,
28752874
&o->blob_oid, &type,
2876-
&final_buf_size_st);
2877-
sb->final_buf_size = cast_size_t_to_ulong(final_buf_size_st);
2875+
&sb->final_buf_size);
28782876

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

blame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct blame_scoreboard {
117117
* indexed with scoreboard.lineno[blame_entry.lno].
118118
*/
119119
char *final_buf;
120-
unsigned long final_buf_size;
120+
size_t final_buf_size;
121121

122122
/* linked list of blames */
123123
struct blame_entry *ent;

builtin/fast-import.c

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ static int store_object(
962962
struct object_entry *e;
963963
unsigned char hdr[96];
964964
struct object_id oid;
965-
unsigned long hdrlen, deltalen;
965+
size_t hdrlen, deltalen;
966966
struct git_hash_ctx c;
967967
git_zstream s;
968968
struct repo_config_values *cfg = repo_config_values(the_repository);
@@ -998,13 +998,10 @@ static int store_object(
998998

999999
if (last && last->data.len && last->data.buf && last->depth < max_depth
10001000
&& dat->len > the_hash_algo->rawsz) {
1001-
size_t deltalen_st = 0;
1002-
10031001
delta_count_attempts_by_type[type]++;
10041002
delta = diff_delta(last->data.buf, last->data.len,
10051003
dat->buf, dat->len,
1006-
&deltalen_st, dat->len - the_hash_algo->rawsz);
1007-
deltalen = cast_size_t_to_ulong(deltalen_st);
1004+
&deltalen, dat->len - the_hash_algo->rawsz);
10081005
} else
10091006
delta = NULL;
10101007

@@ -1240,10 +1237,9 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
12401237
*/
12411238
static void *gfi_unpack_entry(
12421239
struct object_entry *oe,
1243-
unsigned long *sizep)
1240+
size_t *sizep)
12441241
{
12451242
enum object_type type;
1246-
size_t size_st = 0;
12471243
void *data;
12481244
struct packed_git *p = all_packs[oe->pack_id];
12491245
if (p == pack_data && p->pack_size < (pack_size + the_hash_algo->rawsz)) {
@@ -1266,9 +1262,7 @@ static void *gfi_unpack_entry(
12661262
*/
12671263
p->pack_size = pack_size + the_hash_algo->rawsz;
12681264
}
1269-
data = unpack_entry(the_repository, p, oe->idx.offset, &type, &size_st);
1270-
if (sizep)
1271-
*sizep = cast_size_t_to_ulong(size_st);
1265+
data = unpack_entry(the_repository, p, oe->idx.offset, &type, sizep);
12721266
return data;
12731267
}
12741268

@@ -1277,7 +1271,7 @@ static void load_tree(struct tree_entry *root)
12771271
struct object_id *oid = &root->versions[1].oid;
12781272
struct object_entry *myoe;
12791273
struct tree_content *t;
1280-
unsigned long size;
1274+
size_t size;
12811275
char *buf;
12821276
const char *c;
12831277

@@ -1295,10 +1289,8 @@ static void load_tree(struct tree_entry *root)
12951289
die(_("can't load tree %s"), oid_to_hex(oid));
12961290
} else {
12971291
enum object_type type;
1298-
size_t size_st = 0;
12991292
buf = odb_read_object(the_repository->objects, oid, &type,
1300-
&size_st);
1301-
size = cast_size_t_to_ulong(size_st);
1293+
&size);
13021294
if (!buf || type != OBJ_TREE)
13031295
die(_("can't load tree %s"), oid_to_hex(oid));
13041296
}
@@ -2616,7 +2608,7 @@ static void file_change_deleteall(struct branch *b)
26162608
b->num_notes = 0;
26172609
}
26182610

2619-
static void parse_from_commit(struct branch *b, char *buf, unsigned long size)
2611+
static void parse_from_commit(struct branch *b, char *buf, size_t size)
26202612
{
26212613
if (!buf || size < the_hash_algo->hexsz + 6)
26222614
die(_("not a valid commit: %s"), oid_to_hex(&b->oid));
@@ -2633,13 +2625,11 @@ static void parse_from_existing(struct branch *b)
26332625
oidclr(&b->branch_tree.versions[0].oid, the_repository->hash_algo);
26342626
oidclr(&b->branch_tree.versions[1].oid, the_repository->hash_algo);
26352627
} else {
2636-
unsigned long size;
2637-
size_t size_st = 0;
2628+
size_t size;
26382629
char *buf;
26392630

26402631
buf = odb_read_object_peeled(the_repository->objects, &b->oid,
2641-
OBJ_COMMIT, &size_st, &b->oid);
2642-
size = cast_size_t_to_ulong(size_st);
2632+
OBJ_COMMIT, &size, &b->oid);
26432633
parse_from_commit(b, buf, size);
26442634
free(buf);
26452635
}
@@ -2668,7 +2658,7 @@ static int parse_objectish(struct branch *b, const char *objectish)
26682658
if (!oideq(&b->oid, &oe->idx.oid)) {
26692659
oidcpy(&b->oid, &oe->idx.oid);
26702660
if (oe->pack_id != MAX_PACK_ID) {
2671-
unsigned long size;
2661+
size_t size;
26722662
char *buf = gfi_unpack_entry(oe, &size);
26732663
parse_from_commit(b, buf, size);
26742664
free(buf);
@@ -3334,15 +3324,13 @@ static void cat_blob_write(const char *buf, unsigned long size)
33343324
static void cat_blob(struct object_entry *oe, struct object_id *oid)
33353325
{
33363326
struct strbuf line = STRBUF_INIT;
3337-
unsigned long size;
3327+
size_t size;
33383328
enum object_type type = 0;
33393329
char *buf;
33403330

33413331
if (!oe || oe->pack_id == MAX_PACK_ID) {
3342-
size_t size_st = 0;
33433332
buf = odb_read_object(the_repository->objects, oid, &type,
3344-
&size_st);
3345-
size = cast_size_t_to_ulong(size_st);
3333+
&size);
33463334
} else {
33473335
type = oe->type;
33483336
buf = gfi_unpack_entry(oe, &size);
@@ -3421,7 +3409,7 @@ static void parse_cat_blob(const char *p)
34213409
static struct object_entry *dereference(struct object_entry *oe,
34223410
struct object_id *oid)
34233411
{
3424-
unsigned long size;
3412+
size_t size;
34253413
char *buf = NULL;
34263414
const unsigned hexsz = the_hash_algo->hexsz;
34273415

@@ -3450,10 +3438,8 @@ static struct object_entry *dereference(struct object_entry *oe,
34503438
buf = gfi_unpack_entry(oe, &size);
34513439
} else {
34523440
enum object_type unused;
3453-
size_t size_st = 0;
34543441
buf = odb_read_object(the_repository->objects, oid,
3455-
&unused, &size_st);
3456-
size = cast_size_t_to_ulong(size_st);
3442+
&unused, &size);
34573443
}
34583444
if (!buf)
34593445
die(_("can't load object %s"), oid_to_hex(oid));

builtin/pack-objects.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,21 +353,17 @@ static void index_commit_for_bitmap(struct commit *commit)
353353

354354
static void *get_delta(struct object_entry *entry)
355355
{
356-
unsigned long size, base_size;
357-
size_t delta_size;
356+
size_t size, base_size, delta_size;
358357
void *buf, *base_buf, *delta_buf;
359358
enum object_type type;
360-
size_t size_st = 0, base_size_st = 0;
361359

362360
buf = odb_read_object(the_repository->objects, &entry->idx.oid,
363-
&type, &size_st);
364-
size = cast_size_t_to_ulong(size_st);
361+
&type, &size);
365362
if (!buf)
366363
die(_("unable to read %s"), oid_to_hex(&entry->idx.oid));
367364
base_buf = odb_read_object(the_repository->objects,
368365
&DELTA(entry)->idx.oid, &type,
369-
&base_size_st);
370-
base_size = cast_size_t_to_ulong(base_size_st);
366+
&base_size);
371367
if (!base_buf)
372368
die("unable to read %s",
373369
oid_to_hex(&DELTA(entry)->idx.oid));
@@ -385,11 +381,11 @@ static void *get_delta(struct object_entry *entry)
385381
return delta_buf;
386382
}
387383

388-
static unsigned long do_compress(void **pptr, unsigned long size)
384+
static size_t do_compress(void **pptr, size_t size)
389385
{
390386
git_zstream stream;
391387
void *in, *out;
392-
unsigned long maxsize;
388+
size_t maxsize;
393389
struct repo_config_values *cfg = repo_config_values(the_repository);
394390

395391
git_deflate_init(&stream, cfg->pack_compression_level);
@@ -515,7 +511,7 @@ static inline int oe_size_greater_than(struct packing_data *pack,
515511
static unsigned long write_no_reuse_object(struct hashfile *f, struct object_entry *entry,
516512
unsigned long limit, int usable_delta)
517513
{
518-
unsigned long size, datalen;
514+
size_t size, datalen;
519515
unsigned char header[MAX_PACK_OBJECT_HEADER],
520516
dheader[MAX_PACK_OBJECT_HEADER];
521517
unsigned hdrlen;
@@ -534,11 +530,9 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
534530
type = st->type;
535531
size = st->size;
536532
} else {
537-
size_t size_st = 0;
538533
buf = odb_read_object(the_repository->objects,
539534
&entry->idx.oid, &type,
540-
&size_st);
541-
size = cast_size_t_to_ulong(size_st);
535+
&size);
542536
if (!buf)
543537
die(_("unable to read %s"),
544538
oid_to_hex(&entry->idx.oid));
@@ -2788,8 +2782,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
27882782
{
27892783
struct object_entry *trg_entry = trg->entry;
27902784
struct object_entry *src_entry = src->entry;
2791-
unsigned long trg_size, src_size, sizediff, max_size, sz;
2792-
size_t delta_size;
2785+
size_t trg_size, src_size, delta_size, sizediff, max_size, sz;
27932786
unsigned ref_depth;
27942787
enum object_type type;
27952788
void *delta_buf;
@@ -2842,12 +2835,10 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
28422835

28432836
/* Load data if not already done */
28442837
if (!trg->data) {
2845-
size_t sz_st = 0;
28462838
packing_data_lock(&to_pack);
28472839
trg->data = odb_read_object(the_repository->objects,
28482840
&trg_entry->idx.oid, &type,
2849-
&sz_st);
2850-
sz = cast_size_t_to_ulong(sz_st);
2841+
&sz);
28512842
packing_data_unlock(&to_pack);
28522843
if (!trg->data)
28532844
die(_("object %s cannot be read"),
@@ -2859,12 +2850,10 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
28592850
*mem_usage += sz;
28602851
}
28612852
if (!src->data) {
2862-
size_t sz_st = 0;
28632853
packing_data_lock(&to_pack);
28642854
src->data = odb_read_object(the_repository->objects,
28652855
&src_entry->idx.oid, &type,
2866-
&sz_st);
2867-
sz = cast_size_t_to_ulong(sz_st);
2856+
&sz);
28682857
packing_data_unlock(&to_pack);
28692858
if (!src->data) {
28702859
if (src_entry->preferred_base) {

git-compat-util.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,15 +699,6 @@ static inline size_t st_left_shift(size_t a, unsigned shift)
699699
return a << shift;
700700
}
701701

702-
static inline unsigned long cast_size_t_to_ulong(size_t a)
703-
{
704-
if (a != (unsigned long)a)
705-
die("object too large to read on this platform: %"
706-
PRIuMAX" is cut off to %lu",
707-
(uintmax_t)a, (unsigned long)a);
708-
return (unsigned long)a;
709-
}
710-
711702
static inline uint32_t cast_size_t_to_uint32_t(size_t a)
712703
{
713704
if (a != (uint32_t)a)

t/helper/test-pack-deltas.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static const char *usage_str[] = {
1818
NULL
1919
};
2020

21-
static unsigned long do_compress(void **pptr, unsigned long size)
21+
static size_t do_compress(void **pptr, size_t size)
2222
{
2323
git_zstream stream;
2424
void *in, *out;
@@ -48,8 +48,8 @@ static void write_ref_delta(struct hashfile *f,
4848
struct object_id *base)
4949
{
5050
unsigned char header[MAX_PACK_OBJECT_HEADER];
51-
unsigned long delta_size, compressed_size, hdrlen;
52-
size_t size, base_size, delta_size_st = 0;
51+
unsigned long compressed_size, hdrlen;
52+
size_t size, base_size, delta_size;
5353
enum object_type type;
5454
void *base_buf, *delta_buf;
5555
void *buf = odb_read_object(the_repository->objects,
@@ -65,8 +65,7 @@ static void write_ref_delta(struct hashfile *f,
6565
die("unable to read %s", oid_to_hex(base));
6666

6767
delta_buf = diff_delta(base_buf, base_size,
68-
buf, size, &delta_size_st, 0);
69-
delta_size = cast_size_t_to_ulong(delta_size_st);
68+
buf, size, &delta_size, 0);
7069

7170
compressed_size = do_compress(&delta_buf, delta_size);
7271

0 commit comments

Comments
 (0)