]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-partial-clone.c
Merge branch 'tz/lib-gpg-prereq-fix'
[thirdparty/git.git] / t / helper / test-partial-clone.c
CommitLineData
ef830cc4 1#include "test-tool.h"
61a7b982 2#include "hex.h"
ef830cc4
JT
3#include "repository.h"
4#include "object-store.h"
e38da487 5#include "setup.h"
ef830cc4
JT
6
7/*
8 * Prints the size of the object corresponding to the given hash in a specific
9 * gitdir. This is similar to "git -C gitdir cat-file -s", except that this
10 * exercises the code that accesses the object of an arbitrary repository that
11 * is not the_repository. ("git -C gitdir" makes it so that the_repository is
12 * the one in gitdir.)
13 */
14static void object_info(const char *gitdir, const char *oid_hex)
15{
16 struct repository r;
17 struct object_id oid;
18 unsigned long size;
19 struct object_info oi = {.sizep = &size};
20 const char *p;
21
22 if (repo_init(&r, gitdir, NULL))
23 die("could not init repo");
24 if (parse_oid_hex(oid_hex, &oid, &p))
25 die("could not parse oid");
26 if (oid_object_info_extended(&r, &oid, &oi, 0))
27 die("could not obtain object info");
28 printf("%d\n", (int) size);
29}
30
31int cmd__partial_clone(int argc, const char **argv)
32{
33 setup_git_directory();
34
35 if (argc < 4)
36 die("too few arguments");
37
38 if (!strcmp(argv[1], "object-info"))
39 object_info(argv[2], argv[3]);
40 else
41 die("invalid argument '%s'", argv[1]);
42
43 return 0;
44}