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
, const char *hash_algo
)
12 struct child_process index_pack
= CHILD_PROCESS_INIT
;
13 struct argv_array
*argv
= &index_pack
.args
;
14 struct strbuf arg
= STRBUF_INIT
;
15 int verbose
= flags
& VERIFY_PACK_VERBOSE
;
16 int stat_only
= flags
& VERIFY_PACK_STAT_ONLY
;
19 argv_array_push(argv
, "index-pack");
22 argv_array_push(argv
, "--verify-stat-only");
24 argv_array_push(argv
, "--verify-stat");
26 argv_array_push(argv
, "--verify");
29 argv_array_pushf(argv
, "--object-format=%s", hash_algo
);
32 * In addition to "foo.pack" we accept "foo.idx" and "foo";
33 * normalize these forms to "foo.pack" for "index-pack --verify".
35 strbuf_addstr(&arg
, path
);
36 if (strbuf_strip_suffix(&arg
, ".idx") ||
37 !ends_with(arg
.buf
, ".pack"))
38 strbuf_addstr(&arg
, ".pack");
39 argv_array_push(argv
, arg
.buf
);
41 index_pack
.git_cmd
= 1;
43 err
= run_command(&index_pack
);
45 if (verbose
|| stat_only
) {
47 printf("%s: bad\n", arg
.buf
);
50 printf("%s: ok\n", arg
.buf
);
58 static const char * const verify_pack_usage
[] = {
59 N_("git verify-pack [-v | --verbose] [-s | --stat-only] <pack>..."),
63 int cmd_verify_pack(int argc
, const char **argv
, const char *prefix
)
66 unsigned int flags
= 0;
67 const char *object_format
= NULL
;
69 const struct option verify_pack_options
[] = {
70 OPT_BIT('v', "verbose", &flags
, N_("verbose"),
72 OPT_BIT('s', "stat-only", &flags
, N_("show statistics only"),
73 VERIFY_PACK_STAT_ONLY
),
74 OPT_STRING(0, "object-format", &object_format
, N_("hash"),
75 N_("specify the hash algorithm to use")),
79 git_config(git_default_config
, NULL
);
80 argc
= parse_options(argc
, argv
, prefix
, verify_pack_options
,
81 verify_pack_usage
, 0);
83 usage_with_options(verify_pack_usage
, verify_pack_options
);
84 for (i
= 0; i
< argc
; i
++) {
85 if (verify_one_pack(argv
[i
], flags
, object_format
))