Skip to content

Commit c985ddf

Browse files
andreas-schwabgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66fd74e commit c985ddf

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

builtin-count-objects.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
static void count_objects(DIR *d, char *path, int len, int verbose,
1212
unsigned long *loose,
13-
unsigned long *loose_size,
13+
off_t *loose_size,
1414
unsigned long *packed_loose,
1515
unsigned long *garbage)
1616
{
@@ -78,7 +78,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
7878
int len = strlen(objdir);
7979
char *path = xmalloc(len + 50);
8080
unsigned long loose = 0, packed = 0, packed_loose = 0, garbage = 0;
81-
unsigned long loose_size = 0;
81+
off_t loose_size = 0;
8282
struct option opts[] = {
8383
OPT__VERBOSE(&verbose),
8484
OPT_END(),
@@ -104,7 +104,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
104104
if (verbose) {
105105
struct packed_git *p;
106106
unsigned long num_pack = 0;
107-
unsigned long size_pack = 0;
107+
off_t size_pack = 0;
108108
if (!packed_git)
109109
prepare_packed_git();
110110
for (p = packed_git; p; p = p->next) {
@@ -117,15 +117,15 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
117117
num_pack++;
118118
}
119119
printf("count: %lu\n", loose);
120-
printf("size: %lu\n", loose_size / 1024);
120+
printf("size: %lu\n", (unsigned long) (loose_size / 1024));
121121
printf("in-pack: %lu\n", packed);
122122
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));
124124
printf("prune-packable: %lu\n", packed_loose);
125125
printf("garbage: %lu\n", garbage);
126126
}
127127
else
128128
printf("%lu objects, %lu kilobytes\n",
129-
loose, loose_size / 1024);
129+
loose, (unsigned long) (loose_size / 1024));
130130
return 0;
131131
}

0 commit comments

Comments
 (0)