]>
git.ipfire.org Git - thirdparty/git.git/blob - t/helper/test-repository.c
10a6dfc2160f6628db768db3fc7968fa62971815
3 #include "commit-graph.h"
7 #include "object-store.h"
9 #include "repository.h"
12 static void test_parse_commit_in_graph(const char *gitdir
, const char *worktree
,
13 const struct object_id
*commit_oid
)
17 struct commit_list
*parent
;
19 setup_git_env(gitdir
);
21 memset(the_repository
, 0, sizeof(*the_repository
));
23 if (repo_init(&r
, gitdir
, worktree
))
24 die("Couldn't init repo");
26 repo_set_hash_algo(the_repository
, hash_algo_by_ptr(r
.hash_algo
));
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 if (repo_init(&r
, gitdir
, worktree
))
54 die("Couldn't init repo");
56 repo_set_hash_algo(the_repository
, hash_algo_by_ptr(r
.hash_algo
));
58 c
= lookup_commit(&r
, commit_oid
);
61 * get_commit_tree_in_graph does not automatically parse the commit, so
64 if (!parse_commit_in_graph(&r
, c
))
65 die("Couldn't parse commit");
66 tree
= get_commit_tree_in_graph(&r
, c
);
68 die("Couldn't get commit tree");
70 printf("%s\n", oid_to_hex(&tree
->object
.oid
));
75 int cmd__repository(int argc
, const char **argv
)
79 setup_git_directory_gently(&nongit_ok
);
82 die("must have at least 2 arguments");
83 if (!strcmp(argv
[1], "parse_commit_in_graph")) {
86 die("not enough arguments");
87 if (parse_oid_hex(argv
[4], &oid
, &argv
[4]))
88 die("cannot parse oid '%s'", argv
[4]);
89 test_parse_commit_in_graph(argv
[2], argv
[3], &oid
);
90 } else if (!strcmp(argv
[1], "get_commit_tree_in_graph")) {
93 die("not enough arguments");
94 if (parse_oid_hex(argv
[4], &oid
, &argv
[4]))
95 die("cannot parse oid '%s'", argv
[4]);
96 test_get_commit_tree_in_graph(argv
[2], argv
[3], &oid
);
98 die("unrecognized '%s'", argv
[1]);