Skip to content

Commit 20a2b02

Browse files
committed
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.
1 parent 27e98cf commit 20a2b02

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/refdb_fs.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,30 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
513513

514514
fsit_opts.flags = backend->iterator_flags;
515515

516+
if (iter->glob) {
517+
const char *last_sep = NULL;
518+
const char *pos;
519+
for (pos = iter->glob; *pos; ++pos) {
520+
switch (*pos) {
521+
case '?':
522+
case '*':
523+
case '[':
524+
case '\\':
525+
break;
526+
case '/':
527+
last_sep = pos;
528+
/* FALLTHROUGH */
529+
default:
530+
continue;
531+
}
532+
break;
533+
}
534+
if (last_sep) {
535+
ref_prefix = iter->glob;
536+
ref_prefix_len = (last_sep - ref_prefix) + 1;
537+
}
538+
}
539+
516540
if ((error = git_buf_printf(&path, "%s/", backend->commonpath)) < 0 ||
517541
(error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0 ||
518542
(error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {

0 commit comments

Comments
 (0)