Пример #1
0
const git_oid *lookup_master_tree(git_repository *repo)
{
    int ret;
    git_reference *ref;
    const git_oid *commit_oid;
    const git_oid *tree_oid;
    git_commit *commit;

    ret = git_reference_lookup(&ref, repo, "refs/heads/master");
    if (ret) {
        printf("git_reference_lookup() error: %s\n", git_strerror(ret));
        return NULL;
    }
    if (git_reference_type(ref) != GIT_REF_OID) {
        perror("reference_type is not oid reference.");
        return NULL;
    }

    commit_oid = git_reference_oid(ref);

    ret = git_commit_lookup(&commit, repo, commit_oid);
    tree_oid = git_commit_tree_oid(commit);
    git_commit_free(commit);
    return tree_oid;
}
Пример #2
0
int
read_repo(const char *repo_name)
{
	int i;
	int r;
	int n;
	git_repository *repo;
	git_reference *head;
	git_oid oid;
	git_commit *commit;
	git_tree *tree;
	git_tree_entry *tree_entry;
	char out[41];
	out[40] = '\0';

	// opening the repository
	r = git_repository_open(&repo, repo_name);
	if (r)
		printf("error in opening the repository\n");
	printf("Opened the repository successfully.\n");

	// obtaining the head
	r = git_repository_head(&head, repo);
	if (r)
		printf("error in obtaining the head\n");
	r = git_reference_name_to_oid(&oid, repo, git_reference_name(head));
	if (r)
		printf("error in obtaining the ref id of head\n");
	printf("Obtained the head id %s\n", git_oid_tostr(out, 41, &oid));

	// obtaining the commit from commit id
	r = git_commit_lookup(&commit, repo, &oid);
	if (r)
		printf("error in obtaining the commit from oid\n");
	printf("Obtained the commit.\n");

	// obtaining the tree id from the commit
	oid = *git_commit_tree_oid(commit);

	// get the tree
	r = git_tree_lookup(&tree, repo, &oid);
	if (r)
		printf("error in looking up the tree for oid\n");
	printf("Lookup for tree of oid successful.\n");

	n = git_tree_entrycount(tree);
	for (i=0; i<n; i++) {
		tree_entry = git_tree_entry_byindex(tree, i);
		printf("entry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> %s %s\n", git_tree_entry_name(tree_entry), git_object_type2string(git_tree_entry_type(tree_entry)));
	}

	git_repository_free(repo);
	return 0;
}