I am working on a new git built-in. I am taking a commit (that I am pulling using lookup_commit_reference_by_name
) and then I want to go through the parents to check their trees. I try to get the tree object with get_commit_tree
, unfortunately it fails to provide the tree object. What am I doing wrong? Here's the built-in code that you could use to reproduce (working on git repo, by the way):
int cmd_blahblah(int argc, const char **argv, const char *prefix)
{
struct commit *a_commit;
struct commit_list *i;
a_commit = lookup_commit_reference_by_name("f64d4ca8d65bdca39da444d24bde94864ac01bb1");
for (i = a_commit->parents; i; i = i->next) {
struct tree *tree;
struct commit *parent_commit = i->item;
printf("parent commit: %s\n", oid_to_hex(&parent_commit->object.oid));
tree = get_commit_tree(parent_commit);
if (tree) {
printf("Got the tree\n");
printf("\ttree: %s\n", oid_to_hex(&tree->object.oid));
} else {
printf("Don't have a tree\n");
return -1;
}
}
return 0;
}
The output?
23:12 $ ../git blahblah
parent commit: 3dcec76d9df911ed8321007b1d197c1a206dc164
Don't have a tree