[PATCH] Retire git-parse-remote.
[git] / verify-pack.c
1 #include "cache.h"
2 #include "pack.h"
3
4 static int verify_one_pack(char *arg, int verbose)
5 {
6         int len = strlen(arg);
7         struct packed_git *g;
8         
9         while (1) {
10                 /* Should name foo.idx, but foo.pack may be named;
11                  * convert it to foo.idx
12                  */
13                 if (!strcmp(arg + len - 5, ".pack")) {
14                         strcpy(arg + len - 5, ".idx");
15                         len--;
16                 }
17                 /* Should name foo.idx now */
18                 if ((g = add_packed_git(arg, len)))
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)))
24                         break;
25                 return error("packfile %s not found.", arg);
26         }
27         return verify_pack(g, verbose);
28 }
29
30 static const char verify_pack_usage[] = "git-verify-pack [-v] <pack>...";
31
32 int main(int ac, char **av)
33 {
34         int errs = 0;
35         int verbose = 0;
36         int no_more_options = 0;
37
38         while (1 < ac) {
39                 char path[PATH_MAX];
40
41                 if (!no_more_options && av[1][0] == '-') {
42                         if (!strcmp("-v", av[1]))
43                                 verbose = 1;
44                         else if (!strcmp("--", av[1]))
45                                 no_more_options = 1;
46                         else
47                                 usage(verify_pack_usage);
48                 }
49                 else {
50                         strcpy(path, av[1]);
51                         if (verify_one_pack(path, verbose))
52                                 errs++;
53                 }
54                 ac--; av++;
55         }
56         return !!errs;
57 }