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.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
diff --git a/src/cherrypick.c b/src/cherrypick.c
index ab06733..d8b6858 100644
--- a/src/cherrypick.c
+++ b/src/cherrypick.c
@@ -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;
diff --git a/src/fetchhead.c b/src/fetchhead.c
index 0d9ab2c..6e6f3eb 100644
--- a/src/fetchhead.c
+++ b/src/fetchhead.c
@@ -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)
diff --git a/src/merge.c b/src/merge.c
index eceadf0..857d513 100644
--- a/src/merge.c
+++ b/src/merge.c
@@ -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;
diff --git a/src/rebase.c b/src/rebase.c
index b2024a4..09941a2 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -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);
diff --git a/src/refdb_fs.c b/src/refdb_fs.c
index 91183cd..3d69063 100644
--- a/src/refdb_fs.c
+++ b/src/refdb_fs.c
@@ -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)
diff --git a/src/repository.c b/src/repository.c
index 8753636..5572484 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -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);
diff --git a/src/repository.h b/src/repository.h
index 74e15e1..c328ecd 100644
--- a/src/repository.h
+++ b/src/repository.h
@@ -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;
diff --git a/src/revert.c b/src/revert.c
index b255245..747938f 100644
--- a/src/revert.c
+++ b/src/revert.c
@@ -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)
diff --git a/tests/worktree/merge.c b/tests/worktree/merge.c
index 8221e4f..36cc2a6 100644
--- a/tests/worktree/merge.c
+++ b/tests/worktree/merge.c
@@ -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));
}
diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c
index 756cf38..81d5929 100644
--- a/tests/worktree/worktree.c
+++ b/tests/worktree/worktree.c
@@ -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));
}