@matheusbsbs / matheus-bagliano / commits / c4001d92be
Fork 0

Use off_t when we really mean a file offset.

Not all platforms have declared 'unsigned long' to be a 64 bit value, but we want to support a 64 bit packfile (or close enough anyway) in the near future as some projects are getting large enough that their packed size exceeds 4 GiB. By using off_t, the POSIX type that is declared to mean an offset within a file, we support whatever maximum file size the underlying operating system will handle. For most modern systems this is up around 2^60 or higher. 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 c4001d92be61766d3494489b15590ca0147ee19d
6 files changed +54 -47
cache.h
+5 -5
@@ -383,7 +383,7 @@ extern struct packed_git {
383 } *packed_git;
384
385 struct pack_entry {
386 - unsigned int offset;
386 + off_t offset;
387 unsigned char sha1[20];
388 struct packed_git *p;
389 };
@@ -422,15 +422,15 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
422 struct packed_git *packs);
423
424 extern void pack_report(void);
425 -extern unsigned char* use_pack(struct packed_git *, struct pack_window **, unsigned long, unsigned int *);
425 +extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *);
426 extern void unuse_pack(struct pack_window **);
427 extern struct packed_git *add_packed_git(char *, int, int);
428 extern uint32_t num_packed_objects(const struct packed_git *p);
429 extern int nth_packed_object_sha1(const struct packed_git *, uint32_t, unsigned char*);
430 -extern unsigned long find_pack_entry_one(const unsigned char *, struct packed_git *);
431 -extern void *unpack_entry(struct packed_git *, unsigned long, enum object_type *, unsigned long *);
430 +extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);
431 +extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
432 extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
433 -extern const char *packed_object_info_detail(struct packed_git *, unsigned long, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
433 +extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
434
435 /* Dumb servers support */
436 extern int update_server_info(int);
fast-import.c
-4
@@ -133,10 +133,6 @@ Format of STDIN stream:
133 #define PACK_ID_BITS 16
134 #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
135
136 -#ifndef PRIuMAX
137 -#define PRIuMAX "llu"
138 -#endif
139 -
136 struct object_entry
137 {
138 struct object_entry *next;
git-compat-util.h
+4
@@ -70,6 +70,10 @@
70 #define PATH_MAX 4096
71 #endif
72
73 +#ifndef PRIuMAX
74 +#define PRIuMAX "llu"
75 +#endif
76 +
77 #ifdef __GNUC__
78 #define NORETURN __attribute__((__noreturn__))
79 #else
pack-check.c
+12 -9
@@ -4,11 +4,11 @@
4 static int verify_packfile(struct packed_git *p,
5 struct pack_window **w_curs)
6 {
7 - unsigned long index_size = p->index_size;
7 + off_t index_size = p->index_size;
8 void *index_base = p->index_base;
9 SHA_CTX ctx;
10 unsigned char sha1[20];
11 - unsigned long offset = 0, pack_sig = p->pack_size - 20;
11 + off_t offset = 0, pack_sig = p->pack_size - 20;
12 uint32_t nr_objects, i;
13 int err;
14
@@ -24,7 +24,7 @@ static int verify_packfile(struct packed_git *p,
24 unsigned char *in = use_pack(p, w_curs, offset, &remaining);
25 offset += remaining;
26 if (offset > pack_sig)
27 - remaining -= offset - pack_sig;
27 + remaining -= (unsigned int)(offset - pack_sig);
28 SHA1_Update(&ctx, in, remaining);
29 }
30 SHA1_Final(sha1, &ctx);
@@ -45,7 +45,8 @@ static int verify_packfile(struct packed_git *p,
45 unsigned char sha1[20];
46 void *data;
47 enum object_type type;
48 - unsigned long size, offset;
48 + unsigned long size;
49 + off_t offset;
50
51 if (nth_packed_object_sha1(p, i, sha1))
52 die("internal error pack-check nth-packed-object");
@@ -85,7 +86,7 @@ static void show_pack_info(struct packed_git *p)
86 const char *type;
87 unsigned long size;
88 unsigned long store_size;
88 - unsigned long offset;
89 + off_t offset;
90 unsigned int delta_chain_length;
91
92 if (nth_packed_object_sha1(p, i, sha1))
@@ -99,9 +100,11 @@ static void show_pack_info(struct packed_git *p)
100 base_sha1);
101 printf("%s ", sha1_to_hex(sha1));
102 if (!delta_chain_length)
102 - printf("%-6s %lu %lu\n", type, size, offset);
103 + printf("%-6s %lu %"PRIuMAX"\n",
104 + type, size, (uintmax_t)offset);
105 else {
104 - printf("%-6s %lu %lu %u %s\n", type, size, offset,
106 + printf("%-6s %lu %"PRIuMAX" %u %s\n",
107 + type, size, (uintmax_t)offset,
108 delta_chain_length, sha1_to_hex(base_sha1));
109 if (delta_chain_length < MAX_CHAIN)
110 chain_histogram[delta_chain_length]++;
@@ -123,7 +126,7 @@ static void show_pack_info(struct packed_git *p)
126
127 int verify_pack(struct packed_git *p, int verbose)
128 {
126 - unsigned long index_size = p->index_size;
129 + off_t index_size = p->index_size;
130 void *index_base = p->index_base;
131 SHA_CTX ctx;
132 unsigned char sha1[20];
@@ -132,7 +135,7 @@ int verify_pack(struct packed_git *p, int verbose)
135 ret = 0;
136 /* Verify SHA1 sum of the index file */
137 SHA1_Init(&ctx);
135 - SHA1_Update(&ctx, index_base, index_size - 20);
138 + SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20));
139 SHA1_Final(sha1, &ctx);
140 if (hashcmp(sha1, (unsigned char *)index_base + index_size - 20))
141 ret = error("Packfile index for %s SHA1 mismatch",
pack-redundant.c
+4 -4
@@ -396,9 +396,9 @@ static size_t get_pack_redundancy(struct pack_list *pl)
396 return ret;
397 }
398
399 -static inline size_t pack_set_bytecount(struct pack_list *pl)
399 +static inline off_t pack_set_bytecount(struct pack_list *pl)
400 {
401 - size_t ret = 0;
401 + off_t ret = 0;
402 while (pl) {
403 ret += pl->pack->pack_size;
404 ret += pl->pack->index_size;
@@ -413,7 +413,7 @@ static void minimize(struct pack_list **min)
413 *non_unique = NULL, *min_perm = NULL;
414 struct pll *perm, *perm_all, *perm_ok = NULL, *new_perm;
415 struct llist *missing;
416 - size_t min_perm_size = (size_t)-1, perm_size;
416 + off_t min_perm_size = 0, perm_size;
417 int n;
418
419 pl = local_packs;
@@ -461,7 +461,7 @@ static void minimize(struct pack_list **min)
461 perm = perm_ok;
462 while (perm) {
463 perm_size = pack_set_bytecount(perm->pl);
464 - if (min_perm_size > perm_size) {
464 + if (!min_perm_size || min_perm_size > perm_size) {
465 min_perm_size = perm_size;
466 min_perm = perm->pl;
467 }
sha1_file.c
+29 -25
@@ -629,7 +629,7 @@ static int open_packed_git(struct packed_git *p)
629 return -1;
630 }
631
632 -static int in_window(struct pack_window *win, unsigned long offset)
632 +static int in_window(struct pack_window *win, off_t offset)
633 {
634 /* We must promise at least 20 bytes (one hash) after the
635 * offset is available from this window, otherwise the offset
@@ -644,7 +644,7 @@ static int in_window(struct pack_window *win, unsigned long offset)
644
645 unsigned char* use_pack(struct packed_git *p,
646 struct pack_window **w_cursor,
647 - unsigned long offset,
647 + off_t offset,
648 unsigned int *left)
649 {
650 struct pack_window *win = *w_cursor;
@@ -1049,14 +1049,14 @@ void * unpack_sha1_file(void *map, unsigned long mapsize, enum object_type *type
1049 return unpack_sha1_rest(&stream, hdr, *size);
1050 }
1051
1052 -static unsigned long get_delta_base(struct packed_git *p,
1052 +static off_t get_delta_base(struct packed_git *p,
1053 struct pack_window **w_curs,
1054 - unsigned long *curpos,
1054 + off_t *curpos,
1055 enum object_type type,
1056 - unsigned long delta_obj_offset)
1056 + off_t delta_obj_offset)
1057 {
1058 unsigned char *base_info = use_pack(p, w_curs, *curpos, NULL);
1059 - unsigned long base_offset;
1059 + off_t base_offset;
1060
1061 /* use_pack() assured us we have [base_info, base_info + 20)
1062 * as a range that we can look at without walking off the
@@ -1092,17 +1092,17 @@ static unsigned long get_delta_base(struct packed_git *p,
1092 }
1093
1094 /* forward declaration for a mutually recursive function */
1095 -static int packed_object_info(struct packed_git *p, unsigned long offset,
1095 +static int packed_object_info(struct packed_git *p, off_t offset,
1096 unsigned long *sizep);
1097
1098 static int packed_delta_info(struct packed_git *p,
1099 struct pack_window **w_curs,
1100 - unsigned long curpos,
1100 + off_t curpos,
1101 enum object_type type,
1102 - unsigned long obj_offset,
1102 + off_t obj_offset,
1103 unsigned long *sizep)
1104 {
1105 - unsigned long base_offset;
1105 + off_t base_offset;
1106
1107 base_offset = get_delta_base(p, w_curs, &curpos, type, obj_offset);
1108 type = packed_object_info(p, base_offset, NULL);
@@ -1152,7 +1152,7 @@ static int packed_delta_info(struct packed_git *p,
1152
1153 static int unpack_object_header(struct packed_git *p,
1154 struct pack_window **w_curs,
1155 - unsigned long *curpos,
1155 + off_t *curpos,
1156 unsigned long *sizep)
1157 {
1158 unsigned char *base;
@@ -1176,14 +1176,15 @@ static int unpack_object_header(struct packed_git *p,
1176 }
1177
1178 const char *packed_object_info_detail(struct packed_git *p,
1179 - unsigned long obj_offset,
1179 + off_t obj_offset,
1180 unsigned long *size,
1181 unsigned long *store_size,
1182 unsigned int *delta_chain_length,
1183 unsigned char *base_sha1)
1184 {
1185 struct pack_window *w_curs = NULL;
1186 - unsigned long curpos, dummy;
1186 + off_t curpos;
1187 + unsigned long dummy;
1188 unsigned char *next_sha1;
1189 enum object_type type;
1190
@@ -1223,11 +1224,12 @@ const char *packed_object_info_detail(struct packed_git *p,
1224 }
1225 }
1226
1226 -static int packed_object_info(struct packed_git *p, unsigned long obj_offset,
1227 +static int packed_object_info(struct packed_git *p, off_t obj_offset,
1228 unsigned long *sizep)
1229 {
1230 struct pack_window *w_curs = NULL;
1230 - unsigned long size, curpos = obj_offset;
1231 + unsigned long size;
1232 + off_t curpos = obj_offset;
1233 enum object_type type;
1234
1235 type = unpack_object_header(p, &w_curs, &curpos, &size);
@@ -1255,7 +1257,7 @@ static int packed_object_info(struct packed_git *p, unsigned long obj_offset,
1257
1258 static void *unpack_compressed_entry(struct packed_git *p,
1259 struct pack_window **w_curs,
1258 - unsigned long curpos,
1260 + off_t curpos,
1261 unsigned long size)
1262 {
1263 int st;
@@ -1286,20 +1288,22 @@ static void *unpack_compressed_entry(struct packed_git *p,
1288
1289 static void *unpack_delta_entry(struct packed_git *p,
1290 struct pack_window **w_curs,
1289 - unsigned long curpos,
1291 + off_t curpos,
1292 unsigned long delta_size,
1291 - unsigned long obj_offset,
1293 + off_t obj_offset,
1294 enum object_type *type,
1295 unsigned long *sizep)
1296 {
1297 void *delta_data, *result, *base;
1296 - unsigned long base_size, base_offset;
1298 + unsigned long base_size;
1299 + off_t base_offset;
1300
1301 base_offset = get_delta_base(p, w_curs, &curpos, *type, obj_offset);
1302 base = unpack_entry(p, base_offset, type, &base_size);
1303 if (!base)
1301 - die("failed to read delta base object at %lu from %s",
1302 - base_offset, p->pack_name);
1304 + die("failed to read delta base object"
1305 + " at %"PRIuMAX" from %s",
1306 + (uintmax_t)base_offset, p->pack_name);
1307
1308 delta_data = unpack_compressed_entry(p, w_curs, curpos, delta_size);
1309 result = patch_delta(base, base_size,
@@ -1312,11 +1316,11 @@ static void *unpack_delta_entry(struct packed_git *p,
1316 return result;
1317 }
1318
1315 -void *unpack_entry(struct packed_git *p, unsigned long obj_offset,
1319 +void *unpack_entry(struct packed_git *p, off_t obj_offset,
1320 enum object_type *type, unsigned long *sizep)
1321 {
1322 struct pack_window *w_curs = NULL;
1319 - unsigned long curpos = obj_offset;
1323 + off_t curpos = obj_offset;
1324 void *data;
1325
1326 *type = unpack_object_header(p, &w_curs, &curpos, sizep);
@@ -1355,7 +1359,7 @@ int nth_packed_object_sha1(const struct packed_git *p, uint32_t n,
1359 return 0;
1360 }
1361
1358 -unsigned long find_pack_entry_one(const unsigned char *sha1,
1362 +off_t find_pack_entry_one(const unsigned char *sha1,
1363 struct packed_git *p)
1364 {
1365 uint32_t *level1_ofs = p->index_base;
@@ -1397,7 +1401,7 @@ static int matches_pack_name(struct packed_git *p, const char *ig)
1401 static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
1402 {
1403 struct packed_git *p;
1400 - unsigned long offset;
1404 + off_t offset;
1405
1406 prepare_packed_git();
1407