diff options
| author | Clemens Buchacher <drizzd@aon.at> | 2011-12-26 18:37:31 +0100 |
|---|---|---|
| committer | Clemens Buchacher <drizzd@aon.at> | 2011-12-30 20:14:05 +0100 |
| commit | 599f2849bad898c5dfd212e0629f79783f75b700 (patch) | |
| tree | ef7274cbb630ff363975248da5b0247fd12da47c /src/index.c | |
| parent | a26a156349c6d59a80825b9c3f4c9c423fed5d3a (diff) | |
| download | libgit2-599f2849bad898c5dfd212e0629f79783f75b700.tar.gz | |
add git_index_read_tree
Diffstat (limited to 'src/index.c')
| -rw-r--r-- | src/index.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/index.c b/src/index.c index 43e8efa57..9f9a08f0d 100644 --- a/src/index.c +++ b/src/index.c @@ -10,6 +10,7 @@ #include "common.h" #include "repository.h" #include "index.h" +#include "tree.h" #include "tree-cache.h" #include "hash.h" #include "git2/odb.h" @@ -936,3 +937,44 @@ int git_index_entry_stage(const git_index_entry *entry) { return (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT; } + +static int read_tree_cb(const char *root, git_tree_entry *tentry, void *data) +{ + int ret = GIT_SUCCESS; + git_index *index = data; + git_index_entry *entry = NULL; + git_buf path = GIT_BUF_INIT; + + if (entry_is_tree(tentry)) + goto exit; + + ret = git_buf_joinpath(&path, root, tentry->filename); + if (ret < GIT_SUCCESS) + goto exit; + + entry = git__calloc(1, sizeof(git_index_entry)); + if (!entry) { + ret = GIT_ENOMEM; + goto exit; + } + + entry->mode = tentry->attr; + entry->oid = tentry->oid; + entry->path = git_buf_detach(&path); + + ret = index_insert(index, entry, 0); + +exit: + git_buf_free(&path); + + if (ret < GIT_SUCCESS) + index_entry_free(entry); + return ret; +} + +int git_index_read_tree(git_index *index, git_tree *tree) +{ + git_index_clear(index); + + return git_tree_walk(tree, read_tree_cb, GIT_TREEWALK_POST, index); +} |
