verify-pack.con commit Add the --color-words option to the diff options family (f59a59e)
   1#include "cache.h"
   2#include "pack.h"
   3
   4static int verify_one_pack(const char *path, int verbose)
   5{
   6        char arg[PATH_MAX];
   7        int len;
   8        struct packed_git *pack;
   9        int err;
  10
  11        len = strlcpy(arg, path, PATH_MAX);
  12        if (len >= PATH_MAX)
  13                return error("name too long: %s", path);
  14
  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;
  27        }
  28
  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
  38        pack = add_packed_git(arg, len, 1);
  39        if (!pack)
  40                return error("packfile %s not found.", arg);
  41
  42        err = verify_pack(pack, verbose);
  43        free(pack);
  44
  45        return err;
  46}
  47
  48static const char verify_pack_usage[] = "git-verify-pack [-v] <pack>...";
  49
  50int main(int ac, char **av)
  51{
  52        int err = 0;
  53        int verbose = 0;
  54        int no_more_options = 0;
  55        int nothing_done = 1;
  56
  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);
  65                }
  66                else {
  67                        if (verify_one_pack(av[1], verbose))
  68                                err = 1;
  69                        nothing_done = 0;
  70                }
  71                ac--; av++;
  72        }
  73
  74        if (nothing_done)
  75                usage(verify_pack_usage);
  76
  77        return err;
  78}