You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.6 KiB
80 lines
1.6 KiB
18 years ago
|
#include "builtin.h"
|
||
20 years ago
|
#include "cache.h"
|
||
|
#include "pack.h"
|
||
|
|
||
18 years ago
|
static int verify_one_pack(const char *path, int verbose)
|
||
20 years ago
|
{
|
||
18 years ago
|
char arg[PATH_MAX];
|
||
|
int len;
|
||
18 years ago
|
struct packed_git *pack;
|
||
|
int err;
|
||
18 years ago
|
|
||
|
len = strlcpy(arg, path, PATH_MAX);
|
||
|
if (len >= PATH_MAX)
|
||
|
return error("name too long: %s", path);
|
||
|
|
||
18 years ago
|
/*
|
||
|
* In addition to "foo.idx" we accept "foo.pack" and "foo";
|
||
|
* normalize these forms to "foo.idx" for add_packed_git().
|
||
|
*/
|
||
18 years ago
|
if (has_extension(arg, ".pack")) {
|
||
18 years ago
|
strcpy(arg + len - 5, ".idx");
|
||
|
len--;
|
||
18 years ago
|
} else if (!has_extension(arg, ".idx")) {
|
||
18 years ago
|
if (len + 4 >= PATH_MAX)
|
||
|
return error("name too long: %s.idx", arg);
|
||
|
strcpy(arg + len, ".idx");
|
||
|
len += 4;
|
||
20 years ago
|
}
|
||
18 years ago
|
|
||
18 years ago
|
/*
|
||
|
* add_packed_git() uses our buffer (containing "foo.idx") to
|
||
|
* build the pack filename ("foo.pack"). Make sure it fits.
|
||
|
*/
|
||
|
if (len + 1 >= PATH_MAX) {
|
||
|
arg[len - 4] = '\0';
|
||
|
return error("name too long: %s.pack", arg);
|
||
|
}
|
||
|
|
||
18 years ago
|
pack = add_packed_git(arg, len, 1);
|
||
|
if (!pack)
|
||
18 years ago
|
return error("packfile %s not found.", arg);
|
||
|
|
||
18 years ago
|
err = verify_pack(pack, verbose);
|
||
|
free(pack);
|
||
|
|
||
|
return err;
|
||
20 years ago
|
}
|
||
|
|
||
20 years ago
|
static const char verify_pack_usage[] = "git-verify-pack [-v] <pack>...";
|
||
20 years ago
|
|
||
18 years ago
|
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
18 years ago
|
int err = 0;
|
||
20 years ago
|
int verbose = 0;
|
||
|
int no_more_options = 0;
|
||
18 years ago
|
int nothing_done = 1;
|
||
20 years ago
|
|
||
18 years ago
|
while (1 < argc) {
|
||
|
if (!no_more_options && argv[1][0] == '-') {
|
||
|
if (!strcmp("-v", argv[1]))
|
||
20 years ago
|
verbose = 1;
|
||
18 years ago
|
else if (!strcmp("--", argv[1]))
|
||
20 years ago
|
no_more_options = 1;
|
||
|
else
|
||
|
usage(verify_pack_usage);
|
||
|
}
|
||
|
else {
|
||
18 years ago
|
if (verify_one_pack(argv[1], verbose))
|
||
18 years ago
|
err = 1;
|
||
18 years ago
|
nothing_done = 0;
|
||
20 years ago
|
}
|
||
18 years ago
|
argc--; argv++;
|
||
20 years ago
|
}
|
||
18 years ago
|
|
||
|
if (nothing_done)
|
||
|
usage(verify_pack_usage);
|
||
|
|
||
18 years ago
|
return err;
|
||
20 years ago
|
}
|