Skip to content

Commit 84f56cb

Browse files
committed
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 parent 384518d commit 84f56cb

File tree

10 files changed

+50
-50
lines changed

10 files changed

+50
-50
lines changed

src/cherrypick.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int write_cherrypick_head(
2828
git_buf file_path = GIT_BUF_INIT;
2929
int error = 0;
3030

31-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
31+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_CHERRYPICK_HEAD_FILE)) >= 0 &&
3232
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) >= 0 &&
3333
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
3434
error = git_filebuf_commit(&file);
@@ -49,7 +49,7 @@ static int write_merge_msg(
4949
git_buf file_path = GIT_BUF_INIT;
5050
int error = 0;
5151

52-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
52+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
5353
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_CHERRYPICK_FILE_MODE)) < 0 ||
5454
(error = git_filebuf_printf(&file, "%s", commit_msg)) < 0)
5555
goto cleanup;

src/fetchhead.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int git_fetchhead_write(git_repository *repo, git_vector *fetchhead_refs)
115115

116116
assert(repo && fetchhead_refs);
117117

118-
if (git_buf_joinpath(&path, repo->path_repository, GIT_FETCH_HEAD_FILE) < 0)
118+
if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
119119
return -1;
120120

121121
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,
249249

250250
assert(repo && cb);
251251

252-
if (git_buf_joinpath(&path, repo->path_repository, GIT_FETCH_HEAD_FILE) < 0)
252+
if (git_buf_joinpath(&path, repo->gitdir, GIT_FETCH_HEAD_FILE) < 0)
253253
return -1;
254254

255255
if ((error = git_futils_readbuffer(&file, git_buf_cstr(&path))) < 0)

src/merge.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ int git_repository_mergehead_foreach(
562562

563563
assert(repo && cb);
564564

565-
if ((error = git_buf_joinpath(&merge_head_path, repo->path_repository,
565+
if ((error = git_buf_joinpath(&merge_head_path, repo->gitdir,
566566
GIT_MERGE_HEAD_FILE)) < 0)
567567
return error;
568568

@@ -2277,7 +2277,7 @@ static int write_merge_head(
22772277

22782278
assert(repo && heads);
22792279

2280-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_HEAD_FILE)) < 0 ||
2280+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_HEAD_FILE)) < 0 ||
22812281
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) < 0)
22822282
goto cleanup;
22832283

@@ -2305,7 +2305,7 @@ static int write_merge_mode(git_repository *repo)
23052305

23062306
assert(repo);
23072307

2308-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MODE_FILE)) < 0 ||
2308+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MODE_FILE)) < 0 ||
23092309
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) < 0)
23102310
goto cleanup;
23112311

@@ -2536,7 +2536,7 @@ static int write_merge_msg(
25362536
for (i = 0; i < heads_len; i++)
25372537
entries[i].merge_head = heads[i];
25382538

2539-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
2539+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
25402540
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) < 0 ||
25412541
(error = git_filebuf_write(&file, "Merge ", 6)) < 0)
25422542
goto cleanup;
@@ -2914,7 +2914,7 @@ int git_merge__append_conflicts_to_merge_msg(
29142914
if (!git_index_has_conflicts(index))
29152915
return 0;
29162916

2917-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
2917+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
29182918
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_APPEND, GIT_MERGE_FILE_MODE)) < 0)
29192919
goto cleanup;
29202920

