3 #include "commit-graph.h"
6 #include "environment.h"
8 #include "object-store.h"
10 #include "repository.h"
14 static void test_parse_commit_in_graph(const char *gitdir
, const char *worktree
,
15 const struct object_id
*commit_oid
)
19 struct commit_list
*parent
;
21 setup_git_env(gitdir
);
23 memset(the_repository
, 0, sizeof(*the_repository
));
25 if (repo_init(&r
, gitdir
, worktree
))
26 die("Couldn't init repo");
28 repo_set_hash_algo(the_repository
, hash_algo_by_ptr(r
.hash_algo
));
30 c
= lookup_commit(&r
, commit_oid
);
32 if (!parse_commit_in_graph(&r
, c
))
33 die("Couldn't parse commit");
35 printf("%"PRItime
, c
->date
);
36 for (parent
= c
->parents
; parent
; parent
= parent
->next
)
37 printf(" %s", oid_to_hex(&parent
->item
->object
.oid
));
43 static void test_get_commit_tree_in_graph(const char *gitdir
,
45 const struct object_id
*commit_oid
)
51 setup_git_env(gitdir
);
53 memset(the_repository
, 0, sizeof(*the_repository
));
55 if (repo_init(&r
, gitdir
, worktree
))
56 die("Couldn't init repo");
58 repo_set_hash_algo(the_repository
, hash_algo_by_ptr(r
.hash_algo
));
60 c
= lookup_commit(&r
, commit_oid
);
63 * get_commit_tree_in_graph does not automatically parse the commit, so
66 if (!parse_commit_in_graph(&r
, c
))
67 die("Couldn't parse commit");
68 tree
= get_commit_tree_in_graph(&r
, c
);
70 die("Couldn't get commit tree");
72 printf("%s\n", oid_to_hex(&tree
->object
.oid
));
77 int cmd__repository(int argc
, const char **argv
)
81 setup_git_directory_gently(&nongit_ok
);
84 die("must have at least 2 arguments");
85 if (!strcmp(argv
[1], "parse_commit_in_graph")) {
88 die("not enough arguments");
89 if (parse_oid_hex(argv
[4], &oid
, &argv
[4]))
90 die("cannot parse oid '%s'", argv
[4]);
91 test_parse_commit_in_graph(argv
[2], argv
[3], &oid
);
92 } else if (!strcmp(argv
[1], "get_commit_tree_in_graph")) {
95 die("not enough arguments");
96 if (parse_oid_hex(argv
[4], &oid
, &argv
[4]))
97 die("cannot parse oid '%s'", argv
[4]);
98 test_get_commit_tree_in_graph(argv
[2], argv
[3], &oid
);
100 die("unrecognized '%s'", argv
[1]);