Merge branch 'maint'
[git/dscho.git] / builtin-verify-pack.c
blob7d39d9bcd178a65686d6757f8a89065d25f55b23
1 #include "builtin.h"
2 #include "cache.h"
3 #include "pack.h"
5 static int verify_one_pack(const char *path, int verbose)
7 char arg[PATH_MAX];
8 int len;
9 struct packed_git *pack;
10 int err;
12 len = strlcpy(arg, path, PATH_MAX);
13 if (len >= PATH_MAX)
14 return error("name too long: %s", path);
17 * In addition to "foo.idx" we accept "foo.pack" and "foo";
18 * normalize these forms to "foo.idx" for add_packed_git().
20 if (has_extension(arg, ".pack")) {
21 strcpy(arg + len - 5, ".idx");
22 len--;
23 } else if (!has_extension(arg, ".idx")) {
24 if (len + 4 >= PATH_MAX)
25 return error("name too long: %s.idx", arg);
26 strcpy(arg + len, ".idx");
27 len += 4;
31 * add_packed_git() uses our buffer (containing "foo.idx") to
32 * build the pack filename ("foo.pack"). Make sure it fits.
34 if (len + 1 >= PATH_MAX) {
35 arg[len - 4] = '\0';
36 return error("name too long: %s.pack", arg);
39 pack = add_packed_git(arg, len, 1);
40 if (!pack)
41 return error("packfile %s not found.", arg);
43 err = verify_pack(pack, verbose);
44 free(pack);
46 return err;
49 static const char verify_pack_usage[] = "git-verify-pack [-v] <pack>...";
51 int cmd_verify_pack(int argc, const char **argv, const char *prefix)
53 int err = 0;
54 int verbose = 0;
55 int no_more_options = 0;
56 int nothing_done = 1;
58 while (1 < argc) {
59 if (!no_more_options && argv[1][0] == '-') {
60 if (!strcmp("-v", argv[1]))
61 verbose = 1;
62 else if (!strcmp("--", argv[1]))
63 no_more_options = 1;
64 else
65 usage(verify_pack_usage);
67 else {
68 if (verify_one_pack(argv[1], verbose))
69 err = 1;
70 nothing_done = 0;
72 argc--; argv++;
75 if (nothing_done)
76 usage(verify_pack_usage);
78 return err;