]> git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-find-pack.c
The fifth batch
[thirdparty/git.git] / t / helper / test-find-pack.c
1 #include "test-tool.h"
2 #include "object-name.h"
3 #include "object-store.h"
4 #include "packfile.h"
5 #include "parse-options.h"
6 #include "setup.h"
7
8 /*
9 * Display the path(s), one per line, of the packfile(s) containing
10 * the given object.
11 *
12 * If '--check-count <n>' is passed, then error out if the number of
13 * packfiles containing the object is not <n>.
14 */
15
16 static const char *find_pack_usage[] = {
17 "test-tool find-pack [--check-count <n>] <object>",
18 NULL
19 };
20
21 int cmd__find_pack(int argc, const char **argv)
22 {
23 struct object_id oid;
24 struct packed_git *p;
25 int count = -1, actual_count = 0;
26 const char *prefix = setup_git_directory();
27
28 struct option options[] = {
29 OPT_INTEGER('c', "check-count", &count, "expected number of packs"),
30 OPT_END(),
31 };
32
33 argc = parse_options(argc, argv, prefix, options, find_pack_usage, 0);
34 if (argc != 1)
35 usage(find_pack_usage[0]);
36
37 if (repo_get_oid(the_repository, argv[0], &oid))
38 die("cannot parse %s as an object name", argv[0]);
39
40 for (p = get_all_packs(the_repository); p; p = p->next)
41 if (find_pack_entry_one(oid.hash, p)) {
42 printf("%s\n", p->pack_name);
43 actual_count++;
44 }
45
46 if (count > -1 && count != actual_count)
47 die("bad packfile count %d instead of %d", actual_count, count);
48
49 return 0;
50 }