4 #include "run-command.h"
5 #include "parse-options.h"
7 #define VERIFY_PACK_VERBOSE 01
8 #define VERIFY_PACK_STAT_ONLY 02
10 static int verify_one_pack(const char *path, unsigned int flags)
12 struct child_process index_pack = CHILD_PROCESS_INIT;
13 const char *argv[] = {"index-pack", NULL, NULL, NULL };
14 struct strbuf arg = STRBUF_INIT;
15 int verbose = flags & VERIFY_PACK_VERBOSE;
16 int stat_only = flags & VERIFY_PACK_STAT_ONLY;
20 argv[1] = "--verify-stat-only";
22 argv[1] = "--verify-stat";
27 * In addition to "foo.pack" we accept "foo.idx" and "foo";
28 * normalize these forms to "foo.pack" for "index-pack --verify".
30 strbuf_addstr(&arg, path);
31 if (strbuf_strip_suffix(&arg, ".idx") ||
32 !ends_with(arg.buf, ".pack"))
33 strbuf_addstr(&arg, ".pack");
36 index_pack.argv = argv;
37 index_pack.git_cmd = 1;
39 err = run_command(&index_pack);
41 if (verbose || stat_only) {
43 printf("%s: bad\n", arg.buf);
46 printf("%s: ok\n", arg.buf);
54 static const char * const verify_pack_usage[] = {
55 N_("git verify-pack [-v | --verbose] [-s | --stat-only] <pack>..."),
59 int cmd_verify_pack(int argc, const char **argv, const char *prefix)
62 unsigned int flags = 0;
64 const struct option verify_pack_options[] = {
65 OPT_BIT('v', "verbose", &flags, N_("verbose"),
67 OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
68 VERIFY_PACK_STAT_ONLY),
72 git_config(git_default_config, NULL);
73 argc = parse_options(argc, argv, prefix, verify_pack_options,
74 verify_pack_usage, 0);
76 usage_with_options(verify_pack_usage, verify_pack_options);
77 for (i = 0; i < argc; i++) {
78 if (verify_one_pack(argv[i], flags))