Raw
1 #define USE_THE_REPOSITORY_VARIABLE
2
3 #include "test-tool.h"
4 #include "hex.h"
5 #include "repository.h"
6 #include "odb.h"
7 #include "setup.h"
8
9 /*
10 * Prints the size of the object corresponding to the given hash in a specific
11 * gitdir. This is similar to "git -C gitdir cat-file -s", except that this
12 * exercises the code that accesses the object of an arbitrary repository that
13 * is not the_repository. ("git -C gitdir" makes it so that the_repository is
14 * the one in gitdir.)
15 */
16 static void object_info(const char *gitdir, const char *oid_hex)
17 {
18 struct repository r;
19 struct object_id oid;
20 size_t size;
21 struct object_info oi = {.sizep = &size};
22 const char *p;
23
24 if (repo_init(&r, gitdir, NULL))
25 die("could not init repo");
26 if (parse_oid_hex_algop(oid_hex, &oid, &p, r.hash_algo))
27 die("could not parse oid");
28 if (odb_read_object_info_extended(r.objects, &oid, &oi, 0))
29 die("could not obtain object info");
30 printf("%d\n", (int) size);
31
32 repo_clear(&r);
33 }
34
35 int cmd__partial_clone(int argc, const char **argv)
36 {
37 setup_git_directory(the_repository);
38
39 if (argc < 4)
40 die("too few arguments");
41
42 if (!strcmp(argv[1], "object-info"))
43 object_info(argv[2], argv[3]);
44 else
45 die("invalid argument '%s'", argv[1]);
46
47 return 0;
48 }