Merge branch 'master' into mk/rename
[git/jrn.git] / verify-pack.c
blobf440a39678b23ebb9d58115f0481875add21e981
1 #include "cache.h"
2 #include "pack.h"
4 static int verify_one_pack(const char *path, int verbose)
6 char arg[PATH_MAX];
7 int len;
8 struct packed_git *pack;
9 int err;
11 len = strlcpy(arg, path, PATH_MAX);
12 if (len >= PATH_MAX)
13 return error("name too long: %s", path);
16 * In addition to "foo.idx" we accept "foo.pack" and "foo";
17 * normalize these forms to "foo.idx" for add_packed_git().
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;
30 * add_packed_git() uses our buffer (containing "foo.idx") to
31 * build the pack filename ("foo.pack"). Make sure it fits.
33 if (len + 1 >= PATH_MAX) {
34 arg[len - 4] = '\0';
35 return error("name too long: %s.pack", arg);
38 pack = add_packed_git(arg, len, 1);
39 if (!pack)
40 return error("packfile %s not found.", arg);
42 err = verify_pack(pack, verbose);
43 free(pack);
45 return err;
48 static const char verify_pack_usage[] = "git-verify-pack [-v] <pack>...";
50 int main(int ac, char **av)
52 int err = 0;
53 int verbose = 0;
54 int no_more_options = 0;
55 int nothing_done = 1;
57 while (1 < ac) {
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);
66 else {
67 if (verify_one_pack(av[1], verbose))
68 err = 1;
69 nothing_done = 0;
71 ac--; av++;
74 if (nothing_done)
75 usage(verify_pack_usage);
77 return err;