Skip to content

Commit e74b606

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 439d3a1 commit e74b606

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

builtin/verify-pack.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@
77
#define VERIFY_PACK_VERBOSE 01
88
#define VERIFY_PACK_STAT_ONLY 02
99

10-
static int verify_one_pack(const char *path, unsigned int flags)
10+
static int verify_one_pack(const char *path, unsigned int flags, const char *hash_algo)
1111
{
1212
struct child_process index_pack = CHILD_PROCESS_INIT;
13-
const char *argv[] = {"index-pack", NULL, NULL, NULL };
13+
struct argv_array *argv = &index_pack.args;
1414
struct strbuf arg = STRBUF_INIT;
1515
int verbose = flags & VERIFY_PACK_VERBOSE;
1616
int stat_only = flags & VERIFY_PACK_STAT_ONLY;
1717
int err;
1818

19+
argv_array_push(argv, "index-pack");
20+
1921
if (stat_only)
20-
argv[1] = "--verify-stat-only";
22+
argv_array_push(argv, "--verify-stat-only");
2123
else if (verbose)
22-
argv[1] = "--verify-stat";
24+
argv_array_push(argv, "--verify-stat");
2325
else
24-
argv[1] = "--verify";
26+
argv_array_push(argv, "--verify");
27+
28+
if (hash_algo)
29+
argv_array_pushf(argv, "--object-format=%s", hash_algo);
2530

2631
/*
2732
* 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)
3136
if (strbuf_strip_suffix(&arg, ".idx") ||
3237
!ends_with(arg.buf, ".pack"))
3338
strbuf_addstr(&arg, ".pack");
34-
argv[2] = arg.buf;
39+
argv_array_push(argv, arg.buf);
3540

36-
index_pack.argv = argv;
3741
index_pack.git_cmd = 1;
3842

3943
err = run_command(&index_pack);
@@ -60,12 +64,15 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
6064
{
6165
int err = 0;
6266
unsigned int flags = 0;
67+
const char *object_format = NULL;
6368
int i;
6469
const struct option verify_pack_options[] = {
6570
OPT_BIT('v', "verbose", &flags, N_("verbose"),
6671
VERIFY_PACK_VERBOSE),
6772
OPT_BIT('s', "stat-only", &flags, N_("show statistics only"),
6873
VERIFY_PACK_STAT_ONLY),
74+
OPT_STRING(0, "object-format", &object_format, N_("hash"),
75+
N_("specify the hash algorithm to use")),
6976
OPT_END()
7077
};
7178

@@ -75,7 +82,7 @@ int cmd_verify_pack(int argc, const char **argv, const char *prefix)
7582
if (argc < 1)
7683
usage_with_options(verify_pack_usage, verify_pack_options);
7784
for (i = 0; i < argc; i++) {
78-
if (verify_one_pack(argv[i], flags))
85+
if (verify_one_pack(argv[i], flags, object_format))
7986
err = 1;
8087
}
8188

t/t5702-protocol-v2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ test_expect_success 'part of packfile response provided as URI' '
829829
# Ensure that my-blob and other-blob are in separate packfiles.
830830
for idx in http_child/.git/objects/pack/*.idx
831831
do
832-
git verify-pack --verbose $idx >out &&
832+
git verify-pack --object-format=$(test_oid algo) --verbose $idx >out &&
833833
{
834834
grep "^[0-9a-f]\{16,\} " out || :
835835
} >out.objectlist &&

0 commit comments

Comments
 (0)