4 #include "pack-revindex.h"
5 #include "parse-options.h"
9 static void show_pack_info(struct packed_git *p)
11 uint32_t nr_objects, i, chain_histogram[MAX_CHAIN+1];
13 nr_objects = p->num_objects;
14 memset(chain_histogram, 0, sizeof(chain_histogram));
16 for (i = 0; i < nr_objects; i++) {
17 const unsigned char *sha1;
18 unsigned char base_sha1[20];
21 unsigned long store_size;
23 unsigned int delta_chain_length;
25 sha1 = nth_packed_object_sha1(p, i);
27 die("internal error pack-check nth-packed-object");
28 offset = nth_packed_object_offset(p, i);
29 type = packed_object_info_detail(p, offset, &size, &store_size,
32 printf("%s ", sha1_to_hex(sha1));
33 if (!delta_chain_length)
34 printf("%-6s %lu %lu %"PRIuMAX"\n",
35 type, size, store_size, (uintmax_t)offset);
37 printf("%-6s %lu %lu %"PRIuMAX" %u %s\n",
38 type, size, store_size, (uintmax_t)offset,
39 delta_chain_length, sha1_to_hex(base_sha1));
40 if (delta_chain_length <= MAX_CHAIN)
41 chain_histogram[delta_chain_length]++;
47 for (i = 0; i <= MAX_CHAIN; i++) {
48 if (!chain_histogram[i])
50 printf("chain length = %"PRIu32": %"PRIu32" object%s\n", i,
51 chain_histogram[i], chain_histogram[i] > 1 ? "s" : "");
53 if (chain_histogram[0])
54 printf("chain length > %d: %"PRIu32" object%s\n", MAX_CHAIN,
55 chain_histogram[0], chain_histogram[0] > 1 ? "s" : "");
58 static int verify_one_pack(const char *path, int verbose)
62 struct packed_git *pack;
65 len = strlcpy(arg, path, PATH_MAX);
67 return error("name too long: %s", path);
70 * In addition to "foo.idx" we accept "foo.pack" and "foo";
71 * normalize these forms to "foo.idx" for add_packed_git().
73 if (has_extension(arg, ".pack")) {
74 strcpy(arg + len - 5, ".idx");
76 } else if (!has_extension(arg, ".idx")) {
77 if (len + 4 >= PATH_MAX)
78 return error("name too long: %s.idx", arg);
79 strcpy(arg + len, ".idx");
84 * add_packed_git() uses our buffer (containing "foo.idx") to
85 * build the pack filename ("foo.pack"). Make sure it fits.
87 if (len + 1 >= PATH_MAX) {
89 return error("name too long: %s.pack", arg);
92 pack = add_packed_git(arg, len, 1);
94 return error("packfile %s not found.", arg);
96 install_packed_git(pack);
97 err = verify_pack(pack);
101 printf("%s: bad\n", pack->pack_name);
103 show_pack_info(pack);
104 printf("%s: ok\n", pack->pack_name);
111 static const char * const verify_pack_usage[] = {
112 "git verify-pack [-v|--verbose] <pack>...",
116 int cmd_verify_pack(int argc, const char **argv, const char *prefix)
121 const struct option verify_pack_options[] = {
122 OPT__VERBOSE(&verbose),
126 git_config(git_default_config, NULL);
127 argc = parse_options(argc, argv, prefix, verify_pack_options,
128 verify_pack_usage, 0);
130 usage_with_options(verify_pack_usage, verify_pack_options);
131 for (i = 0; i < argc; i++) {
132 if (verify_one_pack(argv[i], verbose))