Commit 71dd0861 by Patrick Steinhardt

refdb: rename refdb_fs_backend's .path to .gitpath

The variable '.path' of the refdb_fs_backend struct becomes
confusing regarding the introduction of the git commondir. It
does not immediatly become obvious what it should point to.

Fix this problem by renaming the variable to `gitpath`,
clarifying that it acutally points to the `.git` directory of the
repository, in contrast to the commonpath directory, which points
to the directory containing shared objects like references and
the object store.
parent 79ab3ef6
...@@ -55,7 +55,8 @@ typedef struct refdb_fs_backend { ...@@ -55,7 +55,8 @@ typedef struct refdb_fs_backend {
git_refdb_backend parent; git_refdb_backend parent;
git_repository *repo; git_repository *repo;
char *path; /* path to git directory */
char *gitpath;
git_sortedcache *refcache; git_sortedcache *refcache;
int peeling_mode; int peeling_mode;
...@@ -77,7 +78,7 @@ static int packed_reload(refdb_fs_backend *backend) ...@@ -77,7 +78,7 @@ static int packed_reload(refdb_fs_backend *backend)
git_buf packedrefs = GIT_BUF_INIT; git_buf packedrefs = GIT_BUF_INIT;
char *scan, *eof, *eol; char *scan, *eof, *eol;
if (!backend->path) if (!backend->gitpath)
return 0; return 0;
error = git_sortedcache_lockandload(backend->refcache, &packedrefs); error = git_sortedcache_lockandload(backend->refcache, &packedrefs);
...@@ -238,7 +239,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name) ...@@ -238,7 +239,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
/* if we fail to load the loose reference, assume someone changed /* if we fail to load the loose reference, assume someone changed
* the filesystem under us and skip it... * the filesystem under us and skip it...
*/ */
if (loose_readbuffer(&ref_file, backend->path, name) < 0) { if (loose_readbuffer(&ref_file, backend->gitpath, name) < 0) {
giterr_clear(); giterr_clear();
goto done; goto done;
} }
...@@ -287,7 +288,7 @@ static int _dirent_loose_load(void *payload, git_buf *full_path) ...@@ -287,7 +288,7 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
return error; return error;
} }
file_path = full_path->ptr + strlen(backend->path); file_path = full_path->ptr + strlen(backend->gitpath);
return loose_lookup_to_packfile(backend, file_path); return loose_lookup_to_packfile(backend, file_path);
} }
...@@ -303,7 +304,7 @@ static int packed_loadloose(refdb_fs_backend *backend) ...@@ -303,7 +304,7 @@ static int packed_loadloose(refdb_fs_backend *backend)
int error; int error;
git_buf refs_path = GIT_BUF_INIT; git_buf refs_path = GIT_BUF_INIT;
if (git_buf_joinpath(&refs_path, backend->path, GIT_REFS_DIR) < 0) if (git_buf_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
return -1; return -1;
/* /*
...@@ -331,7 +332,7 @@ static int refdb_fs_backend__exists( ...@@ -331,7 +332,7 @@ static int refdb_fs_backend__exists(
assert(backend); assert(backend);
if ((error = packed_reload(backend)) < 0 || if ((error = packed_reload(backend)) < 0 ||
(error = git_buf_joinpath(&ref_path, backend->path, ref_name)) < 0) (error = git_buf_joinpath(&ref_path, backend->gitpath, ref_name)) < 0)
return error; return error;
*exists = git_path_isfile(ref_path.ptr) || *exists = git_path_isfile(ref_path.ptr) ||
...@@ -373,7 +374,7 @@ static int loose_lookup( ...@@ -373,7 +374,7 @@ static int loose_lookup(
if (out) if (out)
*out = NULL; *out = NULL;
if ((error = loose_readbuffer(&ref_file, backend->path, ref_name)) < 0) if ((error = loose_readbuffer(&ref_file, backend->gitpath, ref_name)) < 0)
/* cannot read loose ref file - gah */; /* cannot read loose ref file - gah */;
else if (git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF) == 0) { else if (git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF) == 0) {
const char *target; const char *target;
...@@ -484,12 +485,12 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter) ...@@ -484,12 +485,12 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT; git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry = NULL; const git_index_entry *entry = NULL;
if (!backend->path) /* do nothing if no path for loose refs */ if (!backend->gitpath) /* do nothing if no gitpath for loose refs */
return 0; return 0;
fsit_opts.flags = backend->iterator_flags; fsit_opts.flags = backend->iterator_flags;
if ((error = git_buf_printf(&path, "%s/refs", backend->path)) < 0 || if ((error = git_buf_printf(&path, "%s/refs", backend->gitpath)) < 0 ||
(error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) { (error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
git_buf_free(&path); git_buf_free(&path);
return error; return error;
...@@ -729,10 +730,10 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char * ...@@ -729,10 +730,10 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
/* Remove a possibly existing empty directory hierarchy /* Remove a possibly existing empty directory hierarchy
* which name would collide with the reference name * which name would collide with the reference name
*/ */
if ((error = git_futils_rmdir_r(name, backend->path, GIT_RMDIR_SKIP_NONEMPTY)) < 0) if ((error = git_futils_rmdir_r(name, backend->gitpath, GIT_RMDIR_SKIP_NONEMPTY)) < 0)
return error; return error;
if (git_buf_joinpath(&ref_path, backend->path, name) < 0) if (git_buf_joinpath(&ref_path, backend->gitpath, name) < 0)
return -1; return -1;
error = git_filebuf_open(file, ref_path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE); error = git_filebuf_open(file, ref_path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE);
...@@ -1283,7 +1284,7 @@ static int refdb_fs_backend__delete_tail( ...@@ -1283,7 +1284,7 @@ static int refdb_fs_backend__delete_tail(
} }
/* If a loose reference exists, remove it from the filesystem */ /* If a loose reference exists, remove it from the filesystem */
if (git_buf_joinpath(&loose_path, backend->path, ref_name) < 0) if (git_buf_joinpath(&loose_path, backend->gitpath, ref_name) < 0)
return -1; return -1;
...@@ -1408,20 +1409,20 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend) ...@@ -1408,20 +1409,20 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
assert(backend); assert(backend);
git_sortedcache_free(backend->refcache); git_sortedcache_free(backend->refcache);
git__free(backend->path); git__free(backend->gitpath);
git__free(backend); git__free(backend);
} }
static int setup_namespace(git_buf *path, git_repository *repo) static int setup_namespace(git_buf *gitpath, git_repository *repo)
{ {
char *parts, *start, *end; char *parts, *start, *end;
/* Not all repositories have a path */ /* Not all repositories have a gitpath */
if (repo->path_repository == NULL) if (repo->path_repository == NULL)
return 0; return 0;
/* Load the path to the repo first */ /* Load the path to the repo first */
git_buf_puts(path, repo->path_repository); git_buf_puts(gitpath, repo->path_repository);
/* if the repo is not namespaced, nothing else to do */ /* if the repo is not namespaced, nothing else to do */
if (repo->namespace == NULL) if (repo->namespace == NULL)
...@@ -1438,19 +1439,19 @@ static int setup_namespace(git_buf *path, git_repository *repo) ...@@ -1438,19 +1439,19 @@ static int setup_namespace(git_buf *path, git_repository *repo)
* refs under refs/namespaces/foo/refs/namespaces/bar/ * refs under refs/namespaces/foo/refs/namespaces/bar/
*/ */
while ((start = git__strsep(&end, "/")) != NULL) { while ((start = git__strsep(&end, "/")) != NULL) {
git_buf_printf(path, "refs/namespaces/%s/", start); git_buf_printf(gitpath, "refs/namespaces/%s/", start);
} }
git_buf_printf(path, "refs/namespaces/%s/refs", end); git_buf_printf(gitpath, "refs/namespaces/%s/refs", end);
git__free(parts); git__free(parts);
/* Make sure that the folder with the namespace exists */ /* Make sure that the folder with the namespace exists */
if (git_futils_mkdir_relative(git_buf_cstr(path), repo->path_repository, if (git_futils_mkdir_relative(git_buf_cstr(gitpath), repo->path_repository,
0777, GIT_MKDIR_PATH, NULL) < 0) 0777, GIT_MKDIR_PATH, NULL) < 0)
return -1; return -1;
/* Return root of the namespaced path, i.e. without the trailing '/refs' */ /* Return root of the namespaced gitpath, i.e. without the trailing '/refs' */
git_buf_rtruncate_at_char(path, '/'); git_buf_rtruncate_at_char(gitpath, '/');
return 0; return 0;
} }
...@@ -1948,7 +1949,7 @@ int git_refdb_backend_fs( ...@@ -1948,7 +1949,7 @@ int git_refdb_backend_fs(
git_repository *repository) git_repository *repository)
{ {
int t = 0; int t = 0;
git_buf path = GIT_BUF_INIT; git_buf gitpath = GIT_BUF_INIT;
refdb_fs_backend *backend; refdb_fs_backend *backend;
backend = git__calloc(1, sizeof(refdb_fs_backend)); backend = git__calloc(1, sizeof(refdb_fs_backend));
...@@ -1956,18 +1957,18 @@ int git_refdb_backend_fs( ...@@ -1956,18 +1957,18 @@ int git_refdb_backend_fs(
backend->repo = repository; backend->repo = repository;
if (setup_namespace(&path, repository) < 0) if (setup_namespace(&gitpath, repository) < 0)
goto fail; goto fail;
backend->path = git_buf_detach(&path); backend->gitpath = git_buf_detach(&gitpath);
if (git_buf_joinpath(&path, backend->path, GIT_PACKEDREFS_FILE) < 0 || if (git_buf_joinpath(&gitpath, backend->gitpath, GIT_PACKEDREFS_FILE) < 0 ||
git_sortedcache_new( git_sortedcache_new(
&backend->refcache, offsetof(struct packref, name), &backend->refcache, offsetof(struct packref, name),
NULL, NULL, packref_cmp, git_buf_cstr(&path)) < 0) NULL, NULL, packref_cmp, git_buf_cstr(&gitpath)) < 0)
goto fail; goto fail;
git_buf_free(&path); git_buf_free(&gitpath);
if (!git_repository__cvar(&t, backend->repo, GIT_CVAR_IGNORECASE) && t) { if (!git_repository__cvar(&t, backend->repo, GIT_CVAR_IGNORECASE) && t) {
backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE; backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
...@@ -1999,8 +2000,8 @@ int git_refdb_backend_fs( ...@@ -1999,8 +2000,8 @@ int git_refdb_backend_fs(
return 0; return 0;
fail: fail:
git_buf_free(&path); git_buf_free(&gitpath);
git__free(backend->path); git__free(backend->gitpath);
git__free(backend); git__free(backend);
return -1; return -1;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment