@matheusbsbs / matheus-bagliano / commits / 6777a59fcd
Fork 0

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 <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn O. Pearce committed Mar 6, 2007 at 20:44 UTC 6777a59fcdfd96b9ca5cba49cb265c6c47de3d02
2 files changed +28 -28
builtin-pack-objects.c
+26 -26
@@ -23,7 +23,7 @@ git-pack-objects [{ -q | --progress | --all-progress }] \n\
23 struct object_entry {
24 unsigned char sha1[20];
25 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;
27 * nonzero if already written.
28 */
29 unsigned int depth; /* delta depth */
@@ -35,7 +35,7 @@ struct object_entry {
35 #define in_pack_header_size delta_size /* only when reusing pack data */
36 struct object_entry *delta; /* delta base object */
37 struct packed_git *in_pack; /* already in pack */
38 - unsigned int in_pack_offset;
38 + off_t in_pack_offset;
39 struct object_entry *delta_child; /* deltified objects who bases me */
40 struct object_entry *delta_sibling; /* other deltified objects who
41 * uses the same base as me
@@ -101,7 +101,7 @@ static int object_ix_hashsz;
101 * get the object sha1 from the main index.
102 */
103 struct revindex_entry {
104 - unsigned int offset;
104 + off_t offset;
105 unsigned int nr;
106 };
107 struct pack_revindex {
@@ -183,7 +183,7 @@ static void prepare_pack_revindex(struct pack_revindex *rix)
183 }
184
185 static struct revindex_entry * find_packed_object(struct packed_git *p,
186 - unsigned int ofs)
186 + off_t ofs)
187 {
188 int num;
189 int lo, hi;
@@ -211,15 +211,14 @@ static struct revindex_entry * find_packed_object(struct packed_git *p,
211 die("internal error: pack revindex corrupt");
212 }
213
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)
215 {
216 struct revindex_entry *entry = find_packed_object(p, ofs);
217 return entry[1].offset - ofs;
218 }
219
220 static unsigned char *find_packed_object_name(struct packed_git *p,
222 - unsigned long ofs)
221 + off_t ofs)
222 {
223 struct revindex_entry *entry = find_packed_object(p, ofs);
224 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
275 */
276 static int check_pack_inflate(struct packed_git *p,
277 struct pack_window **w_curs,
279 - unsigned long offset,
280 - unsigned long len,
278 + off_t offset,
279 + off_t len,
280 unsigned long expect)
281 {
282 z_stream stream;
@@ -303,8 +302,8 @@ static int check_pack_inflate(struct packed_git *p,
302 static void copy_pack_data(struct sha1file *f,
303 struct packed_git *p,
304 struct pack_window **w_curs,
306 - unsigned long offset,
307 - unsigned long len)
305 + off_t offset,
306 + off_t len)
307 {
308 unsigned char *in;
309 unsigned int avail;
@@ -312,7 +311,7 @@ static void copy_pack_data(struct sha1file *f,
311 while (len) {
312 in = use_pack(p, w_curs, offset, &avail);
313 if (avail > len)
315 - avail = len;
314 + avail = (unsigned int)len;
315 sha1write(f, in, avail);
316 offset += avail;
317 len -= avail;
@@ -369,14 +368,15 @@ static int revalidate_loose_object(struct object_entry *entry,
368 return check_loose_inflate(map, mapsize, size);
369 }
370
372 -static unsigned long write_object(struct sha1file *f,
371 +static off_t write_object(struct sha1file *f,
372 struct object_entry *entry)
373 {
374 unsigned long size;
375 enum object_type type;
376 void *buf;
377 unsigned char header[10];
379 - unsigned hdrlen, datalen;
378 + unsigned hdrlen;
379 + off_t datalen;
380 enum object_type obj_type;
381 int to_reuse = 0;
382
@@ -439,7 +439,7 @@ static unsigned long write_object(struct sha1file *f,
439 * encoding of the relative offset for the delta
440 * base from this object's position in the pack.
441 */
442 - unsigned long ofs = entry->offset - entry->delta->offset;
442 + off_t ofs = entry->offset - entry->delta->offset;
443 unsigned pos = sizeof(header) - 1;
444 header[pos] = ofs & 127;
445 while (ofs >>= 7)
@@ -460,7 +460,7 @@ static unsigned long write_object(struct sha1file *f,
460 else {
461 struct packed_git *p = entry->in_pack;
462 struct pack_window *w_curs = NULL;
463 - unsigned long offset;
463 + off_t offset;
464
465 if (entry->delta) {
466 obj_type = (allow_ofs_delta && entry->delta->offset) ?
@@ -470,7 +470,7 @@ static unsigned long write_object(struct sha1file *f,
470 hdrlen = encode_header(obj_type, entry->size, header);
471 sha1write(f, header, hdrlen);
472 if (obj_type == OBJ_OFS_DELTA) {
473 - unsigned long ofs = entry->offset - entry->delta->offset;
473 + off_t ofs = entry->offset - entry->delta->offset;
474 unsigned pos = sizeof(header) - 1;
475 header[pos] = ofs & 127;
476 while (ofs >>= 7)
@@ -498,9 +498,9 @@ static unsigned long write_object(struct sha1file *f,
498 return hdrlen + datalen;
499 }
500
501 -static unsigned long write_one(struct sha1file *f,
501 +static off_t write_one(struct sha1file *f,
502 struct object_entry *e,
503 - unsigned long offset)
503 + off_t offset)
504 {
505 if (e->offset || e->preferred_base)
506 /* offset starts from header size and cannot be zero
@@ -518,7 +518,7 @@ static void write_pack_file(void)
518 {
519 uint32_t i;
520 struct sha1file *f;
521 - unsigned long offset;
521 + off_t offset;
522 struct pack_header hdr;
523 unsigned last_percent = 999;
524 int do_progress = progress;
@@ -671,13 +671,13 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud
671 uint32_t idx = nr_objects;
672 struct object_entry *entry;
673 struct packed_git *p;
674 - unsigned int found_offset = 0;
674 + off_t found_offset = 0;
675 struct packed_git *found_pack = NULL;
676 int ix, status = 0;
677
678 if (!exclude) {
679 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);
681 if (offset) {
682 if (incremental)
683 return 0;
@@ -978,17 +978,17 @@ static void check_object(struct object_entry *entry)
978 if (entry->in_pack && !entry->preferred_base) {
979 struct packed_git *p = entry->in_pack;
980 struct pack_window *w_curs = NULL;
981 - unsigned long left = p->pack_size - entry->in_pack_offset;
981 unsigned long size, used;
982 + unsigned int avail;
983 unsigned char *buf;
984 struct object_entry *base_entry = NULL;
985
986 - buf = use_pack(p, &w_curs, entry->in_pack_offset, NULL);
986 + buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail);
987
988 /* We want in_pack_type even if we do not reuse delta.
989 * There is no point not reusing non-delta representations.
990 */
991 - used = unpack_object_header_gently(buf, left,
991 + used = unpack_object_header_gently(buf, avail,
992 &entry->in_pack_type, &size);
993
994 /* Check if it is delta, and the base is also an object
@@ -997,7 +997,7 @@ static void check_object(struct object_entry *entry)
997 */
998 if (!no_reuse_delta) {
999 unsigned char c, *base_name;
1000 - unsigned long ofs;
1000 + off_t ofs;
1001 unsigned long used_0;
1002 /* there is at least 20 bytes left in the pack */
1003 switch (entry->in_pack_type) {
fast-import.c
+2 -2
@@ -249,7 +249,7 @@ typedef enum {
249
250 /* Configured limits on output */
251 static unsigned long max_depth = 10;
252 -static unsigned long max_packsize = (1LL << 32) - 1;
252 +static off_t max_packsize = (1LL << 32) - 1;
253 static int force_update;
254
255 /* Stats and misc. counters */
@@ -1527,7 +1527,7 @@ static void unload_one_branch(void)
1527 {
1528 while (cur_active_branches
1529 && cur_active_branches >= max_active_branches) {
1530 - unsigned long min_commit = ULONG_MAX;
1530 + uintmax_t min_commit = ULONG_MAX;
1531 struct branch *e, *l = NULL, *p = NULL;
1532
1533 for (e = active_branches; e; e = e->active_next_branch) {