Commit 05e891f1f1bad3e2729a2e3800b314d5b63d43eb

Julian Ganz 2018-06-01T08:44:30

refdb_fs: test whether the base directory exists when globbing This commit fixes a regression introduced by 20a2b02d9a1bcb4825ec49605146223c565dcacf The commit introduced an optimization for finding references using a glob: rather than iterating over all references and matching each one against the glob, we would iterate only over references within the directory common to all possible references which may match against the glob. However, contrary to the `ref/` directory, which was the previous entry point for the iteration, this directory may not exist. In this case, the optimization causes an error (`ENOENT`) rather than the iterator simply yielding no references. This patch fixes the regression by checkign for this specific case.

diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 9db6281..0b4bbb4 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -538,12 +538,16 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
 	}
 
 	if ((error = git_buf_printf(&path, "%s/", backend->commonpath)) < 0 ||
-		(error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0 ||
-		(error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
+		(error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0) {
 		git_buf_free(&path);
 		return error;
 	}
 
+	if ((error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
+		git_buf_free(&path);
+		return (iter->glob && error == GIT_ENOTFOUND)? 0 : error;
+	}
+
 	error = git_buf_sets(&path, ref_prefix);
 
 	while (!error && !git_iterator_advance(&entry, fsit)) {