Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-03-14 01:59:51 +0400
committerRussell Belfer <rb@github.com>2013-03-14 01:59:51 +0400
commitbbb1364671b1a111e4ba9bd6e34e016768306da4 (patch)
treebe2087cb16de9c9a7552d3ac251accf0159cebb6 /src/iterator.c
parentad003763ccb39c0e59f5c1d8372a202541a9049e (diff)
Fix workdir iterator bugs
This fixes two bugs with the workdir iterator depth check: first that the depth was not being decremented and second that empty directories were counting against the depth even though a frame was not being created for them. This also fixes a bug with the ENOTFOUND return code for workdir iterators when you attempt to advance_into an empty directory. Actually, that works correctly, but it was incorrectly being propogated into regular advance() calls in some circumstances. Added new tests for the above that create a huge hierarchy on the fly and try using the workdir iterator to traverse it.
Diffstat (limited to 'src/iterator.c')
-rw-r--r--src/iterator.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/iterator.c b/src/iterator.c
index e6e0ea481..1ac6a4919 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -973,11 +973,6 @@ static int workdir_iterator__expand_dir(workdir_iterator *wi)
int error;
workdir_iterator_frame *wf;
- if (++(wi->depth) > WORKDIR_MAX_DEPTH) {
- giterr_set(GITERR_REPOSITORY, "Working directory is too deep");
- return -1;
- }
-
wf = workdir_iterator__alloc_frame(wi);
GITERR_CHECK_ALLOC(wf);
@@ -990,6 +985,13 @@ static int workdir_iterator__expand_dir(workdir_iterator *wi)
return GIT_ENOTFOUND;
}
+ if (++(wi->depth) > WORKDIR_MAX_DEPTH) {
+ giterr_set(GITERR_REPOSITORY,
+ "Working directory is too deep (%d)", wi->depth);
+ workdir_iterator__free_frame(wf);
+ return -1;
+ }
+
workdir_iterator__seek_frame_start(wi, wf);
/* only push new ignores if this is not top level directory */
@@ -1086,6 +1088,7 @@ static int workdir_iterator__advance(
}
wi->stack = wf->next;
+ wi->depth--;
workdir_iterator__free_frame(wf);
git_ignore__pop_dir(&wi->ignores);
}
@@ -1119,6 +1122,7 @@ static int workdir_iterator__reset(
workdir_iterator__free_frame(wf);
git_ignore__pop_dir(&wi->ignores);
}
+ wi->depth = 0;
if (iterator__reset_range(self, start, end) < 0)
return -1;
@@ -1201,7 +1205,7 @@ static int workdir_iterator__update_entry(workdir_iterator *wi)
if (iterator__include_trees(wi))
return 0;
- return workdir_iterator__advance_into(NULL, (git_iterator *)wi);
+ return workdir_iterator__advance(NULL, (git_iterator *)wi);
}
int git_iterator_for_workdir(