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