src/rebase.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int rebase_state_type(
9292
git_buf path = GIT_BUF_INIT;
9393
git_rebase_type_t type = GIT_REBASE_TYPE_NONE;
9494

95-
if (git_buf_joinpath(&path, repo->path_repository, REBASE_APPLY_DIR) < 0)
95+
if (git_buf_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0)
9696
return -1;
9797

9898
if (git_path_isdir(git_buf_cstr(&path))) {
@@ -101,7 +101,7 @@ static int rebase_state_type(
101101
}
102102

103103
git_buf_clear(&path);
104-
if (git_buf_joinpath(&path, repo->path_repository, REBASE_MERGE_DIR) < 0)
104+
if (git_buf_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0)
105105
return -1;
106106

107107
if (git_path_isdir(git_buf_cstr(&path))) {
@@ -624,7 +624,7 @@ static int rebase_init_merge(
624624

625625
GIT_UNUSED(upstream);
626626

627-
if ((error = git_buf_joinpath(&state_path, repo->path_repository, REBASE_MERGE_DIR)) < 0)
627+
if ((error = git_buf_joinpath(&state_path, repo->gitdir, REBASE_MERGE_DIR)) < 0)
628628
goto done;
629629

630630
rebase->state_path = git_buf_detach(&state_path);

src/refdb_fs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,13 +1435,13 @@ static int setup_namespace(git_buf *gitpath, git_repository *repo)
14351435
char *parts, *start, *end;
14361436

14371437
/* Not all repositories have a gitpath */
1438-
if (repo->path_repository == NULL)
1438+
if (repo->gitdir == NULL)
14391439
return 0;
14401440
if (repo->commondir == NULL)
14411441
return 0;
14421442

14431443
/* Load the path to the repo first */
1444-
git_buf_puts(gitpath, repo->path_repository);
1444+
git_buf_puts(gitpath, repo->gitdir);
14451445

14461446
/* if the repo is not namespaced, nothing else to do */
14471447
if (repo->namespace == NULL)
@@ -1877,7 +1877,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
18771877
&normalized, new_name, GIT_REF_FORMAT_ALLOW_ONELEVEL)) < 0)
18781878
return error;
18791879

1880-
if (git_buf_joinpath(&temp_path, repo->path_repository, GIT_REFLOG_DIR) < 0)
1880+
if (git_buf_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
18811881
return -1;
18821882

18831883
if (git_buf_joinpath(&old_path, git_buf_cstr(&temp_path), old_name) < 0)

src/repository.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ void git_repository_free(git_repository *repo)
165165
git_buf_free(git_array_get(repo->reserved_names, i));
166166
git_array_clear(repo->reserved_names);
167167

168-
git__free(repo->path_gitlink);
169-
git__free(repo->path_repository);
168+
git__free(repo->gitlink);
169+
git__free(repo->gitdir);
170170
git__free(repo->commondir);
171171
git__free(repo->workdir);
172172
git__free(repo->namespace);
@@ -288,15 +288,15 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
288288

289289
if (ce && ce->value) {
290290
if ((error = git_path_prettify_dir(
291-
&worktree, ce->value, repo->path_repository)) < 0)
291+
&worktree, ce->value, repo->gitdir)) < 0)
292292
goto cleanup;
293293

