Provide git_config with a callback-data parameter
[git/git.git] / builtin-verify-pack.c
CommitLineData
2e3ed670 1#include "builtin.h"
f9253394
JH
2#include "cache.h"
3#include "pack.h"
4
ae9c86f2 5static int verify_one_pack(const char *path, int verbose)
f9253394 6{
ae9c86f2
RS
7 char arg[PATH_MAX];
8 int len;
d0d619c8
RS
9 struct packed_git *pack;
10 int err;
ae9c86f2
RS
11
12 len = strlcpy(arg, path, PATH_MAX);
13 if (len >= PATH_MAX)
14 return error("name too long: %s", path);
15
fc5fc509
RS
16 /*
17 * In addition to "foo.idx" we accept "foo.pack" and "foo";
18 * normalize these forms to "foo.idx" for add_packed_git().
19 */
5bb1cda5 20 if (has_extension(arg, ".pack")) {
fc5fc509
RS
21 strcpy(arg + len - 5, ".idx");
22 len--;
5bb1cda5 23 } else if (!has_extension(arg, ".idx")) {
fc5fc509
RS
24 if (len + 4 >= PATH_MAX)
25 return error("name too long: %s.idx", arg);
26 strcpy(arg + len, ".idx");
27 len += 4;
f3bf9224 28 }
fc5fc509 29
f711ab54
RS
30 /*
31 * add_packed_git() uses our buffer (containing "foo.idx") to
32 * build the pack filename ("foo.pack"). Make sure it fits.
33 */
34 if (len + 1 >= PATH_MAX) {
35 arg[len - 4] = '\0';
36 return error("name too long: %s.pack", arg);
37 }
38
d0d619c8
RS
39 pack = add_packed_git(arg, len, 1);
40 if (!pack)
fc5fc509
RS
41 return error("packfile %s not found.", arg);
42
34081463 43 install_packed_git(pack);
d0d619c8 44 err = verify_pack(pack, verbose);
d0d619c8
RS
45
46 return err;
f9253394
JH
47}
48
4d1f1190 49static const char verify_pack_usage[] = "git-verify-pack [-v] <pack>...";
f3bf9224 50
2e3ed670 51int cmd_verify_pack(int argc, const char **argv, const char *prefix)
f9253394 52{
0eaf22f4 53 int err = 0;
f3bf9224
JH
54 int verbose = 0;
55 int no_more_options = 0;
6f05b57d 56 int nothing_done = 1;
f9253394 57
ef90d6d4 58 git_config(git_default_config, NULL);
2e3ed670
RS
59 while (1 < argc) {
60 if (!no_more_options && argv[1][0] == '-') {
61 if (!strcmp("-v", argv[1]))
f3bf9224 62 verbose = 1;
2e3ed670 63 else if (!strcmp("--", argv[1]))
f3bf9224
JH
64 no_more_options = 1;
65 else
66 usage(verify_pack_usage);
67 }
68 else {
2e3ed670 69 if (verify_one_pack(argv[1], verbose))
0eaf22f4 70 err = 1;
6f05b57d 71 nothing_done = 0;
f3bf9224 72 }
2e3ed670 73 argc--; argv++;
f9253394 74 }
6f05b57d
RS
75
76 if (nothing_done)
77 usage(verify_pack_usage);
78
0eaf22f4 79 return err;
f9253394 80}