git-p4: fix typos
[git/gitster.git] / t / helper / test-find-pack.c
blob14b2b0c12c0da366e78fe91acd9b0ef0045673b8
1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "test-tool.h"
4 #include "object-name.h"
5 #include "object-store.h"
6 #include "packfile.h"
7 #include "parse-options.h"
8 #include "setup.h"
11 * Display the path(s), one per line, of the packfile(s) containing
12 * the given object.
14 * If '--check-count <n>' is passed, then error out if the number of
15 * packfiles containing the object is not <n>.
18 static const char *find_pack_usage[] = {
19 "test-tool find-pack [--check-count <n>] <object>",
20 NULL
23 int cmd__find_pack(int argc, const char **argv)
25 struct object_id oid;
26 struct packed_git *p;
27 int count = -1, actual_count = 0;
28 const char *prefix = setup_git_directory();
30 struct option options[] = {
31 OPT_INTEGER('c', "check-count", &count, "expected number of packs"),
32 OPT_END(),
35 argc = parse_options(argc, argv, prefix, options, find_pack_usage, 0);
36 if (argc != 1)
37 usage(find_pack_usage[0]);
39 if (repo_get_oid(the_repository, argv[0], &oid))
40 die("cannot parse %s as an object name", argv[0]);
42 for (p = get_all_packs(the_repository); p; p = p->next)
43 if (find_pack_entry_one(oid.hash, p)) {
44 printf("%s\n", p->pack_name);
45 actual_count++;
48 if (count > -1 && count != actual_count)
49 die("bad packfile count %d instead of %d", actual_count, count);
51 return 0;