]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/verify-pack.c
config: remove git_config_iter
[thirdparty/git.git] / builtin / verify-pack.c
CommitLineData
2e3ed670 1#include "builtin.h"
f9253394 2#include "cache.h"
3de89c9d 3#include "run-command.h"
c9c3c678 4#include "parse-options.h"
77d3ecee 5
6c4f3ec9
JH
6#define VERIFY_PACK_VERBOSE 01
7#define VERIFY_PACK_STAT_ONLY 02
8
6c4f3ec9 9static int verify_one_pack(const char *path, unsigned int flags)
f9253394 10{
d3180279 11 struct child_process index_pack = CHILD_PROCESS_INIT;
3de89c9d
JH
12 const char *argv[] = {"index-pack", NULL, NULL, NULL };
13 struct strbuf arg = STRBUF_INIT;
6c4f3ec9
JH
14 int verbose = flags & VERIFY_PACK_VERBOSE;
15 int stat_only = flags & VERIFY_PACK_STAT_ONLY;
d0d619c8 16 int err;
ae9c86f2 17
3de89c9d
JH
18 if (stat_only)
19 argv[1] = "--verify-stat-only";
20 else if (verbose)
21 argv[1] = "--verify-stat";
22 else
23 argv[1] = "--verify";
fc5fc509 24
f711ab54 25 /*
3de89c9d
JH
26 * In addition to "foo.pack" we accept "foo.idx" and "foo";
27 * normalize these forms to "foo.pack" for "index-pack --verify".
f711ab54 28 */
3de89c9d 29 strbuf_addstr(&arg, path);
d6cd00c7
JK
30 if (strbuf_strip_suffix(&arg, ".idx") ||
31 !ends_with(arg.buf, ".pack"))
32 strbuf_addstr(&arg, ".pack");
3de89c9d 33 argv[2] = arg.buf;
fc5fc509 34
3de89c9d
JH
35 index_pack.argv = argv;
36 index_pack.git_cmd = 1;
77d3ecee 37
3de89c9d 38 err = run_command(&index_pack);
6c4f3ec9
JH
39
40 if (verbose || stat_only) {
77d3ecee 41 if (err)
3de89c9d 42 printf("%s: bad\n", arg.buf);
77d3ecee 43 else {
6c4f3ec9 44 if (!stat_only)
3de89c9d 45 printf("%s: ok\n", arg.buf);
77d3ecee
NP
46 }
47 }
3de89c9d 48 strbuf_release(&arg);
d0d619c8
RS
49
50 return err;
f9253394
JH
51}
52
c9c3c678 53static const char * const verify_pack_usage[] = {
9c9b4f2f 54 N_("git verify-pack [-v | --verbose] [-s | --stat-only] <pack>..."),
c9c3c678
SB
55 NULL
56};
f3bf9224 57
2e3ed670 58int cmd_verify_pack(int argc, const char **argv, const char *prefix)
f9253394 59{
0eaf22f4 60 int err = 0;
6c4f3ec9 61 unsigned int flags = 0;
c9c3c678
SB
62 int i;
63 const struct option verify_pack_options[] = {
0a245e24 64 OPT_BIT('v', "verbose", &flags, N_("verbose"),
6c4f3ec9 65 VERIFY_PACK_VERBOSE),
0a245e24 66 OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
6c4f3ec9 67 VERIFY_PACK_STAT_ONLY),
c9c3c678
SB
68 OPT_END()
69 };
f9253394 70
ef90d6d4 71 git_config(git_default_config, NULL);
c9c3c678
SB
72 argc = parse_options(argc, argv, prefix, verify_pack_options,
73 verify_pack_usage, 0);
74 if (argc < 1)
75 usage_with_options(verify_pack_usage, verify_pack_options);
76 for (i = 0; i < argc; i++) {
6c4f3ec9 77 if (verify_one_pack(argv[i], flags))
c9c3c678 78 err = 1;
f9253394 79 }
6f05b57d 80
0eaf22f4 81 return err;
f9253394 82}