refdb_fs: prepare arbitration of the root used for ref iteration Instead of a hardcoded "refs", we may choose a different directory within the git directory as the root from which we look for references.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 140879d..4a349c5 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -505,26 +505,29 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
git_iterator *fsit = NULL;
git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry = NULL;
+ const char *ref_prefix = GIT_REFS_DIR;
+ size_t ref_prefix_len = strlen(ref_prefix);
if (!backend->commonpath) /* do nothing if no commonpath for loose refs */
return 0;
fsit_opts.flags = backend->iterator_flags;
- if ((error = git_buf_printf(&path, "%s/refs", backend->commonpath)) < 0 ||
+ 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) {
git_buf_free(&path);
return error;
}
- error = git_buf_sets(&path, GIT_REFS_DIR);
+ error = git_buf_sets(&path, ref_prefix);
while (!error && !git_iterator_advance(&entry, fsit)) {
const char *ref_name;
struct packref *ref;
char *ref_dup;
- git_buf_truncate(&path, strlen(GIT_REFS_DIR));
+ git_buf_truncate(&path, ref_prefix_len);
git_buf_puts(&path, entry->path);
ref_name = git_buf_cstr(&path);