mirror of
https://github.com/git/git.git
synced 2024-11-18 06:54:55 +01:00
3de89c9d42
This finally gets rid of the inefficient verify-pack implementation that walks objects in the packfile in their object name order and replaces it with a call to index-pack --verify. As a side effect, it also removes packed_object_info_detail() API which is rather expensive. As this changes the way errors are reported (verify-pack used to rely on the usual runtime error detection routine unpack_entry() to diagnose the CRC errors in an entry in the *.idx file; index-pack --verify checks the whole *.idx file in one go), update a test that expected the string "CRC" to appear in the error message. Signed-off-by: Junio C Hamano <gitster@pobox.com>
84 lines
2 KiB
C
84 lines
2 KiB
C
#include "builtin.h"
|
|
#include "cache.h"
|
|
#include "run-command.h"
|
|
#include "parse-options.h"
|
|
|
|
#define VERIFY_PACK_VERBOSE 01
|
|
#define VERIFY_PACK_STAT_ONLY 02
|
|
|
|
static int verify_one_pack(const char *path, unsigned int flags)
|
|
{
|
|
struct child_process index_pack;
|
|
const char *argv[] = {"index-pack", NULL, NULL, NULL };
|
|
struct strbuf arg = STRBUF_INIT;
|
|
int verbose = flags & VERIFY_PACK_VERBOSE;
|
|
int stat_only = flags & VERIFY_PACK_STAT_ONLY;
|
|
int err;
|
|
|
|
if (stat_only)
|
|
argv[1] = "--verify-stat-only";
|
|
else if (verbose)
|
|
argv[1] = "--verify-stat";
|
|
else
|
|
argv[1] = "--verify";
|
|
|
|
/*
|
|
* In addition to "foo.pack" we accept "foo.idx" and "foo";
|
|
* normalize these forms to "foo.pack" for "index-pack --verify".
|
|
*/
|
|
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;
|
|
|
|
memset(&index_pack, 0, sizeof(index_pack));
|
|
index_pack.argv = argv;
|
|
index_pack.git_cmd = 1;
|
|
|
|
err = run_command(&index_pack);
|
|
|
|
if (verbose || stat_only) {
|
|
if (err)
|
|
printf("%s: bad\n", arg.buf);
|
|
else {
|
|
if (!stat_only)
|
|
printf("%s: ok\n", arg.buf);
|
|
}
|
|
}
|
|
strbuf_release(&arg);
|
|
|
|
return err;
|
|
}
|
|
|
|
static const char * const verify_pack_usage[] = {
|
|
"git verify-pack [-v|--verbose] [-s|--stat-only] <pack>...",
|
|
NULL
|
|
};
|
|
|
|
int cmd_verify_pack(int argc, const char **argv, const char *prefix)
|
|
{
|
|
int err = 0;
|
|
unsigned int flags = 0;
|
|
int i;
|
|
const struct option verify_pack_options[] = {
|
|
OPT_BIT('v', "verbose", &flags, "verbose",
|
|
VERIFY_PACK_VERBOSE),
|
|
OPT_BIT('s', "stat-only", &flags, "show statistics only",
|
|
VERIFY_PACK_STAT_ONLY),
|
|
OPT_END()
|
|
};
|
|
|
|
git_config(git_default_config, NULL);
|
|
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++) {
|
|
if (verify_one_pack(argv[i], flags))
|
|
err = 1;
|
|
}
|
|
|
|
return err;
|
|
}
|