2 #include "commit-graph.h"
5 #include "environment.h"
7 #include "object-store-ll.h"
9 #include "repository.h"
13 static void test_parse_commit_in_graph(const char *gitdir
, const char *worktree
,
14 const struct object_id
*commit_oid
)
18 struct commit_list
*parent
;
20 setup_git_env(gitdir
);
22 memset(the_repository
, 0, sizeof(*the_repository
));
24 if (repo_init(&r
, gitdir
, worktree
))
25 die("Couldn't init repo");
27 repo_set_hash_algo(the_repository
, hash_algo_by_ptr(r
.hash_algo
));
29 c
= lookup_commit(&r
, commit_oid
);
31 if (!parse_commit_in_graph(&r
, c
))
32 die("Couldn't parse commit");
34 printf("%"PRItime
, c
->date
);
35 for (parent
= c
->parents
; parent
; parent
= parent
->next
)
36 printf(" %s", oid_to_hex(&parent
->item
->object
.oid
));
42 static void test_get_commit_tree_in_graph(const char *gitdir
,
44 const struct object_id
*commit_oid
)
50 setup_git_env(gitdir
);
52 memset(the_repository
, 0, sizeof(*the_repository
));
54 if (repo_init(&r
, gitdir
, worktree
))
55 die("Couldn't init repo");
57 repo_set_hash_algo(the_repository
, hash_algo_by_ptr(r
.hash_algo
));
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
)
80 setup_git_directory_gently(&nongit_ok
);
83 die("must have at least 2 arguments");
84 if (!strcmp(argv
[1], "parse_commit_in_graph")) {
87 die("not enough arguments");
88 if (parse_oid_hex(argv
[4], &oid
, &argv
[4]))
89 die("cannot parse oid '%s'", argv
[4]);
90 test_parse_commit_in_graph(argv
[2], argv
[3], &oid
);
91 } else if (!strcmp(argv
[1], "get_commit_tree_in_graph")) {
94 die("not enough arguments");
95 if (parse_oid_hex(argv
[4], &oid
, &argv
[4]))
96 die("cannot parse oid '%s'", argv
[4]);
97 test_get_commit_tree_in_graph(argv
[2], argv
[3], &oid
);
99 die("unrecognized '%s'", argv
[1]);