summaryrefslogtreecommitdiff
path: root/src/status.c
diff options
context:
space:
mode:
authorJason Penny <jasonpenny4@gmail.com>2011-06-24 20:36:53 -0400
committerVicent Marti <tanoku@gmail.com>2011-07-09 13:49:50 +0200
commit34dfea2774c10257eb13aae515d79ea2c224b911 (patch)
tree1c6641002488a0a0b05df1b427a36923f25f978a /src/status.c
parent6b251490a811e6539488f83f506b2b0839de7ee1 (diff)
downloadlibgit2-34dfea2774c10257eb13aae515d79ea2c224b911.tar.gz
status: handle subdirs for git_status_file
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/src/status.c b/src/status.c
index 60310c5c9..e42184292 100644
--- a/src/status.c
+++ b/src/status.c
@@ -152,6 +152,35 @@ static void recurse_tree_entries(git_tree *tree, git_vector *entries, char *path
git_tree_close(tree);
}
+static void recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path)
+{
+ char *dir_sep;
+ char buffer[GIT_PATH_MAX];
+ const git_tree_entry *tree_entry;
+ git_tree *subtree;
+
+ strcpy(buffer, path);
+
+ dir_sep = strchr(buffer, '/');
+ if (dir_sep) {
+ *dir_sep = '\0';
+
+ tree_entry = git_tree_entry_byname(tree, buffer);
+ if (tree_entry != NULL) {
+ if (git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid) == GIT_SUCCESS) {
+ recurse_tree_entry(subtree, e, dir_sep+1);
+ return;
+ }
+ }
+ }
+
+ tree_entry = git_tree_entry_byname(tree, path);
+ if (tree_entry != NULL) {
+ git_oid_cpy(&e->head_oid, &tree_entry->oid);
+ }
+ git_tree_close(tree);
+}
+
static int workdir_path_len;
static int dirent_cb(void *state, char *full_path)
{
@@ -320,7 +349,6 @@ int git_status_file(unsigned int *status_flags, git_repository *repo, const char
git_tree *tree;
git_reference *head_ref, *resolved_head_ref;
git_commit *head_commit;
- const git_tree_entry *tree_entry;
assert(status_flags);
@@ -342,12 +370,7 @@ int git_status_file(unsigned int *status_flags, git_repository *repo, const char
git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref));
git_commit_tree(&tree, head_commit);
- // TODO: handle subdirectories by walking into subtrees
- tree_entry = git_tree_entry_byname(tree, path);
- if (tree_entry != NULL) {
- git_oid_cpy(&e->head_oid, &tree_entry->oid);
- }
- git_tree_close(tree);
+ recurse_tree_entry(tree, e, path);
// Find file in Workdir
workdir_path_len = strlen(repo->path_workdir);