3 #include "run-command.h"
4 #include "parse-options.h"
6 #define VERIFY_PACK_VERBOSE 01
7 #define VERIFY_PACK_STAT_ONLY 02
9 static int verify_one_pack(const char *path, unsigned int flags)
11 struct child_process index_pack = CHILD_PROCESS_INIT;
12 const char *argv[] = {"index-pack", NULL, NULL, NULL };
13 struct strbuf arg = STRBUF_INIT;
14 int verbose = flags & VERIFY_PACK_VERBOSE;
15 int stat_only = flags & VERIFY_PACK_STAT_ONLY;
19 argv[1] = "--verify-stat-only";
21 argv[1] = "--verify-stat";
26 * In addition to "foo.pack" we accept "foo.idx" and "foo";
27 * normalize these forms to "foo.pack" for "index-pack --verify".
29 strbuf_addstr(&arg, path);
30 if (strbuf_strip_suffix(&arg, ".idx") ||
31 !ends_with(arg.buf, ".pack"))
32 strbuf_addstr(&arg, ".pack");
35 index_pack.argv = argv;
36 index_pack.git_cmd = 1;
38 err = run_command(&index_pack);
40 if (verbose || stat_only) {
42 printf("%s: bad\n", arg.buf);
45 printf("%s: ok\n", arg.buf);
53 static const char * const verify_pack_usage[] = {
54 N_("git verify-pack [-v|--verbose] [-s|--stat-only] <pack>..."),
58 int cmd_verify_pack(int argc, const char **argv, const char *prefix)
61 unsigned int flags = 0;
63 const struct option verify_pack_options[] = {
64 OPT_BIT('v', "verbose", &flags, N_("verbose"),
66 OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
67 VERIFY_PACK_STAT_ONLY),
71 git_config(git_default_config, NULL);
72 argc = parse_options(argc, argv, prefix, verify_pack_options,
73 verify_pack_usage, 0);
75 usage_with_options(verify_pack_usage, verify_pack_options);
76 for (i = 0; i < argc; i++) {
77 if (verify_one_pack(argv[i], flags))