git count-objects: handle packs bigger than 4G
Use off_t to count sizes of packs and objects to avoid overflow after 4Gb. Signed-off-by: Andreas Schwab <schwab@linux-m68k.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Andreas Schwab committed
Dec 29, 2009 at 20:09 UTC
c985ddf318a8c41c6e1abc8bebd058b31c7413c1
1 file changed
+6
-6
builtin-count-objects.c
+6
-6
@@ -10,7 +10,7 @@
10
11
static void count_objects(DIR *d, char *path, int len, int verbose,
12
unsigned long *loose,
13
- unsigned long *loose_size,
13
+ off_t *loose_size,
14
unsigned long *packed_loose,
15
unsigned long *garbage)
16
{
@@ -78,7 +78,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
78
int len = strlen(objdir);
79
char *path = xmalloc(len + 50);
80
unsigned long loose = 0, packed = 0, packed_loose = 0, garbage = 0;
81
- unsigned long loose_size = 0;
81
+ off_t loose_size = 0;
82
struct option opts[] = {
83
OPT__VERBOSE(&verbose),
84
OPT_END(),
@@ -104,7 +104,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
104
if (verbose) {
105
struct packed_git *p;
106
unsigned long num_pack = 0;
107
- unsigned long size_pack = 0;
107
+ off_t size_pack = 0;
108
if (!packed_git)
109
prepare_packed_git();
110
for (p = packed_git; p; p = p->next) {
@@ -117,15 +117,15 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
117
num_pack++;
118
}
119
printf("count: %lu\n", loose);
120
- printf("size: %lu\n", loose_size / 1024);
120
+ printf("size: %lu\n", (unsigned long) (loose_size / 1024));
121
printf("in-pack: %lu\n", packed);
122
printf("packs: %lu\n", num_pack);
123
- printf("size-pack: %lu\n", size_pack / 1024);
123
+ printf("size-pack: %lu\n", (unsigned long) (size_pack / 1024));
124
printf("prune-packable: %lu\n", packed_loose);
125
printf("garbage: %lu\n", garbage);
126
}
127
else
128
printf("%lu objects, %lu kilobytes\n",
129
- loose, loose_size / 1024);
129
+ loose, (unsigned long) (loose_size / 1024));
130
return 0;
131
}