git-verify-pack: show usage when no pack was specified
[git/jrn.git] / verify-pack.c
blob7201596bf948094979464eddc1000a1cd5cb2ae6
1 #include "cache.h"
2 #include "pack.h"
4 static int verify_one_pack(char *arg, int verbose)
6 int len = strlen(arg);
7 struct packed_git *g;
9 while (1) {
10 /* Should name foo.idx, but foo.pack may be named;
11 * convert it to foo.idx
13 if (has_extension(arg, len, ".pack")) {
14 strcpy(arg + len - 5, ".idx");
15 len--;
17 /* Should name foo.idx now */
18 if ((g = add_packed_git(arg, len, 1)))
19 break;
20 /* No? did you name just foo? */
21 strcpy(arg + len, ".idx");
22 len += 4;
23 if ((g = add_packed_git(arg, len, 1)))
24 break;
25 return error("packfile %s not found.", arg);
27 return verify_pack(g, verbose);
30 static const char verify_pack_usage[] = "git-verify-pack [-v] <pack>...";
32 int main(int ac, char **av)
34 int errs = 0;
35 int verbose = 0;
36 int no_more_options = 0;
37 int nothing_done = 1;
39 while (1 < ac) {
40 char path[PATH_MAX];
42 if (!no_more_options && av[1][0] == '-') {
43 if (!strcmp("-v", av[1]))
44 verbose = 1;
45 else if (!strcmp("--", av[1]))
46 no_more_options = 1;
47 else
48 usage(verify_pack_usage);
50 else {
51 strcpy(path, av[1]);
52 if (verify_one_pack(path, verbose))
53 errs++;
54 nothing_done = 0;
56 ac--; av++;
59 if (nothing_done)
60 usage(verify_pack_usage);
62 return !!errs;