4 #include "run-command.h"
5 #include "parse-options.h"
8 #define VERIFY_PACK_VERBOSE 01
9 #define VERIFY_PACK_STAT_ONLY 02
11 static int verify_one_pack(const char *path
, unsigned int flags
, const char *hash_algo
)
13 struct child_process index_pack
= CHILD_PROCESS_INIT
;
14 struct strvec
*argv
= &index_pack
.args
;
15 struct strbuf arg
= STRBUF_INIT
;
16 int verbose
= flags
& VERIFY_PACK_VERBOSE
;
17 int stat_only
= flags
& VERIFY_PACK_STAT_ONLY
;
20 strvec_push(argv
, "index-pack");
23 strvec_push(argv
, "--verify-stat-only");
25 strvec_push(argv
, "--verify-stat");
27 strvec_push(argv
, "--verify");
30 strvec_pushf(argv
, "--object-format=%s", hash_algo
);
33 * In addition to "foo.pack" we accept "foo.idx" and "foo";
34 * normalize these forms to "foo.pack" for "index-pack --verify".
36 strbuf_addstr(&arg
, path
);
37 if (strbuf_strip_suffix(&arg
, ".idx") ||
38 !ends_with(arg
.buf
, ".pack"))
39 strbuf_addstr(&arg
, ".pack");
40 strvec_push(argv
, arg
.buf
);
42 index_pack
.git_cmd
= 1;
44 err
= run_command(&index_pack
);
46 if (verbose
|| stat_only
) {
48 printf("%s: bad\n", arg
.buf
);
51 printf("%s: ok\n", arg
.buf
);
59 static const char * const verify_pack_usage
[] = {
60 N_("git verify-pack [-v | --verbose] [-s | --stat-only] [--] <pack>.idx..."),
64 int cmd_verify_pack(int argc
, const char **argv
, const char *prefix
)
67 unsigned int flags
= 0;
68 const char *object_format
= NULL
;
70 const struct option verify_pack_options
[] = {
71 OPT_BIT('v', "verbose", &flags
, N_("verbose"),
73 OPT_BIT('s', "stat-only", &flags
, N_("show statistics only"),
74 VERIFY_PACK_STAT_ONLY
),
75 OPT_STRING(0, "object-format", &object_format
, N_("hash"),
76 N_("specify the hash algorithm to use")),
80 git_config(git_default_config
, NULL
);
81 argc
= parse_options(argc
, argv
, prefix
, verify_pack_options
,
82 verify_pack_usage
, 0);
84 usage_with_options(verify_pack_usage
, verify_pack_options
);
85 for (i
= 0; i
< argc
; i
++) {
86 if (verify_one_pack(argv
[i
], flags
, object_format
))