Skip to content

Commit 3284197

Browse files
committed
repository: improve parameter names for find_repo
The out-parameters of `find_repo` containing found paths of a repository are a tad confusing, as they are not as obvious as they could be. Rename them like following to ease reading the code: - `repo_path` -> `gitdir_path` - `parent_path` -> `workdir_path` - `link_path` -> `gitlink_path` - `common_path` -> `commondir_path`
1 parent 57121a2 commit 3284197

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

src/repository.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
422422
}
423423

424424
static int find_repo(
425-
git_buf *repo_path,
426-
git_buf *parent_path,
427-
git_buf *link_path,
428-
git_buf *common_path,
425+
git_buf *gitdir_path,
426+
git_buf *workdir_path,
427+
git_buf *gitlink_path,
428+
git_buf *commondir_path,
429429
const char *start_path,
430430
uint32_t flags,
431431
const char *ceiling_dirs)
@@ -440,7 +440,7 @@ static int find_repo(
440440
bool in_dot_git;
441441
size_t ceiling_offset = 0;
442442

443-
git_buf_clear(repo_path);
443+
git_buf_clear(gitdir_path);
444444

445445
error = git_path_prettify(&path, start_path, NULL);
446446
if (error < 0)
@@ -482,13 +482,13 @@ static int find_repo(
482482
if (S_ISDIR(st.st_mode)) {
483483
if (valid_repository_path(&path, &common_link)) {
484484
git_path_to_dir(&path);
485-
git_buf_set(repo_path, path.ptr, path.size);
485+
git_buf_set(gitdir_path, path.ptr, path.size);
486486

487-
if (link_path)
488-
git_buf_attach(link_path,
487+
if (gitlink_path)
488+
git_buf_attach(gitlink_path,
489489
git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0);
490-
if (common_path)
491-
git_buf_swap(&common_link, common_path);
490+
if (commondir_path)
491+
git_buf_swap(&common_link, commondir_path);
492492

493493
break;
494494
}
@@ -498,12 +498,12 @@ static int find_repo(
498498
if (error < 0)
499499
break;
500500
if (valid_repository_path(&repo_link, &common_link)) {
501-
git_buf_swap(repo_path, &repo_link);
501+
git_buf_swap(gitdir_path, &repo_link);
502502

503-
if (link_path)
504-
error = git_buf_put(link_path, path.ptr, path.size);
505-
if (common_path)
506-
git_buf_swap(&common_link, common_path);
503+
if (gitlink_path)
504+
error = git_buf_put(gitlink_path, path.ptr, path.size);
505+
if (commondir_path)
506+
git_buf_swap(&common_link, commondir_path);
507507
}
508508
break;
509509
}
@@ -529,20 +529,20 @@ static int find_repo(
529529
break;
530530
}
531531

532-
if (!error && parent_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
533-
if (!git_buf_len(repo_path))
534-
git_buf_clear(parent_path);
532+
if (!error && workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
533+
if (!git_buf_len(gitdir_path))
534+
git_buf_clear(workdir_path);
535535
else {
536-
git_path_dirname_r(parent_path, path.ptr);
537-
git_path_to_dir(parent_path);
536+
git_path_dirname_r(workdir_path, path.ptr);
537+
git_path_to_dir(workdir_path);
538538
}
539-
if (git_buf_oom(parent_path))
539+
if (git_buf_oom(workdir_path))
540540
return -1;
541541
}
542542

543543
/* If we didn't find the repository, and we don't have any other error
544544
* to report, report that. */
545-
if (!git_buf_len(repo_path) && !error) {
545+
if (!git_buf_len(gitdir_path) && !error) {
546546
giterr_set(GITERR_REPOSITORY,
547547
"could not find repository from '%s'", start_path);
548548
error = GIT_ENOTFOUND;
@@ -765,8 +765,8 @@ int git_repository_open_ext(
765765
const char *ceiling_dirs)
766766
{
767767
int error;
768-
git_buf path = GIT_BUF_INIT, parent = GIT_BUF_INIT,
769-
link_path = GIT_BUF_INIT, common_path = GIT_BUF_INIT;
768+
git_buf gitdir = GIT_BUF_INIT, workdir = GIT_BUF_INIT,
769+
gitlink = GIT_BUF_INIT, commondir = GIT_BUF_INIT;
770770
git_repository *repo;
771771
git_config *config = NULL;
772772

@@ -777,31 +777,31 @@ int git_repository_open_ext(
777777
*repo_ptr = NULL;
778778

779779
error = find_repo(
780-
&path, &parent, &link_path, &common_path, start_path, flags, ceiling_dirs);
780+
&gitdir, &workdir, &gitlink, &commondir, start_path, flags, ceiling_dirs);
781781

782782
if (error < 0 || !repo_ptr)
783783
return error;
784784

785785
repo = repository_alloc();
786786
GITERR_CHECK_ALLOC(repo);
787787

788-
repo->gitdir = git_buf_detach(&path);
788+
repo->gitdir = git_buf_detach(&gitdir);
789789
GITERR_CHECK_ALLOC(repo->gitdir);
790790

791-
if (link_path.size) {
792-
repo->gitlink = git_buf_detach(&link_path);
791+
if (gitlink.size) {
792+
repo->gitlink = git_buf_detach(&gitlink);
793793
GITERR_CHECK_ALLOC(repo->gitlink);
794794
}
795-
if (common_path.size) {
796-
repo->commondir = git_buf_detach(&common_path);
795+
if (commondir.size) {
796+
repo->commondir = git_buf_detach(&commondir);
797797
GITERR_CHECK_ALLOC(repo->commondir);
798798
}
799799

800-
if ((error = git_buf_joinpath(&path, repo->gitdir, "gitdir")) < 0)
800+
if ((error = git_buf_joinpath(&gitdir, repo->gitdir, "gitdir")) < 0)
801801
goto cleanup;
802802
/* A 'gitdir' file inside a git directory is currently
803803
* only used when the repository is a working tree. */
804-
if (git_path_exists(path.ptr))
804+
if (git_path_exists(gitdir.ptr))
805805
repo->is_worktree = 1;
806806

807807
/*
@@ -822,13 +822,13 @@ int git_repository_open_ext(
822822

823823
if (config &&
824824
((error = load_config_data(repo, config)) < 0 ||
825-
(error = load_workdir(repo, config, &parent)) < 0))
825+
(error = load_workdir(repo, config, &workdir)) < 0))
826826
goto cleanup;
827827
}
828828

829829
cleanup:
830-
git_buf_free(&path);
831-
git_buf_free(&parent);
830+
git_buf_free(&gitdir);
831+
git_buf_free(&workdir);
832832
git_config_free(config);
833833

834834
if (error < 0)

0 commit comments

Comments
 (0)