4 #include "pack-revindex.h"
8 static void show_pack_info(struct packed_git *p)
10 uint32_t nr_objects, i;
12 unsigned long chain_histogram[MAX_CHAIN+1], baseobjects;
14 nr_objects = p->num_objects;
15 memset(chain_histogram, 0, sizeof(chain_histogram));
18 for (i = 0; i < nr_objects; i++) {
19 const unsigned char *sha1;
20 unsigned char base_sha1[20];
23 unsigned long store_size;
25 unsigned int delta_chain_length;
27 sha1 = nth_packed_object_sha1(p, i);
29 die("internal error pack-check nth-packed-object");
30 offset = nth_packed_object_offset(p, i);
31 type = packed_object_info_detail(p, offset, &size, &store_size,
34 printf("%s ", sha1_to_hex(sha1));
35 if (!delta_chain_length) {
36 printf("%-6s %lu %lu %"PRIuMAX"\n",
37 type, size, store_size, (uintmax_t)offset);
41 printf("%-6s %lu %lu %"PRIuMAX" %u %s\n",
42 type, size, store_size, (uintmax_t)offset,
43 delta_chain_length, sha1_to_hex(base_sha1));
44 if (delta_chain_length <= MAX_CHAIN)
45 chain_histogram[delta_chain_length]++;
52 printf("non delta: %lu object%s\n",
53 baseobjects, baseobjects > 1 ? "s" : "");
55 for (cnt = 1; cnt <= MAX_CHAIN; cnt++) {
56 if (!chain_histogram[cnt])
58 printf("chain length = %d: %lu object%s\n", cnt,
60 chain_histogram[cnt] > 1 ? "s" : "");
62 if (chain_histogram[0])
63 printf("chain length > %d: %lu object%s\n", MAX_CHAIN,
65 chain_histogram[0] > 1 ? "s" : "");
68 static int verify_one_pack(const char *path, int verbose)
72 struct packed_git *pack;
75 len = strlcpy(arg, path, PATH_MAX);
77 return error("name too long: %s", path);
80 * In addition to "foo.idx" we accept "foo.pack" and "foo";
81 * normalize these forms to "foo.idx" for add_packed_git().
83 if (has_extension(arg, ".pack")) {
84 strcpy(arg + len - 5, ".idx");
86 } else if (!has_extension(arg, ".idx")) {
87 if (len + 4 >= PATH_MAX)
88 return error("name too long: %s.idx", arg);
89 strcpy(arg + len, ".idx");
94 * add_packed_git() uses our buffer (containing "foo.idx") to
95 * build the pack filename ("foo.pack"). Make sure it fits.
97 if (len + 1 >= PATH_MAX) {
99 return error("name too long: %s.pack", arg);
102 pack = add_packed_git(arg, len, 1);
104 return error("packfile %s not found.", arg);
106 install_packed_git(pack);
107 err = verify_pack(pack);
111 printf("%s: bad\n", pack->pack_name);
113 show_pack_info(pack);
114 printf("%s: ok\n", pack->pack_name);
121 static const char verify_pack_usage[] = "git verify-pack [-v] <pack>...";
123 int cmd_verify_pack(int argc, const char **argv, const char *prefix)
127 int no_more_options = 0;
128 int nothing_done = 1;
130 git_config(git_default_config, NULL);
132 if (!no_more_options && argv[1][0] == '-') {
133 if (!strcmp("-v", argv[1]))
135 else if (!strcmp("--", argv[1]))
138 usage(verify_pack_usage);
141 if (verify_one_pack(argv[1], verbose))
150 usage(verify_pack_usage);