3 #include "commit-graph.h"
6 #include "object-store.h"
8 #include "repository.h"
11 static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
12 const struct object_id *commit_oid)
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));
41 static void test_get_commit_tree_in_graph(const char *gitdir,
43 const struct object_id *commit_oid)
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
65 if (!parse_commit_in_graph(&r, c))
66 die("Couldn't parse commit");
67 tree = get_commit_tree_in_graph(&r, c);
69 die("Couldn't get commit tree");
71 printf("%s\n", oid_to_hex(&tree->object.oid));
76 int cmd__repository(int argc, const char **argv)
79 die("must have at least 2 arguments");
80 if (!strcmp(argv[1], "parse_commit_in_graph")) {
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")) {
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);
95 die("unrecognized '%s'", argv[1]);