diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-04-04 19:24:19 +0300 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-04-04 19:25:33 +0300 |
| commit | 0ad6efa110853763894b60e4c454985a726968da (patch) | |
| tree | e4522ed4f5ed33aadcbe03e46173f4996dafda57 /tests/t09-tree.c | |
| parent | b153589be2b3b9aea1f90a68891564ddeb12083c (diff) | |
| download | libgit2-0ad6efa110853763894b60e4c454985a726968da.tar.gz | |
Build & write custom trees in memory
Diffstat (limited to 'tests/t09-tree.c')
| -rw-r--r-- | tests/t09-tree.c | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/tests/t09-tree.c b/tests/t09-tree.c index 6c1b2e643..e4252dbca 100644 --- a/tests/t09-tree.c +++ b/tests/t09-tree.c @@ -29,6 +29,36 @@ static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; +#if 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; +} +#endif + BEGIN_TEST(read0, "acces randomly the entries on a loaded tree") git_oid id; git_repository *repo; @@ -55,7 +85,7 @@ BEGIN_TEST(read1, "read a tree from the repository") git_oid id; git_repository *repo; git_tree *tree; - git_tree_entry *entry; + const git_tree_entry *entry; git_object *obj; must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); @@ -80,10 +110,27 @@ BEGIN_TEST(read1, "read a tree from the repository") git_repository_free(repo); END_TEST +#if 0 +BEGIN_TEST(write0, "write a tree from an index") + git_repository *repo; + git_index *index; + git_oid tree_oid; + + must_pass(git_repository_open(&repo, "/tmp/redtmp/.git")); + must_pass(git_repository_index(&index, repo)); + + must_pass(git_tree_create_fromindex(&tree_oid, index)); + must_pass(print_tree(repo, &tree_oid, 0)); + + git_repository_free(repo); +END_TEST +#endif + BEGIN_SUITE(tree) + //ADD_TEST(print0); ADD_TEST(read0); ADD_TEST(read1); -// ADD_TEST(write0); /* TODO THREADSAFE */ -// ADD_TEST(write1); + //ADD_TEST(write0); + //ADD_TEST(write1); END_SUITE |
