summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Ganz <neither@nut.email>2018-04-18 19:23:40 +0200
committerJulian Ganz <neither@nut.email>2018-04-27 16:30:27 +0200
commit20a2b02d9a1bcb4825ec49605146223c565dcacf (patch)
tree504243972bced5bbbd0eee287f7e7700aba9aa07
parent27e98cf7f0ef67cd34bcf92549fccaf91bc0e0bd (diff)
downloadlibgit2-20a2b02d9a1bcb4825ec49605146223c565dcacf.tar.gz
refdb_fs: enable root arbitration for fixed portion of globs
A glob used for iteration may start with an entire path containing no special characters. If we start scanning for references within that path rather than in `refs/`, we may end up scanning only a small fraction of all references.
-rw-r--r--src/refdb_fs.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 4a349c55a..7d01645f0 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -513,6 +513,30 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
fsit_opts.flags = backend->iterator_flags;
+ if (iter->glob) {
+ const char *last_sep = NULL;
+ const char *pos;
+ for (pos = iter->glob; *pos; ++pos) {
+ switch (*pos) {
+ case '?':
+ case '*':
+ case '[':
+ case '\\':
+ break;
+ case '/':
+ last_sep = pos;
+ /* FALLTHROUGH */
+ default:
+ continue;
+ }
+ break;
+ }
+ if (last_sep) {
+ ref_prefix = iter->glob;
+ ref_prefix_len = (last_sep - ref_prefix) + 1;
+ }
+ }
+
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) {