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;
13 unsigned long chain_histogram[MAX_CHAIN+1], baseobjects;
15 nr_objects = p->num_objects;
16 memset(chain_histogram, 0, sizeof(chain_histogram));
19 for (i = 0; i < nr_objects; i++) {
20 const unsigned char *sha1;
21 unsigned char base_sha1[20];
24 unsigned long store_size;
26 unsigned int delta_chain_length;
28 sha1 = nth_packed_object_sha1(p, i);
30 die("internal error pack-check nth-packed-object");
31 offset = nth_packed_object_offset(p, i);
32 type = packed_object_info_detail(p, offset, &size, &store_size,
35 printf("%s ", sha1_to_hex(sha1));
36 if (!delta_chain_length) {
37 printf("%-6s %lu %lu %"PRIuMAX"\n",
38 type, size, store_size, (uintmax_t)offset);
42 printf("%-6s %lu %lu %"PRIuMAX" %u %s\n",
43 type, size, store_size, (uintmax_t)offset,
44 delta_chain_length, sha1_to_hex(base_sha1));
45 if (delta_chain_length <= MAX_CHAIN)
46 chain_histogram[delta_chain_length]++;
53 printf("non delta: %lu object%s\n",
54 baseobjects, baseobjects > 1 ? "s" : "");
56 for (cnt = 1; cnt <= MAX_CHAIN; cnt++) {
57 if (!chain_histogram[cnt])
59 printf("chain length = %d: %lu object%s\n", cnt,
61 chain_histogram[cnt] > 1 ? "s" : "");
63 if (chain_histogram[0])
64 printf("chain length > %d: %lu object%s\n", MAX_CHAIN,
66 chain_histogram[0] > 1 ? "s" : "");
69 static int verify_one_pack(const char *path, int verbose)
73 struct packed_git *pack;
76 len = strlcpy(arg, path, PATH_MAX);
78 return error("name too long: %s", path);
81 * In addition to "foo.idx" we accept "foo.pack" and "foo";
82 * normalize these forms to "foo.idx" for add_packed_git().
84 if (has_extension(arg, ".pack")) {
85 strcpy(arg + len - 5, ".idx");
87 } else if (!has_extension(arg, ".idx")) {
88 if (len + 4 >= PATH_MAX)
89 return error("name too long: %s.idx", arg);
90 strcpy(arg + len, ".idx");
95 * add_packed_git() uses our buffer (containing "foo.idx") to
96 * build the pack filename ("foo.pack"). Make sure it fits.
98 if (len + 1 >= PATH_MAX) {
100 return error("name too long: %s.pack", arg);
103 pack = add_packed_git(arg, len, 1);
105 return error("packfile %s not found.", arg);
107 install_packed_git(pack);
108 err = verify_pack(pack);
112 printf("%s: bad\n", pack->pack_name);
114 show_pack_info(pack);
115 printf("%s: ok\n", pack->pack_name);
122 static const char * const verify_pack_usage[] = {
123 "git verify-pack [-v|--verbose] <pack>...",
127 int cmd_verify_pack(int argc, const char **argv, const char *prefix)
132 const struct option verify_pack_options[] = {
133 OPT__VERBOSE(&verbose),
137 git_config(git_default_config, NULL);
138 argc = parse_options(argc, argv, prefix, verify_pack_options,
139 verify_pack_usage, 0);
141 usage_with_options(verify_pack_usage, verify_pack_options);
142 for (i = 0; i < argc; i++) {
143 if (verify_one_pack(argv[i], verbose))