294294
repo->workdir = git_buf_detach(&worktree);
295295
}
296296
else if (parent_path && git_path_isdir(parent_path->ptr))
297297
repo->workdir = git_buf_detach(parent_path);
298298
else {
299-
if (git_path_dirname_r(&worktree, repo->path_repository) < 0 ||
299+
if (git_path_dirname_r(&worktree, repo->gitdir) < 0 ||
300300
git_path_to_dir(&worktree) < 0) {
301301
error = -1;
302302
goto cleanup;
@@ -553,8 +553,8 @@ int git_repository_open_bare(
553553
repo = repository_alloc();
554554
GITERR_CHECK_ALLOC(repo);
555555

556-
repo->path_repository = git_buf_detach(&path);
557-
GITERR_CHECK_ALLOC(repo->path_repository);
556+
repo->gitdir = git_buf_detach(&path);
557+
GITERR_CHECK_ALLOC(repo->gitdir);
558558
repo->commondir = git_buf_detach(&common_path);
559559
GITERR_CHECK_ALLOC(repo->commondir);
560560

@@ -763,19 +763,19 @@ int git_repository_open_ext(
763763
repo = repository_alloc();
764764
GITERR_CHECK_ALLOC(repo);
765765

766-
repo->path_repository = git_buf_detach(&path);
767-
GITERR_CHECK_ALLOC(repo->path_repository);
766+
repo->gitdir = git_buf_detach(&path);
767+
GITERR_CHECK_ALLOC(repo->gitdir);
768768

769769
if (link_path.size) {
770-
repo->path_gitlink = git_buf_detach(&link_path);
771-
GITERR_CHECK_ALLOC(repo->path_gitlink);
770+
repo->gitlink = git_buf_detach(&link_path);
771+
GITERR_CHECK_ALLOC(repo->gitlink);
772772
}
773773
if (common_path.size) {
774774
repo->commondir = git_buf_detach(&common_path);
775775
GITERR_CHECK_ALLOC(repo->commondir);
776776
}
777777

778-
if (repo->path_gitlink && repo->commondir && strcmp(repo->path_gitlink, repo->commondir))
778+
if (repo->gitlink && repo->commondir && strcmp(repo->gitlink, repo->commondir))
779779
repo->is_worktree = 1;
780780

781781
/*
@@ -1114,7 +1114,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
11141114
git_buf index_path = GIT_BUF_INIT;
11151115
git_index *index;
11161116

1117-
if ((error = git_buf_joinpath(&index_path, repo->path_repository, GIT_INDEX_FILE)) < 0)
1117+
if ((error = git_buf_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
11181118
return error;
11191119

11201120
error = git_index_open(&index, index_path.ptr);
@@ -1230,13 +1230,13 @@ bool git_repository__reserved_names(
12301230
prefixcmp = (error || ignorecase) ? git__prefixcmp_icase :
12311231
git__prefixcmp;
12321232

1233-
if (repo->path_gitlink &&
1234-
reserved_names_add8dot3(repo, repo->path_gitlink) < 0)
1233+
if (repo->gitlink &&
1234+
reserved_names_add8dot3(repo, repo->gitlink) < 0)
12351235
goto on_error;
12361236

1237-
if (repo->path_repository &&
1238-
prefixcmp(repo->path_repository, repo->workdir) == 0 &&
1239-
reserved_names_add8dot3(repo, repo->path_repository) < 0)
1237+
if (repo->gitdir &&
1238+
prefixcmp(repo->gitdir, repo->workdir) == 0 &&
1239+
reserved_names_add8dot3(repo, repo->gitdir) < 0)
12401240
goto on_error;
12411241
}
12421242
}
@@ -2237,7 +2237,7 @@ int git_repository_item_path(git_buf *out, git_repository *repo, git_repository_
22372237
const char *git_repository_path(git_repository *repo)
22382238
{
22392239
assert(repo);
2240-
return repo->path_repository;
2240+
return repo->gitdir;
22412241
}
22422242

22432243
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
23662366

23672367
git_oid_fmt(orig_head_str, orig_head);
23682368

2369-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_ORIG_HEAD_FILE)) == 0 &&
2369+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
23702370
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_MERGE_FILE_MODE)) == 0 &&
23712371
(error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
23722372
error = git_filebuf_commit(&file);
@@ -2387,7 +2387,7 @@ int git_repository_message(git_buf *out, git_repository *repo)
23872387

23882388
git_buf_sanitize(out);
23892389

2390-
if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
2390+
if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
23912391
return -1;
23922392

23932393
if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
@@ -2408,7 +2408,7 @@ int git_repository_message_remove(git_repository *repo)
24082408
git_buf path = GIT_BUF_INIT;
24092409
int error;
24102410

2411-
if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
2411+
if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
24122412
return -1;
24132413

24142414
error = p_unlink(git_buf_cstr(&path));
@@ -2650,7 +2650,7 @@ int git_repository_state(git_repository *repo)
26502650

26512651
assert(repo);
26522652

2653-
if (git_buf_puts(&repo_path, repo->path_repository) < 0)
2653+
if (git_buf_puts(&repo_path, repo->gitdir) < 0)
26542654
return -1;
26552655

26562656
if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
@@ -2692,7 +2692,7 @@ int git_repository__cleanup_files(
26922692
for (error = 0, i = 0; !error && i < files_len; ++i) {
26932693
const char *path;
26942694

2695-
if (git_buf_joinpath(&buf, repo->path_repository, files[i]) < 0)
2695+
if (git_buf_joinpath(&buf, repo->gitdir, files[i]) < 0)
26962696
return -1;
26972697

26982698
path = git_buf_cstr(&buf);
@@ -2736,7 +2736,7 @@ int git_repository_is_shallow(git_repository *repo)
27362736
struct stat st;
27372737
int error;
27382738

2739-
if ((error = git_buf_joinpath(&path, repo->path_repository, "shallow")) < 0)
2739+
if ((error = git_buf_joinpath(&path, repo->gitdir, "shallow")) < 0)
27402740
return error;
27412741

27422742
error = git_path_lstat(path.ptr, &st);

src/repository.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ struct git_repository {
126126
git_attr_cache *attrcache;
127127
git_diff_driver_registry *diff_drivers;
128128

129-
char *path_repository;
130-
char *path_gitlink;
129+
char *gitlink;
130+
char *gitdir;
131131
char *commondir;
132132
char *workdir;
133133
char *namespace;

src/revert.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int write_revert_head(
2727
git_buf file_path = GIT_BUF_INIT;
2828
int error = 0;
2929

30-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_REVERT_HEAD_FILE)) >= 0 &&
30+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_REVERT_HEAD_FILE)) >= 0 &&
3131
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_REVERT_FILE_MODE)) >= 0 &&
3232
(error = git_filebuf_printf(&file, "%s\n", commit_oidstr)) >= 0)
3333
error = git_filebuf_commit(&file);
@@ -49,7 +49,7 @@ static int write_merge_msg(
4949
git_buf file_path = GIT_BUF_INIT;
5050
int error = 0;
5151

52-
if ((error = git_buf_joinpath(&file_path, repo->path_repository, GIT_MERGE_MSG_FILE)) < 0 ||
52+
if ((error = git_buf_joinpath(&file_path, repo->gitdir, GIT_MERGE_MSG_FILE)) < 0 ||
5353
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_FORCE, GIT_REVERT_FILE_MODE)) < 0 ||
5454
(error = git_filebuf_printf(&file, "Revert \"%s\"\n\nThis reverts commit %s.\n",
5555
commit_msgline, commit_oidstr)) < 0)

tests/worktree/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void test_worktree_merge__merge_setup(void)
7272
for (i = 0; i < ARRAY_SIZE(merge_files); i++) {
7373
git_buf_clear(&path);
7474
cl_git_pass(git_buf_printf(&path, "%s/%s",
75-
fixture.worktree->path_repository, merge_files[i]));
75+
fixture.worktree->gitdir, merge_files[i]));
7676
cl_assert(git_path_exists(path.ptr));
7777
}
7878

tests/worktree/worktree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ void test_worktree_worktree__lookup(void)
117117
git_buf_printf(&gitdir_path, "%s/worktrees/%s", fixture.repo->commondir, "testrepo-worktree");
118118

119119
cl_assert_equal_s(wt->gitdir_path, gitdir_path.ptr);
120-
cl_assert_equal_s(wt->parent_path, fixture.repo->path_repository);
121-
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->path_gitlink);
120+
cl_assert_equal_s(wt->parent_path, fixture.repo->gitdir);
121+
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
122122
cl_assert_equal_s(wt->commondir_path, fixture.repo->commondir);
123123

124124
git_buf_free(&gitdir_path);
@@ -196,7 +196,7 @@ void test_worktree_worktree__open_invalid_parent(void)
196196

197197
cl_git_pass(git_buf_sets(&buf, "/path/to/nonexistent/gitdir"));
198198
cl_git_pass(git_futils_writebuffer(&buf,
199-
fixture.worktree->path_gitlink, O_RDWR, 0644));
199+
fixture.worktree->gitlink, O_RDWR, 0644));
200200

201201
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
202202
cl_git_fail(git_repository_open_from_worktree(&repo, wt));
@@ -254,7 +254,7 @@ void test_worktree_worktree__init_existing_worktree(void)
254254
cl_git_fail(git_worktree_add(&wt, fixture.repo, "testrepo-worktree", path.ptr));
255255

256256
cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree"));
257-
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->path_gitlink);
257+
cl_assert_equal_s(wt->gitlink_path, fixture.worktree->gitlink);
258258

259259
git_buf_free(&path);
260260
git_worktree_free(wt);
@@ -271,7 +271,7 @@ void test_worktree_worktree__init_existing_path(void)
271271
* the init call */
272272
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
273273
cl_git_pass(git_buf_joinpath(&path,
274-
fixture.worktree->path_repository, wtfiles[i]));
274+
fixture.worktree->gitdir, wtfiles[i]));
275275
cl_git_pass(p_unlink(path.ptr));
276276
}
277277

@@ -281,7 +281,7 @@ void test_worktree_worktree__init_existing_path(void)
281281
/* Verify files have not been re-created */
282282
for (i = 0; i < ARRAY_SIZE(wtfiles); i++) {
283283
cl_git_pass(git_buf_joinpath(&path,
284-
fixture.worktree->path_repository, wtfiles[i]));
284+
fixture.worktree->gitdir, wtfiles[i]));
285285
cl_assert(!git_path_exists(path.ptr));
286286
}
287287

0 commit comments

Comments
 (0)