8 static void show_pack_info(struct packed_git
*p
)
10 uint32_t nr_objects
, i
, chain_histogram
[MAX_CHAIN
+1];
12 nr_objects
= p
->num_objects
;
13 memset(chain_histogram
, 0, sizeof(chain_histogram
));
15 for (i
= 0; i
< nr_objects
; i
++) {
16 const unsigned char *sha1
;
17 unsigned char base_sha1
[20];
20 unsigned long store_size
;
22 unsigned int delta_chain_length
;
24 sha1
= nth_packed_object_sha1(p
, i
);
26 die("internal error pack-check nth-packed-object");
27 offset
= nth_packed_object_offset(p
, i
);
28 type
= packed_object_info_detail(p
, offset
, &size
, &store_size
,
31 printf("%s ", sha1_to_hex(sha1
));
32 if (!delta_chain_length
)
33 printf("%-6s %lu %lu %"PRIuMAX
"\n",
34 type
, size
, store_size
, (uintmax_t)offset
);
36 printf("%-6s %lu %lu %"PRIuMAX
" %u %s\n",
37 type
, size
, store_size
, (uintmax_t)offset
,
38 delta_chain_length
, sha1_to_hex(base_sha1
));
39 if (delta_chain_length
<= MAX_CHAIN
)
40 chain_histogram
[delta_chain_length
]++;
46 for (i
= 0; i
<= MAX_CHAIN
; i
++) {
47 if (!chain_histogram
[i
])
49 printf("chain length = %"PRIu32
": %"PRIu32
" object%s\n", i
,
50 chain_histogram
[i
], chain_histogram
[i
] > 1 ? "s" : "");
52 if (chain_histogram
[0])
53 printf("chain length > %d: %"PRIu32
" object%s\n", MAX_CHAIN
,
54 chain_histogram
[0], chain_histogram
[0] > 1 ? "s" : "");
57 static int verify_one_pack(const char *path
, int verbose
)
61 struct packed_git
*pack
;
64 len
= strlcpy(arg
, path
, PATH_MAX
);
66 return error("name too long: %s", path
);
69 * In addition to "foo.idx" we accept "foo.pack" and "foo";
70 * normalize these forms to "foo.idx" for add_packed_git().
72 if (has_extension(arg
, ".pack")) {
73 strcpy(arg
+ len
- 5, ".idx");
75 } else if (!has_extension(arg
, ".idx")) {
76 if (len
+ 4 >= PATH_MAX
)
77 return error("name too long: %s.idx", arg
);
78 strcpy(arg
+ len
, ".idx");
83 * add_packed_git() uses our buffer (containing "foo.idx") to
84 * build the pack filename ("foo.pack"). Make sure it fits.
86 if (len
+ 1 >= PATH_MAX
) {
88 return error("name too long: %s.pack", arg
);
91 pack
= add_packed_git(arg
, len
, 1);
93 return error("packfile %s not found.", arg
);
95 install_packed_git(pack
);
96 err
= verify_pack(pack
);
100 printf("%s: bad\n", pack
->pack_name
);
102 show_pack_info(pack
);
103 printf("%s: ok\n", pack
->pack_name
);
110 static const char verify_pack_usage
[] = "git-verify-pack [-v] <pack>...";
112 int cmd_verify_pack(int argc
, const char **argv
, const char *prefix
)
116 int no_more_options
= 0;
117 int nothing_done
= 1;
119 git_config(git_default_config
, NULL
);
121 if (!no_more_options
&& argv
[1][0] == '-') {
122 if (!strcmp("-v", argv
[1]))
124 else if (!strcmp("--", argv
[1]))
127 usage(verify_pack_usage
);
130 if (verify_one_pack(argv
[1], verbose
))
138 usage(verify_pack_usage
);