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 if (repo_init(&r, gitdir, worktree))
23 die("Couldn't init repo");
25 repo_set_hash_algo(the_repository, hash_algo_by_ptr(r.hash_algo));
27 c = lookup_commit(&r, commit_oid);
29 if (!parse_commit_in_graph(&r, c))
30 die("Couldn't parse commit");
32 printf("%"PRItime, c->date);
33 for (parent = c->parents; parent; parent = parent->next)
34 printf(" %s", oid_to_hex(&parent->item->object.oid));
40 static void test_get_commit_tree_in_graph(const char *gitdir,
42 const struct object_id *commit_oid)
48 setup_git_env(gitdir);
50 memset(the_repository, 0, sizeof(*the_repository));
52 if (repo_init(&r, gitdir, worktree))
53 die("Couldn't init repo");
55 repo_set_hash_algo(the_repository, hash_algo_by_ptr(r.hash_algo));
57 c = lookup_commit(&r, commit_oid);
60 * get_commit_tree_in_graph does not automatically parse the commit, so
63 if (!parse_commit_in_graph(&r, c))
64 die("Couldn't parse commit");
65 tree = get_commit_tree_in_graph(&r, c);
67 die("Couldn't get commit tree");
69 printf("%s\n", oid_to_hex(&tree->object.oid));
74 int cmd__repository(int argc, const char **argv)
78 setup_git_directory_gently(&nongit_ok);
81 die("must have at least 2 arguments");
82 if (!strcmp(argv[1], "parse_commit_in_graph")) {
85 die("not enough arguments");
86 if (parse_oid_hex(argv[4], &oid, &argv[4]))
87 die("cannot parse oid '%s'", argv[4]);
88 test_parse_commit_in_graph(argv[2], argv[3], &oid);
89 } else if (!strcmp(argv[1], "get_commit_tree_in_graph")) {
92 die("not enough arguments");
93 if (parse_oid_hex(argv[4], &oid, &argv[4]))
94 die("cannot parse oid '%s'", argv[4]);
95 test_get_commit_tree_in_graph(argv[2], argv[3], &oid);
97 die("unrecognized '%s'", argv[1]);