builtin/verify-pack: implement an --object-format option
A recently added test in t5702 started using git verify-pack outside of a repository. While this poses no problems with SHA-1, with SHA-256 we implicitly rely on the setup of the repository to initialize our hash algorithm settings. Since we're not in a repository here, we need to provide git verify-pack help to set things up properly. git index-pack already knows an --object-format option, so let's accept one as well and pass it down to our git index-pack invocation. Since we're now dynamically adjusting the elements in argv, let's switch to using struct argv_array to manage them. Finally, let's make t5702 pass the proper argument on down to its git verify-pack caller. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
439d3a17b6
commit
e74b606d47
@ -7,21 +7,26 @@
|
|||||||
#define VERIFY_PACK_VERBOSE 01
|
#define VERIFY_PACK_VERBOSE 01
|
||||||
#define VERIFY_PACK_STAT_ONLY 02
|
#define VERIFY_PACK_STAT_ONLY 02
|
||||||
|
|
||||||
static int verify_one_pack(const char *path, unsigned int flags)
|
static int verify_one_pack(const char *path, unsigned int flags, const char *hash_algo)
|
||||||
{
|
{
|
||||||
struct child_process index_pack = CHILD_PROCESS_INIT;
|
struct child_process index_pack = CHILD_PROCESS_INIT;
|
||||||
const char *argv[] = {"index-pack", NULL, NULL, NULL };
|
struct argv_array *argv = &index_pack.args;
|
||||||
struct strbuf arg = STRBUF_INIT;
|
struct strbuf arg = STRBUF_INIT;
|
||||||
int verbose = flags & VERIFY_PACK_VERBOSE;
|
int verbose = flags & VERIFY_PACK_VERBOSE;
|
||||||
int stat_only = flags & VERIFY_PACK_STAT_ONLY;
|
int stat_only = flags & VERIFY_PACK_STAT_ONLY;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
argv_array_push(argv, "index-pack");
|
||||||
|
|
||||||
if (stat_only)
|
if (stat_only)
|
||||||
argv[1] = "--verify-stat-only";
|
argv_array_push(argv, "--verify-stat-only");
|
||||||
else if (verbose)
|
else if (verbose)
|
||||||
argv[1] = "--verify-stat";
|
argv_array_push(argv, "--verify-stat");
|
||||||
else
|
else
|
||||||
argv[1] = "--verify";
|
argv_array_push(argv, "--verify");
|
||||||
|
|
||||||
|
if (hash_algo)
|
||||||
|
argv_array_pushf(argv, "--object-format=%s", hash_algo);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In addition to "foo.pack" we accept "foo.idx" and "foo";
|
* In addition to "foo.pack" we accept "foo.idx" and "foo";
|
||||||
@ -31,9 +36,8 @@ static int verify_one_pack(const char *path, unsigned int flags)
|
|||||||
if (strbuf_strip_suffix(&arg, ".idx") ||
|
if (strbuf_strip_suffix(&arg, ".idx") ||
|
||||||
!ends_with(arg.buf, ".pack"))
|
!ends_with(arg.buf, ".pack"))
|
||||||
strbuf_addstr(&arg, ".pack");
|
strbuf_addstr(&arg, ".pack");
|
||||||
argv[2] = arg.buf;
|
argv_array_push(argv, arg.buf);
|
||||||
|
|
||||||
index_pack.argv = argv;
|
|
||||||
index_pack.git_cmd = 1;
|
index_pack.git_cmd = 1;
|
||||||
|
|
||||||
err = run_command(&index_pack);
|
err = run_command(&index_pack);
|
||||||
@ -60,12 +64,15 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
|
|||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
|
const char *object_format = NULL;
|
||||||
int i;
|
int i;
|
||||||
const struct option verify_pack_options[] = {
|
const struct option verify_pack_options[] = {
|
||||||
OPT_BIT('v', "verbose", &flags, N_("verbose"),
|
OPT_BIT('v', "verbose", &flags, N_("verbose"),
|
||||||
VERIFY_PACK_VERBOSE),
|
VERIFY_PACK_VERBOSE),
|
||||||
OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
|
OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
|
||||||
VERIFY_PACK_STAT_ONLY),
|
VERIFY_PACK_STAT_ONLY),
|
||||||
|
OPT_STRING(0, "object-format", &object_format, N_("hash"),
|
||||||
|
N_("specify the hash algorithm to use")),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -75,7 +82,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
|
|||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
usage_with_options(verify_pack_usage, verify_pack_options);
|
usage_with_options(verify_pack_usage, verify_pack_options);
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
if (verify_one_pack(argv[i], flags))
|
if (verify_one_pack(argv[i], flags, object_format))
|
||||||
err = 1;
|
err = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,7 +829,7 @@ test_expect_success 'part of packfile response provided as URI' '
|
|||||||
# Ensure that my-blob and other-blob are in separate packfiles.
|
# Ensure that my-blob and other-blob are in separate packfiles.
|
||||||
for idx in http_child/.git/objects/pack/*.idx
|
for idx in http_child/.git/objects/pack/*.idx
|
||||||
do
|
do
|
||||||
git verify-pack --verbose $idx >out &&
|
git verify-pack --object-format=$(test_oid algo) --verbose $idx >out &&
|
||||||
{
|
{
|
||||||
grep "^[0-9a-f]\{16,\} " out || :
|
grep "^[0-9a-f]\{16,\} " out || :
|
||||||
} >out.objectlist &&
|
} >out.objectlist &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user