summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2014-05-06 14:03:58 -0700
committerRussell Belfer <rb@github.com>2014-05-06 14:03:58 -0700
commit1051100025c1075fa1b7f003dad7db086791b583 (patch)
tree8e094272d4bc63e5beb6b70382b63caf71fbab6e
parent6e9afb97d14545f9cea292f581de89d610ae8c07 (diff)
parentee311907ee0299ff2c1d7fc37699dc3e4da20c52 (diff)
downloadlibgit2-1051100025c1075fa1b7f003dad7db086791b583.tar.gz
Merge pull request #2324 from libgit2/cmn/file-in-objects-dir
odb: ignore files in the objects dir
-rw-r--r--src/odb_loose.c4
-rw-r--r--tests/odb/foreach.c24
2 files changed, 28 insertions, 0 deletions
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 7b46a6652..b2e8bed4d 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -755,6 +755,10 @@ static int foreach_cb(void *_state, git_buf *path)
{
struct foreach_state *state = (struct foreach_state *) _state;
+ /* non-dir is some stray file, ignore it */
+ if (!git_path_isdir(git_buf_cstr(path)))
+ return 0;
+
return git_path_direach(path, 0, foreach_object_dir_cb, state);
}
diff --git a/tests/odb/foreach.c b/tests/odb/foreach.c
index 256ae9cd7..ab3808b00 100644
--- a/tests/odb/foreach.c
+++ b/tests/odb/foreach.c
@@ -2,6 +2,7 @@
#include "odb.h"
#include "git2/odb_backend.h"
#include "pack.h"
+#include "buffer.h"
static git_odb *_odb;
static git_repository *_repo;
@@ -80,3 +81,26 @@ void test_odb_foreach__interrupt_foreach(void)
cl_assert_equal_i(-321, git_odb_foreach(_odb, foreach_stop_cb, &nobj));
cl_assert(nobj == 1000);
}
+
+void test_odb_foreach__files_in_objects_dir(void)
+{
+ git_repository *repo;
+ git_odb *odb;
+ git_buf buf = GIT_BUF_INIT;
+ size_t nobj = 0;
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+
+ cl_git_pass(git_buf_printf(&buf, "%s/objects/somefile", git_repository_path(repo)));
+
+ cl_git_mkfile(buf.ptr, "");
+
+ cl_git_pass(git_repository_odb(&odb, repo));
+ cl_git_pass(git_odb_foreach(odb, foreach_cb, &nobj));
+ cl_assert_equal_i(47 + 1640, nobj); /* count + in-pack */
+
+ git_odb_free(odb);
+ git_repository_free(repo);
+ cl_fixture_cleanup("testrepo.git");
+}