2006-08-10 19:02:38 +04:00
|
|
|
#include "builtin.h"
|
2005-06-29 13:51:27 +04:00
|
|
|
#include "cache.h"
|
2011-06-04 02:32:17 +04:00
|
|
|
#include "run-command.h"
|
2009-07-08 09:15:40 +04:00
|
|
|
#include "parse-options.h"
|
2008-06-25 07:18:17 +04:00
|
|
|
|
2009-08-08 02:45:30 +04:00
|
|
|
#define VERIFY_PACK_VERBOSE 01
|
|
|
|
#define VERIFY_PACK_STAT_ONLY 02
|
|
|
|
|
|
|
|
static int verify_one_pack(const char *path, unsigned int flags)
|
2005-06-29 13:51:27 +04:00
|
|
|
{
|
2011-06-04 02:32:17 +04:00
|
|
|
struct child_process index_pack;
|
|
|
|
const char *argv[] = {"index-pack", NULL, NULL, NULL };
|
|
|
|
struct strbuf arg = STRBUF_INIT;
|
2009-08-08 02:45:30 +04:00
|
|
|
int verbose = flags & VERIFY_PACK_VERBOSE;
|
|
|
|
int stat_only = flags & VERIFY_PACK_STAT_ONLY;
|
2006-08-10 19:02:35 +04:00
|
|
|
int err;
|
2006-08-10 19:02:32 +04:00
|
|
|
|
2011-06-04 02:32:17 +04:00
|
|
|
if (stat_only)
|
|
|
|
argv[1] = "--verify-stat-only";
|
|
|
|
else if (verbose)
|
|
|
|
argv[1] = "--verify-stat";
|
|
|
|
else
|
|
|
|
argv[1] = "--verify";
|
2006-08-10 19:02:34 +04:00
|
|
|
|
2006-08-10 19:02:36 +04:00
|
|
|
/*
|
2011-06-04 02:32:17 +04:00
|
|
|
* In addition to "foo.pack" we accept "foo.idx" and "foo";
|
|
|
|
* normalize these forms to "foo.pack" for "index-pack --verify".
|
2006-08-10 19:02:36 +04:00
|
|
|
*/
|
2011-06-04 02:32:17 +04:00
|
|
|
strbuf_addstr(&arg, path);
|
|
|
|
if (has_extension(arg.buf, ".idx"))
|
|
|
|
strbuf_splice(&arg, arg.len - 3, 3, "pack", 4);
|
|
|
|
else if (!has_extension(arg.buf, ".pack"))
|
|
|
|
strbuf_add(&arg, ".pack", 5);
|
|
|
|
argv[2] = arg.buf;
|
2006-08-10 19:02:34 +04:00
|
|
|
|
2011-06-04 02:32:17 +04:00
|
|
|
memset(&index_pack, 0, sizeof(index_pack));
|
|
|
|
index_pack.argv = argv;
|
|
|
|
index_pack.git_cmd = 1;
|
2008-06-25 07:18:17 +04:00
|
|
|
|
2011-06-04 02:32:17 +04:00
|
|
|
err = run_command(&index_pack);
|
2009-08-08 02:45:30 +04:00
|
|
|
|
|
|
|
if (verbose || stat_only) {
|
2008-06-25 07:18:17 +04:00
|
|
|
if (err)
|
2011-06-04 02:32:17 +04:00
|
|
|
printf("%s: bad\n", arg.buf);
|
2008-06-25 07:18:17 +04:00
|
|
|
else {
|
2009-08-08 02:45:30 +04:00
|
|
|
if (!stat_only)
|
2011-06-04 02:32:17 +04:00
|
|
|
printf("%s: ok\n", arg.buf);
|
2008-06-25 07:18:17 +04:00
|
|
|
}
|
|
|
|
}
|
2011-06-04 02:32:17 +04:00
|
|
|
strbuf_release(&arg);
|
2006-08-10 19:02:35 +04:00
|
|
|
|
|
|
|
return err;
|
2005-06-29 13:51:27 +04:00
|
|
|
}
|
|
|
|
|
2009-07-08 09:15:40 +04:00
|
|
|
static const char * const verify_pack_usage[] = {
|
2012-08-20 16:32:51 +04:00
|
|
|
N_("git verify-pack [-v|--verbose] [-s|--stat-only] <pack>..."),
|
2009-07-08 09:15:40 +04:00
|
|
|
NULL
|
|
|
|
};
|
2005-07-01 04:15:39 +04:00
|
|
|
|
2006-08-10 19:02:38 +04:00
|
|
|
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
|
2005-06-29 13:51:27 +04:00
|
|
|
{
|
2006-08-10 19:02:37 +04:00
|
|
|
int err = 0;
|
2009-08-08 02:45:30 +04:00
|
|
|
unsigned int flags = 0;
|
2009-07-08 09:15:40 +04:00
|
|
|
int i;
|
|
|
|
const struct option verify_pack_options[] = {
|
2012-08-20 16:32:51 +04:00
|
|
|
OPT_BIT('v', "verbose", &flags, N_("verbose"),
|
2009-08-08 02:45:30 +04:00
|
|
|
VERIFY_PACK_VERBOSE),
|
2012-08-20 16:32:51 +04:00
|
|
|
OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
|
2009-08-08 02:45:30 +04:00
|
|
|
VERIFY_PACK_STAT_ONLY),
|
2009-07-08 09:15:40 +04:00
|
|
|
OPT_END()
|
|
|
|
};
|
2005-06-29 13:51:27 +04:00
|
|
|
|
2008-05-14 21:46:53 +04:00
|
|
|
git_config(git_default_config, NULL);
|
2009-07-08 09:15:40 +04:00
|
|
|
argc = parse_options(argc, argv, prefix, verify_pack_options,
|
|
|
|
verify_pack_usage, 0);
|
|
|
|
if (argc < 1)
|
|
|
|
usage_with_options(verify_pack_usage, verify_pack_options);
|
|
|
|
for (i = 0; i < argc; i++) {
|
2009-08-08 02:45:30 +04:00
|
|
|
if (verify_one_pack(argv[i], flags))
|
2009-07-08 09:15:40 +04:00
|
|
|
err = 1;
|
2005-06-29 13:51:27 +04:00
|
|
|
}
|
2006-08-10 19:02:31 +04:00
|
|
|
|
2006-08-10 19:02:37 +04:00
|
|
|
return err;
|
2005-06-29 13:51:27 +04:00
|
|
|
}
|