1 #define USE_THE_REPOSITORY_VARIABLE
5 #include "run-command.h"
6 #include "parse-options.h"
9 #define VERIFY_PACK_VERBOSE 01
10 #define VERIFY_PACK_STAT_ONLY 02
12 static int verify_one_pack(const char *path
, unsigned int flags
, const char *hash_algo
)
14 struct child_process index_pack
= CHILD_PROCESS_INIT
;
15 struct strvec
*argv
= &index_pack
.args
;
16 struct strbuf arg
= STRBUF_INIT
;
17 int verbose
= flags
& VERIFY_PACK_VERBOSE
;
18 int stat_only
= flags
& VERIFY_PACK_STAT_ONLY
;
21 strvec_push(argv
, "index-pack");
24 strvec_push(argv
, "--verify-stat-only");
26 strvec_push(argv
, "--verify-stat");
28 strvec_push(argv
, "--verify");
31 strvec_pushf(argv
, "--object-format=%s", hash_algo
);
34 * In addition to "foo.pack" we accept "foo.idx" and "foo";
35 * normalize these forms to "foo.pack" for "index-pack --verify".
37 strbuf_addstr(&arg
, path
);
38 if (strbuf_strip_suffix(&arg
, ".idx") ||
39 !ends_with(arg
.buf
, ".pack"))
40 strbuf_addstr(&arg
, ".pack");
41 strvec_push(argv
, arg
.buf
);
43 index_pack
.git_cmd
= 1;
45 err
= run_command(&index_pack
);
47 if (verbose
|| stat_only
) {
49 printf("%s: bad\n", arg
.buf
);
52 printf("%s: ok\n", arg
.buf
);
60 static const char * const verify_pack_usage
[] = {
61 N_("git verify-pack [-v | --verbose] [-s | --stat-only] [--] <pack>.idx..."),
65 int cmd_verify_pack(int argc
,
68 struct repository
*repo UNUSED
)
71 unsigned int flags
= 0;
72 const char *object_format
= NULL
;
74 const struct option verify_pack_options
[] = {
75 OPT_BIT('v', "verbose", &flags
, N_("verbose"),
77 OPT_BIT('s', "stat-only", &flags
, N_("show statistics only"),
78 VERIFY_PACK_STAT_ONLY
),
79 OPT_STRING(0, "object-format", &object_format
, N_("hash"),
80 N_("specify the hash algorithm to use")),
84 git_config(git_default_config
, NULL
);
85 argc
= parse_options(argc
, argv
, prefix
, verify_pack_options
,
86 verify_pack_usage
, 0);
88 usage_with_options(verify_pack_usage
, verify_pack_options
);
89 for (i
= 0; i
< argc
; i
++) {
90 if (verify_one_pack(argv
[i
], flags
, object_format
))