Commit 84f56cb0 by Patrick Steinhardt

repository: rename `path_repository` and `path_gitlink`

The `path_repository` variable is actually confusing to think
about, as it is not always clear what the repository actually is.
It may either be the path to the folder containing worktree and
.git directory, the path to .git itself, a worktree or something
entirely different. Actually, the intent of the variable is to
hold the path to the gitdir, which is either the .git directory
or the bare repository.

Rename the variable to `gitdir` to avoid confusion. While at it,
also rename `path_gitlink` to `gitlink` to improve consistency.
parent 384518d0
......@@ -28,7 +28,7 @@ static int write_cherrypick_head(
git_buf file_path = GIT_BUF_INIT;
int error = 0;
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
error = git_filebuf_commit(&file);
......@@ -49,7 +49,7 @@ static int write_merge_msg(
git_buf file_path = GIT_BUF_INIT;
int error = 0;
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) < 0 ||
(error = git_filebuf_printf(&file, "%s", commit_msg)) < 0)
goto cleanup;
......
......@@ -115,7 +115,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
assert(repo && fetchhead_refs);
if (git_buf_joinpath(&path, repo->path_repository, GIT_FETCH_HEAD_FILE) < 0)
if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1;
if (git_filebuf_open(&file, path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE) < 0) {
......@@ -249,7 +249,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
assert(repo && cb);
if (git_buf_joinpath(&path, repo->path_repository, GIT_FETCH_HEAD_FILE) < 0)
if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
return -1;
if ((error = git_futils_readbuffer(&file, git_buf_cstr(&path))) < 0)
......
......@@ -562,7 +562,7 @@ int git_repository_mergehead_foreach(
assert(repo && cb);
if ((error = git_buf_joinpath(&merge_head_path, repo->path_repository,
if ((error = git_buf_joinpath(&merge_head_path, repo->gitdir,
GIT_MERGE_HEAD_FILE)) < 0)
return error;
......@@ -2277,7 +2277,7 @@ static int write_merge_head(
assert(repo && heads);
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_HEAD_FILE)) < 0 ||
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_HEAD_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
......@@ -2305,7 +2305,7 @@ static int write_merge_mode(git_repository *repo)
assert(repo);
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MODE_FILE)) < 0 ||
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MODE_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
......@@ -2536,7 +2536,7 @@ static int write_merge_msg(
for (i = 0; i < heads_len; i++)
entries[i].merge_head = heads[i];
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) < 0 ||
(error = git_filebuf_write(&file, "Merge ", 6)) < 0)
goto cleanup;
......@@ -2914,7 +2914,7 @@ int git_merge__append_conflicts_to_merge_msg(
if (!git_index_has_conflicts(index))
return 0;
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_APPEND, GIT_MERGE_FILE_MODE)) < 0)
goto cleanup;
......
......@@ -92,7 +92,7 @@ static int rebase_state_type(
git_buf path = GIT_BUF_INIT;
git_rebase_type_t type = GIT_REBASE_TYPE_NONE;
if (git_buf_joinpath(&path, repo->path_repository, REBASE_APPLY_DIR) < 0)
if (git_buf_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
return -1;
if (git_path_isdir(git_buf_cstr(&path))) {
......@@ -101,7 +101,7 @@ static int rebase_state_type(
}
git_buf_clear(&path);
if (git_buf_joinpath(&path, repo->path_repository, REBASE_MERGE_DIR) < 0)
if (git_buf_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
return -1;
if (git_path_isdir(git_buf_cstr(&path))) {
......@@ -624,7 +624,7 @@ static int rebase_init_merge(
GIT_UNUSED(upstream);
if ((error = git_buf_joinpath(&state_path, repo->path_repository, REBASE_MERGE_DIR)) < 0)
if ((error = git_buf_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0)
goto done;
rebase->state_path = git_buf_detach(&state_path);
......
......@@ -1435,13 +1435,13 @@ static int setup_namespace(git_buf *gitpath, git_repository *repo)
char *parts, *start, *end;
/* Not all repositories have a gitpath */
if (repo->path_repository == NULL)
if (repo->gitdir == NULL)
return 0;
if (repo->commondir == NULL)
return 0;
/* Load the path to the repo first */
git_buf_puts(gitpath, repo->path_repository);
git_buf_puts(gitpath, repo->gitdir);
/* if the repo is not namespaced, nothing else to do */
if (repo->namespace == NULL)
......@@ -1877,7 +1877,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
&normalized, new_name, GIT_REF_FORMAT_ALLOW_ONELEVEL)) < 0)
return error;
if (git_buf_joinpath(&temp_path, repo->path_repository, GIT_REFLOG_DIR) < 0)
if (git_buf_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
return -1;
if (git_buf_joinpath(&old_path, git_buf_cstr(&temp_path), old_name) < 0)
......
......@@ -165,8 +165,8 @@ void git_repository_free(git_repository *repo)
git_buf_free(git_array_get(repo->reserved_names, i));
git_array_clear(repo->reserved_names);
git__free(repo->path_gitlink);
git__free(repo->path_repository);
git__free(repo->gitlink);
git__free(repo->gitdir);
git__free(repo->commondir);
git__free(repo->workdir);
git__free(repo->namespace);
......@@ -288,7 +288,7 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
if (ce && ce->value) {
if ((error = git_path_prettify_dir(
&worktree, ce->value, repo->path_repository)) < 0)
&worktree, ce->value, repo->gitdir)) < 0)
goto cleanup;
repo->workdir = git_buf_detach(&worktree);
......@@ -296,7 +296,7 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
else if (parent_path && git_path_isdir(parent_path->ptr))
repo->workdir = git_buf_detach(parent_path);
else {
if (git_path_dirname_r(&worktree, repo->path_repository) < 0 ||
if (git_path_dirname_r(&worktree, repo->gitdir) < 0 ||
git_path_to_dir(&worktree) < 0) {
error = -1;
goto cleanup;
......@@ -553,8 +553,8 @@ int git_repository_open_bare(
repo = repository_alloc();
GITERR_CHECK_ALLOC(repo);
repo->path_repository = git_buf_detach(&path);
GITERR_CHECK_ALLOC(repo->path_repository);
repo->gitdir = git_buf_detach(&path);
GITERR_CHECK_ALLOC(repo->gitdir);
repo->commondir = git_buf_detach(&common_path);
GITERR_CHECK_ALLOC(repo->commondir);
......@@ -763,19 +763,19 @@ int git_repository_open_ext(
repo = repository_alloc();
GITERR_CHECK_ALLOC(repo);
repo->path_repository = git_buf_detach(&path);
GITERR_CHECK_ALLOC(repo->path_repository);
repo->gitdir = git_buf_detach(&path);
GITERR_CHECK_ALLOC(repo->gitdir);
if (link_path.size) {
repo->path_gitlink = git_buf_detach(&link_path);
GITERR_CHECK_ALLOC(repo->path_gitlink);
repo->gitlink = git_buf_detach(&link_path);
GITERR_CHECK_ALLOC(repo->gitlink);
}
if (common_path.size) {
repo->commondir = git_buf_detach(&common_path);
GITERR_CHECK_ALLOC(repo->commondir);
}
if (repo->path_gitlink && repo->commondir && strcmp(repo->path_gitlink, repo->commondir))
if (repo->gitlink && repo->commondir && strcmp(repo->gitlink, repo->commondir))
repo->is_worktree = 1;
/*
......@@ -1114,7 +1114,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
git_buf index_path = GIT_BUF_INIT;
git_index *index;
if ((error = git_buf_joinpath(&index_path, repo->path_repository, GIT_INDEX_FILE)) < 0)
if ((error = git_buf_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
return error;
error = git_index_open(&index, index_path.ptr);
......@@ -1230,13 +1230,13 @@ bool git_repository__reserved_names(
prefixcmp = (error || ignorecase) ? git__prefixcmp_icase :
git__prefixcmp;
if (repo->path_gitlink &&
reserved_names_add8dot3(repo, repo->path_gitlink) < 0)
if (repo->gitlink &&
reserved_names_add8dot3(repo, repo->gitlink) < 0)
goto on_error;
if (repo->path_repository &&
prefixcmp(repo->path_repository, repo->workdir) == 0 &&
reserved_names_add8dot3(repo, repo->path_repository) < 0)
if (repo->gitdir &&
prefixcmp(repo->gitdir, repo->workdir) == 0 &&
reserved_names_add8dot3(repo, repo->gitdir) < 0)
goto on_error;
}
}
......@@ -2237,7 +2237,7 @@ int git_repository_item_path(git_buf *out, git_repository *repo, git_repository_
const char *git_repository_path(git_repository *repo)
{
assert(repo);
return repo->path_repository;
return repo->gitdir;
}
const char *git_repository_workdir(git_repository *repo)
......@@ -2366,7 +2366,7 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
git_oid_fmt(orig_head_str, orig_head);
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_ORIG_HEAD_FILE)) == 0 &&
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) == 0 &&
(error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
error = git_filebuf_commit(&file);
......@@ -2387,7 +2387,7 @@ int git_repository_message(git_buf *out, git_repository *repo)
git_buf_sanitize(out);
if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
return -1;
if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
......@@ -2408,7 +2408,7 @@ int git_repository_message_remove(git_repository *repo)
git_buf path = GIT_BUF_INIT;
int error;
if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
return -1;
error = p_unlink(git_buf_cstr(&path));
......@@ -2650,7 +2650,7 @@ int git_repository_state(git_repository *repo)
assert(repo);
if (git_buf_puts(&repo_path, repo->path_repository) < 0)
if (git_buf_puts(&repo_path, repo->gitdir) < 0)
return -1;
if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
......@@ -2692,7 +2692,7 @@ int git_repository__cleanup_files(
for (error = 0, i = 0; !error && i < files_len; ++i) {
const char *path;
if (git_buf_joinpath(&buf, repo->path_repository, files[i]) < 0)
if (git_buf_joinpath(&buf, repo->gitdir, files[i]) < 0)
return -1;
path = git_buf_cstr(&buf);
......@@ -2736,7 +2736,7 @@ int git_repository_is_shallow(git_repository *repo)
struct stat st;
int error;
if ((error = git_buf_joinpath(&path, repo->path_repository, "shallow")) < 0)
if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
return error;
error = git_path_lstat(path.ptr, &st);
......
......@@ -126,8 +126,8 @@ struct git_repository {
git_attr_cache *attrcache;
git_diff_driver_registry *diff_drivers;
char *path_repository;
char *path_gitlink;
char *gitlink;
char *gitdir;
char *commondir;
char *workdir;
char *namespace;
......
......@@ -27,7 +27,7 @@ static int write_revert_head(
git_buf file_path = GIT_BUF_INIT;
int error = 0;
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_REVERT_HEAD_FILE)) >= 0 &&
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_REVERT_HEAD_FILE)) >= 0 &&
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_REVERT_FILE_MODE)) >= 0 &&
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
error = git_filebuf_commit(&file);
......@@ -49,7 +49,7 @@ static int write_merge_msg(
git_buf file_path = GIT_BUF_INIT;
int error = 0;
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_REVERT_FILE_MODE)) < 0 ||
(error = git_filebuf_printf(&file, "Revert \"%s\"\n\nThis reverts commit %s.\n",
commit_msgline, commit_oidstr)) < 0)
......
......@@ -72,7 +72,7 @@ void test_worktree_merge__merge_setup(void)
for (i = 0; i < ARRAY_SIZE(merge_files); i++) {
git_buf_clear(&path);
cl_git_pass(git_buf_printf(&path, "%s/%s",
fixture.worktree->path_repository, merge_files[i]));
fixture.worktree->gitdir, merge_files[i]));
cl_assert(git_path_exists(path.ptr));
}
......
......@@ -117,8 +117,8 @@ void test_worktree_worktree__lookup(void)
git_buf_printf(&gitdir_path, "%s/worktrees/%s", fixture.repo->commondir, "testrepo-worktree");
cl_assert_equal_s(wt->gitdir_path, gitdir_path.ptr);
cl_assert_equal_s(wt->parent_path, fixture.repo->path_repository);
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->path_gitlink);
cl_assert_equal_s(wt->parent_path, fixture.repo->gitdir);
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
cl_assert_equal_s(wt->commondir_path, fixture.repo->commondir);
git_buf_free(&gitdir_path);
......@@ -196,7 +196,7 @@ void test_worktree_worktree__open_invalid_parent(void)
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
cl_git_pass(git_futils_writebuffer(&buf,
fixture.worktree->path_gitlink, O_RDWR, 0644));
fixture.worktree->gitlink, O_RDWR, 0644));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
......@@ -254,7 +254,7 @@ void test_worktree_worktree__init_existing_worktree(void)
cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr));
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->path_gitlink);
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
git_buf_free(&path);
git_worktree_free(wt);
......@@ -271,7 +271,7 @@ void test_worktree_worktree__init_existing_path(void)
* the init call */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
cl_git_pass(git_buf_joinpath(&path,
fixture.worktree->path_repository, wtfiles[i]));
fixture.worktree->gitdir, wtfiles[i]));
cl_git_pass(p_unlink(path.ptr));
}
......@@ -281,7 +281,7 @@ void test_worktree_worktree__init_existing_path(void)
/* Verify files have not been re-created */
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
cl_git_pass(git_buf_joinpath(&path,
fixture.worktree->path_repository, wtfiles[i]));
fixture.worktree->gitdir, wtfiles[i]));
cl_assert(!git_path_exists(path.ptr));
}
......
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