7
#define VERIFY_PACK_VERBOSE 01
8
#define VERIFY_PACK_STAT_ONLY 02
9
10
-static int verify_one_pack(const char *path, unsigned int flags)
10
+static int verify_one_pack(const char *path, unsigned int flags, const char *hash_algo)
11
{
12
struct child_process index_pack = CHILD_PROCESS_INIT;
13
- const char *argv[] = {"index-pack", NULL, NULL, NULL };
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;
17
int err;
18
19
+ argv_array_push(argv, "index-pack");
20
+
21
if (stat_only)
20
- argv[1] = "--verify-stat-only";
22
+ argv_array_push(argv, "--verify-stat-only");
23
else if (verbose)
22
- argv[1] = "--verify-stat";
24
+ argv_array_push(argv, "--verify-stat");
25
else
24
- argv[1] = "--verify";
26
+ argv_array_push(argv, "--verify");
27
+
28
+ if (hash_algo)
29
+ argv_array_pushf(argv, "--object-format=%s", hash_algo);
30
31
/*
32
* In addition to "foo.pack" we accept "foo.idx" and "foo";
36
if (strbuf_strip_suffix(&arg, ".idx") ||
37
!ends_with(arg.buf, ".pack"))
38
strbuf_addstr(&arg, ".pack");
34
- argv[2] = arg.buf;
39
+ argv_array_push(argv, arg.buf);
40
36
- index_pack.argv = argv;
41
index_pack.git_cmd = 1;
42
43
err = run_command(&index_pack);
64
{
65
int err = 0;
66
unsigned int flags = 0;
67
+ const char *object_format = NULL;
68
int i;
69
const struct option verify_pack_options[] = {
70
OPT_BIT('v', "verbose", &flags, N_("verbose"),
71
VERIFY_PACK_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")),
76
OPT_END()
77
};
78
82
if (argc < 1)
83
usage_with_options(verify_pack_usage, verify_pack_options);
84
for (i = 0; i < argc; i++) {
78
- if (verify_one_pack(argv[i], flags))
85
+ if (verify_one_pack(argv[i], flags, object_format))
86
err = 1;
87
}
88