Skip to content

Commit 6777a59

Browse files
spearceJunio C Hamano
authored andcommitted
Use off_t in pack-objects/fast-import when we mean an offset
Always use an off_t value in pack-objects anytime we are dealing with an offset to some data within a packfile. Also fixed a minor uintmax_t that was incorrectly defined before. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c4001d9 commit 6777a59

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

builtin-pack-objects.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ git-pack-objects [{ -q | --progress | --all-progress }] \n\
2323
struct object_entry {
2424
unsigned char sha1[20];
2525
unsigned long size; /* uncompressed size */
26-
unsigned long offset; /* offset into the final pack file;
26+
off_t offset; /* offset into the final pack file;
2727
* nonzero if already written.
2828
*/
2929
unsigned int depth; /* delta depth */
@@ -35,7 +35,7 @@ struct object_entry {
3535
#define in_pack_header_size delta_size /* only when reusing pack data */
3636
struct object_entry *delta; /* delta base object */
3737
struct packed_git *in_pack; /* already in pack */
38-
unsigned int in_pack_offset;
38+
off_t in_pack_offset;
3939
struct object_entry *delta_child; /* deltified objects who bases me */
4040
struct object_entry *delta_sibling; /* other deltified objects who
4141
* uses the same base as me
@@ -101,7 +101,7 @@ static int object_ix_hashsz;
101101
* get the object sha1 from the main index.
102102
*/
103103
struct revindex_entry {
104-
unsigned int offset;
104+
off_t offset;
105105
unsigned int nr;
106106
};
107107
struct pack_revindex {
@@ -183,7 +183,7 @@ static void prepare_pack_revindex(struct pack_revindex *rix)
183183
}
184184

185185
static struct revindex_entry * find_packed_object(struct packed_git *p,
186-
unsigned int ofs)
186+
off_t ofs)
187187
{
188188
int num;
189189
int lo, hi;
@@ -211,15 +211,14 @@ static struct revindex_entry * find_packed_object(struct packed_git *p,
211211
die("internal error: pack revindex corrupt");
212212
}
213213

214-
static unsigned long find_packed_object_size(struct packed_git *p,
215-
unsigned long ofs)
214+
static off_t find_packed_object_size(struct packed_git *p, off_t ofs)
216215
{
217216
struct revindex_entry *entry = find_packed_object(p, ofs);
218217
return entry[1].offset - ofs;
219218
}
220219

221220
static unsigned char *find_packed_object_name(struct packed_git *p,
222-
unsigned long ofs)
221+
off_t ofs)
223222
{
224223
struct revindex_entry *entry = find_packed_object(p, ofs);
225224
return (unsigned char *)(p->index_base + 256) + 24 * entry->nr + 4;
@@ -276,8 +275,8 @@ static int encode_header(enum object_type type, unsigned long size, unsigned cha
276275
*/
277276
static int check_pack_inflate(struct packed_git *p,
278277
struct pack_window **w_curs,
279-
unsigned long offset,
280-
unsigned long len,
278+
off_t offset,
279+
off_t len,
281280
unsigned long expect)
282281
{
283282
z_stream stream;
@@ -303,16 +302,16 @@ static int check_pack_inflate(struct packed_git *p,
303302
static void copy_pack_data(struct sha1file *f,
304303
struct packed_git *p,
305304
struct pack_window **w_curs,
306-
unsigned long offset,
307-
unsigned long len)
305+
off_t offset,
306+
off_t len)
308307
{
309308
unsigned char *in;
310309
unsigned int avail;
311310

312311
while (len) {
313312
in = use_pack(p, w_curs, offset, &avail);
314313
if (avail > len)
315-
avail = len;
314+
avail = (unsigned int)len;
316315
sha1write(f, in, avail);
317316
offset += avail;
318317
len -= avail;
@@ -369,14 +368,15 @@ static int revalidate_loose_object(struct object_entry *entry,
369368
return check_loose_inflate(map, mapsize, size);
370369
}
371370

372-
static unsigned long write_object(struct sha1file *f,
371+
static off_t write_object(struct sha1file *f,
373372
struct object_entry *entry)
374373
{
375374
unsigned long size;
376375
enum object_type type;
377376
void *buf;
378377
unsigned char header[10];
379-
unsigned hdrlen, datalen;
378+
unsigned hdrlen;
379+
off_t datalen;
380380
enum object_type obj_type;
381381
int to_reuse = 0;
382382

@@ -439,7 +439,7 @@ static unsigned long write_object(struct sha1file *f,
439439
* encoding of the relative offset for the delta
440440
* base from this object's position in the pack.
441441
*/
442-
unsigned long ofs = entry->offset - entry->delta->offset;
442+
off_t ofs = entry->offset - entry->delta->offset;
443443
unsigned pos = sizeof(header) - 1;
444444
header[pos] = ofs & 127;
445445
while (ofs >>= 7)
@@ -460,7 +460,7 @@ static unsigned long write_object(struct sha1file *f,
460460
else {
461461
struct packed_git *p = entry->in_pack;
462462
struct pack_window *w_curs = NULL;
463-
unsigned long offset;
463+
off_t offset;
464464

465465
if (entry->delta) {
466466
obj_type = (allow_ofs_delta && entry->delta->offset) ?
@@ -470,7 +470,7 @@ static unsigned long write_object(struct sha1file *f,
470470
hdrlen = encode_header(obj_type, entry->size, header);
471471
sha1write(f, header, hdrlen);
472472
if (obj_type == OBJ_OFS_DELTA) {
473-
unsigned long ofs = entry->offset - entry->delta->offset;
473+
off_t ofs = entry->offset - entry->delta->offset;
474474
unsigned pos = sizeof(header) - 1;
475475
header[pos] = ofs & 127;
476476
while (ofs >>= 7)
@@ -498,9 +498,9 @@ static unsigned long write_object(struct sha1file *f,
498498
return hdrlen + datalen;
499499
}
500500

501-
static unsigned long write_one(struct sha1file *f,
501+
static off_t write_one(struct sha1file *f,
502502
struct object_entry *e,
503-
unsigned long offset)
503+
off_t offset)
504504
{
505505
if (e->offset || e->preferred_base)
506506
/* offset starts from header size and cannot be zero
@@ -518,7 +518,7 @@ static void write_pack_file(void)
518518
{
519519
uint32_t i;
520520
struct sha1file *f;
521-
unsigned long offset;
521+
off_t offset;
522522
struct pack_header hdr;
523523
unsigned last_percent = 999;
524524
int do_progress = progress;
@@ -671,13 +671,13 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud
671671
uint32_t idx = nr_objects;
672672
struct object_entry *entry;
673673
struct packed_git *p;
674-
unsigned int found_offset = 0;
674+
off_t found_offset = 0;
675675
struct packed_git *found_pack = NULL;
676676
int ix, status = 0;
677677

678678
if (!exclude) {
679679
for (p = packed_git; p; p = p->next) {
680-
unsigned long offset = find_pack_entry_one(sha1, p);
680+
off_t offset = find_pack_entry_one(sha1, p);
681681
if (offset) {
682682
if (incremental)
683683
return 0;
@@ -978,17 +978,17 @@ static void check_object(struct object_entry *entry)
978978
if (entry->in_pack && !entry->preferred_base) {
979979
struct packed_git *p = entry->in_pack;
980980
struct pack_window *w_curs = NULL;
981-
unsigned long left = p->pack_size - entry->in_pack_offset;
982981
unsigned long size, used;
982+
unsigned int avail;
983983
unsigned char *buf;
984984
struct object_entry *base_entry = NULL;
985985

986-
buf = use_pack(p, &w_curs, entry->in_pack_offset, NULL);
986+
buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail);
987987

988988
/* We want in_pack_type even if we do not reuse delta.
989989
* There is no point not reusing non-delta representations.
990990
*/
991-
used = unpack_object_header_gently(buf, left,
991+
used = unpack_object_header_gently(buf, avail,
992992
&entry->in_pack_type, &size);
993993

994994
/* Check if it is delta, and the base is also an object
@@ -997,7 +997,7 @@ static void check_object(struct object_entry *entry)
997997
*/
998998
if (!no_reuse_delta) {
999999
unsigned char c, *base_name;
1000-
unsigned long ofs;
1000+
off_t ofs;
10011001
unsigned long used_0;
10021002
/* there is at least 20 bytes left in the pack */
10031003
switch (entry->in_pack_type) {

fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ typedef enum {
249249

250250
/* Configured limits on output */
251251
static unsigned long max_depth = 10;
252-
static unsigned long max_packsize = (1LL << 32) - 1;
252+
static off_t max_packsize = (1LL << 32) - 1;
253253
static int force_update;
254254

255255
/* Stats and misc. counters */
@@ -1527,7 +1527,7 @@ static void unload_one_branch(void)
15271527
{
15281528
while (cur_active_branches
15291529
&& cur_active_branches >= max_active_branches) {
1530-
unsigned long min_commit = ULONG_MAX;
1530+
uintmax_t min_commit = ULONG_MAX;
15311531
struct branch *e, *l = NULL, *p = NULL;
15321532

15331533
for (e = active_branches; e; e = e->active_next_branch) {

0 commit comments

Comments
 (0)