Example #1
0
static int print_tree(git_repository *repo, const git_oid *tree_oid, int depth)
{
	static const char *indent = "                              ";
	git_tree *tree;
	unsigned int i;

	if (git_tree_lookup(&tree, repo, tree_oid) < GIT_SUCCESS)
		return GIT_ERROR;

	for (i = 0; i < git_tree_entrycount(tree); ++i) {
		const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
		char entry_oid[40];

		git_oid_fmt(entry_oid, &entry->oid);
		printf("%.*s%o [%.*s] %s\n", depth*2, indent, entry->attr, 40, entry_oid, entry->filename);

		if (entry->attr == S_IFDIR) {
			if (print_tree(repo, &entry->oid, depth + 1) < GIT_SUCCESS) {
				git_tree_close(tree);
				return GIT_ERROR;
			}
		}
	}

	git_tree_close(tree);
	return GIT_SUCCESS;
}
Example #2
0
static void kGitTree_free(CTX ctx, kRawPtr *po)
{
	if (po->rawptr != NULL) {
		git_tree_close((git_tree *)po->rawptr);
		po->rawptr = NULL;
	}
}
Example #3
0
int cmd_checkout(int argc, const char **argv) 
{
	/* Delete the following line once gits tests pass
	please_git_do_it_for_me();

	if (argc != 1)
		please_git_do_it_for_me();
	*/
	git_index *index;
	git_repository *repo;
	git_index_entry *index_entry;
	git_oid id;
	
	 /* Open the repository */
	if (git_repository_open(&repo, ".git")) {
		libgit_error();
	}

	/* Get the Index file of a Git repository */
	if (git_repository_index(&index,repo)) {
		libgit_error();
	}
	
	/* Find the first index of any entries which point to given path in the Git index */
	if (git_index_find (index, ".git")) {
		libgit_error();
	}

	int i = 0;

	/* get a pointer to one of the entries in the index */
	index_entry = git_index_get(index, i);
	if (index_entry == NULL)
		printf("Out of bound");
	else
		id = index_entry->oid;
	(void)id;
	
	git_reference *symbolic_ref;
	if (git_reference_lookup(&symbolic_ref, repo, "HEAD"))
		libgit_error();

	git_reference *direct_ref;
	if (git_reference_resolve(&direct_ref, symbolic_ref))
		libgit_error();

	const git_oid *oid;
	oid = git_reference_oid(direct_ref);
	if (oid == NULL) {
		printf("Internal error: reference is not direct\n");
		return EXIT_FAILURE;
	}
	
	git_tree *tree;
	/* Lookup a tree object from the repository */
	if (git_tree_lookup(&tree, repo, oid))
		libgit_error();
	
	/* Update the index ?? */
	if (git_index_read(index))
		libgit_error();
	
	git_index_free(index);
	git_tree_close(tree);
	
	return EXIT_SUCCESS;
}