strbuf_git_path(sb, "logs/%s", refname);
}
+static void files_ref_path(struct files_ref_store *refs,
+ struct strbuf *sb,
+ const char *refname)
+{
+ if (refs->submodule) {
+ strbuf_git_path_submodule(sb, refs->submodule, "%s", refname);
+ return;
+ }
+
+ strbuf_git_path(sb, "%s", refname);
+}
+
/*
* Get the packed_ref_cache for the specified files_ref_store,
* creating it if necessary.
struct strbuf refname;
struct strbuf path = STRBUF_INIT;
size_t path_baselen;
- int err = 0;
- if (refs->submodule)
- err = strbuf_git_path_submodule(&path, refs->submodule, "%s", dirname);
- else
- strbuf_git_path(&path, "%s", dirname);
+ files_ref_path(refs, &path, dirname);
path_baselen = path.len;
- if (err) {
- strbuf_release(&path);
- return;
- }
-
d = opendir(path.buf);
if (!d) {
strbuf_release(&path);
*type = 0;
strbuf_reset(&sb_path);
- if (refs->submodule)
- strbuf_git_path_submodule(&sb_path, refs->submodule, "%s", refname);
- else
- strbuf_git_path(&sb_path, "%s", refname);
+ files_ref_path(refs, &sb_path, refname);
path = sb_path.buf;
*lock_p = lock = xcalloc(1, sizeof(*lock));
lock->ref_name = xstrdup(refname);
- strbuf_git_path(&ref_file, "%s", refname);
+ files_ref_path(refs, &ref_file, refname);
retry:
switch (safe_create_leading_directories(ref_file.buf)) {
if (flags & REF_DELETING)
resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME;
- strbuf_git_path(&ref_file, "%s", refname);
+ files_ref_path(refs, &ref_file, refname);
resolved = !!resolve_ref_unsafe(refname, resolve_flags,
lock->old_oid.hash, type);
if (!resolved && errno == EISDIR) {
strbuf_setlen(&buf, q - buf.buf);
strbuf_reset(&sb);
- strbuf_git_path(&sb, "%s", buf.buf);
+ files_ref_path(refs, &sb, buf.buf);
if ((flags & REMOVE_EMPTY_PARENTS_REF) && rmdir(sb.buf))
flags &= ~REMOVE_EMPTY_PARENTS_REF;
struct strbuf path = STRBUF_INIT;
int result;
- strbuf_git_path(&path, "%s", newrefname);
+ files_ref_path(refs, &path, newrefname);
result = remove_empty_directories(&path);
strbuf_release(&path);
update->type & REF_ISSYMREF) {
/* It is a loose reference. */
strbuf_reset(&sb);
- strbuf_git_path(&sb, "%s", lock->ref_name);
+ files_ref_path(refs, &sb, lock->ref_name);
if (unlink_or_msg(sb.buf, err)) {
ret = TRANSACTION_GENERIC_ERROR;
goto cleanup;
static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
{
+ struct files_ref_store *refs =
+ files_downcast(ref_store, 0, "init_db");
struct strbuf sb = STRBUF_INIT;
- /* Check validity (but we don't need the result): */
- files_downcast(ref_store, 0, "init_db");
-
/*
* Create .git/refs/{heads,tags}
*/
- strbuf_git_path(&sb, "refs/heads");
+ files_ref_path(refs, &sb, "refs/heads");
safe_create_dir(sb.buf, 1);
strbuf_reset(&sb);
- strbuf_git_path(&sb, "refs/tags");
+ files_ref_path(refs, &sb, "refs/tags");
safe_create_dir(sb.buf, 1);
strbuf_release(&sb);