l10n: git.pot: v2.23.0 round 1 (130 new, 35 removed)
[git/raj.git] / t / helper / test-repository.c
blobf7f861844560e0578eda989e39c4bd0572dcd5d6
1 #include "test-tool.h"
2 #include "cache.h"
3 #include "commit-graph.h"
4 #include "commit.h"
5 #include "config.h"
6 #include "object-store.h"
7 #include "object.h"
8 #include "repository.h"
9 #include "tree.h"
11 static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
12 const struct object_id *commit_oid)
14 struct repository r;
15 struct commit *c;
16 struct commit_list *parent;
18 setup_git_env(gitdir);
20 memset(the_repository, 0, sizeof(*the_repository));
22 /* TODO: Needed for temporary hack in hashcmp, see 183a638b7da. */
23 repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
25 if (repo_init(&r, gitdir, worktree))
26 die("Couldn't init repo");
28 c = lookup_commit(&r, commit_oid);
30 if (!parse_commit_in_graph(&r, c))
31 die("Couldn't parse commit");
33 printf("%"PRItime, c->date);
34 for (parent = c->parents; parent; parent = parent->next)
35 printf(" %s", oid_to_hex(&parent->item->object.oid));
36 printf("\n");
38 repo_clear(&r);
41 static void test_get_commit_tree_in_graph(const char *gitdir,
42 const char *worktree,
43 const struct object_id *commit_oid)
45 struct repository r;
46 struct commit *c;
47 struct tree *tree;
49 setup_git_env(gitdir);
51 memset(the_repository, 0, sizeof(*the_repository));
53 /* TODO: Needed for temporary hack in hashcmp, see 183a638b7da. */
54 repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
56 if (repo_init(&r, gitdir, worktree))
57 die("Couldn't init repo");
59 c = lookup_commit(&r, commit_oid);
62 * get_commit_tree_in_graph does not automatically parse the commit, so
63 * parse it first.
65 if (!parse_commit_in_graph(&r, c))
66 die("Couldn't parse commit");
67 tree = get_commit_tree_in_graph(&r, c);
68 if (!tree)
69 die("Couldn't get commit tree");
71 printf("%s\n", oid_to_hex(&tree->object.oid));
73 repo_clear(&r);
76 int cmd__repository(int argc, const char **argv)
78 if (argc < 2)
79 die("must have at least 2 arguments");
80 if (!strcmp(argv[1], "parse_commit_in_graph")) {
81 struct object_id oid;
82 if (argc < 5)
83 die("not enough arguments");
84 if (parse_oid_hex(argv[4], &oid, &argv[4]))
85 die("cannot parse oid '%s'", argv[4]);
86 test_parse_commit_in_graph(argv[2], argv[3], &oid);
87 } else if (!strcmp(argv[1], "get_commit_tree_in_graph")) {
88 struct object_id oid;
89 if (argc < 5)
90 die("not enough arguments");
91 if (parse_oid_hex(argv[4], &oid, &argv[4]))
92 die("cannot parse oid '%s'", argv[4]);
93 test_get_commit_tree_in_graph(argv[2], argv[3], &oid);
94 } else {
95 die("unrecognized '%s'", argv[1]);
97 return 0;