Skip to content

Commit 71dd086

Browse files
committed
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.
1 parent 79ab3ef commit 71dd086

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

src/refdb_fs.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ typedef struct refdb_fs_backend {
5555
git_refdb_backend parent;
5656

5757
git_repository *repo;
58-
char *path;
58+
/* path to git directory */
59+
char *gitpath;
5960

6061
git_sortedcache *refcache;
6162
int peeling_mode;
@@ -77,7 +78,7 @@ static int packed_reload(refdb_fs_backend *backend)
7778
git_buf packedrefs = GIT_BUF_INIT;
7879
char *scan, *eof, *eol;
7980

80-
if (!backend->path)
81+
if (!backend->gitpath)
8182
return 0;
8283

8384
error = git_sortedcache_lockandload(backend->refcache, &packedrefs);
@@ -238,7 +239,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
238239
/* if we fail to load the loose reference, assume someone changed
239240
* the filesystem under us and skip it...
240241
*/
241-
if (loose_readbuffer(&ref_file, backend->path, name) < 0) {
242+
if (loose_readbuffer(&ref_file, backend->gitpath, name) < 0) {
242243
giterr_clear();
243244
goto done;
244245
}
@@ -287,7 +288,7 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
287288
return error;
288289
}
289290

290-
file_path = full_path->ptr + strlen(backend->path);
291+
file_path = full_path->ptr + strlen(backend->gitpath);
291292

292293
return loose_lookup_to_packfile(backend, file_path);
293294
}
@@ -303,7 +304,7 @@ static int packed_loadloose(refdb_fs_backend *backend)
303304
int error;
304305
git_buf refs_path = GIT_BUF_INIT;
305306

306-
if (git_buf_joinpath(&refs_path, backend->path, GIT_REFS_DIR) < 0)
307+
if (git_buf_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
307308
return -1;
308309

309310
/*
@@ -331,7 +332,7 @@ static int refdb_fs_backend__exists(
331332
assert(backend);
332333

333334
if ((error = packed_reload(backend)) < 0 ||
334-
(error = git_buf_joinpath(&ref_path, backend->path, ref_name)) < 0)
335+
(error = git_buf_joinpath(&ref_path, backend->gitpath, ref_name)) < 0)
335336
return error;
336337

337338
*exists = git_path_isfile(ref_path.ptr) ||
@@ -373,7 +374,7 @@ static int loose_lookup(
373374
if (out)
374375
*out = NULL;
375376

376-
if ((error = loose_readbuffer(&ref_file, backend->path, ref_name)) < 0)
377+
if ((error = loose_readbuffer(&ref_file, backend->gitpath, ref_name)) < 0)
377378
/* cannot read loose ref file - gah */;
378379
else if (git__prefixcmp(git_buf_cstr(&ref_file), GIT_SYMREF) == 0) {
379380
const char *target;
@@ -484,12 +485,12 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
484485
git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
485486
const git_index_entry *entry = NULL;
486487

487-
if (!backend->path) /* do nothing if no path for loose refs */
488+
if (!backend->gitpath) /* do nothing if no gitpath for loose refs */
488489
return 0;
489490

490491
fsit_opts.flags = backend->iterator_flags;
491492

492-
if ((error = git_buf_printf(&path, "%s/refs", backend->path)) < 0 ||
493+
if ((error = git_buf_printf(&path, "%s/refs", backend->gitpath)) < 0 ||
493494
(error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
494495
git_buf_free(&path);
495496
return error;
@@ -729,10 +730,10 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
729730
/* Remove a possibly existing empty directory hierarchy
730731
* which name would collide with the reference name
731732
*/
732-
if ((error = git_futils_rmdir_r(name, backend->path, GIT_RMDIR_SKIP_NONEMPTY)) < 0)
733+
if ((error = git_futils_rmdir_r(name, backend->gitpath, GIT_RMDIR_SKIP_NONEMPTY)) < 0)
733734
return error;
734735

735-
if (git_buf_joinpath(&ref_path, backend->path, name) < 0)
736+
if (git_buf_joinpath(&ref_path, backend->gitpath, name) < 0)
736737
return -1;
737738

738739
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(
12831284
}
12841285

12851286
/* If a loose reference exists, remove it from the filesystem */
1286-
if (git_buf_joinpath(&loose_path, backend->path, ref_name) < 0)
1287+
if (git_buf_joinpath(&loose_path, backend->gitpath, ref_name) < 0)
12871288
return -1;
12881289

12891290

@@ -1408,20 +1409,20 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
14081409
assert(backend);
14091410

14101411
git_sortedcache_free(backend->refcache);
1411-
git__free(backend->path);
1412+
git__free(backend->gitpath);
14121413
git__free(backend);
14131414
}
14141415

1415-
static int setup_namespace(git_buf *path, git_repository *repo)
1416+
static int setup_namespace(git_buf *gitpath, git_repository *repo)
14161417
{
14171418
char *parts, *start, *end;
14181419

1419-
/* Not all repositories have a path */
1420+
/* Not all repositories have a gitpath */
14201421
if (repo->path_repository == NULL)
14211422
return 0;
14221423

14231424
/* Load the path to the repo first */
1424-
git_buf_puts(path, repo->path_repository);
1425+
git_buf_puts(gitpath, repo->path_repository);
14251426

14261427
/* if the repo is not namespaced, nothing else to do */
14271428
if (repo->namespace == NULL)
@@ -1438,19 +1439,19 @@ static int setup_namespace(git_buf *path, git_repository *repo)
14381439
* refs under refs/namespaces/foo/refs/namespaces/bar/
14391440
*/
14401441
while ((start = git__strsep(&end, "/")) != NULL) {
1441-
git_buf_printf(path, "refs/namespaces/%s/", start);
1442+
git_buf_printf(gitpath, "refs/namespaces/%s/", start);
14421443
}
14431444

1444-
git_buf_printf(path, "refs/namespaces/%s/refs", end);
1445+
git_buf_printf(gitpath, "refs/namespaces/%s/refs", end);
14451446
git__free(parts);
14461447

14471448
/* Make sure that the folder with the namespace exists */
1448-
if (git_futils_mkdir_relative(git_buf_cstr(path), repo->path_repository,
1449+
if (git_futils_mkdir_relative(git_buf_cstr(gitpath), repo->path_repository,
14491450
0777, GIT_MKDIR_PATH, NULL) < 0)
14501451
return -1;
14511452

1452-
/* Return root of the namespaced path, i.e. without the trailing '/refs' */
1453-
git_buf_rtruncate_at_char(path, '/');
1453+
/* Return root of the namespaced gitpath, i.e. without the trailing '/refs' */
1454+
git_buf_rtruncate_at_char(gitpath, '/');
14541455
return 0;
14551456
}
14561457

@@ -1948,26 +1949,26 @@ int git_refdb_backend_fs(
19481949
git_repository *repository)
19491950
{
19501951
int t = 0;
1951-
git_buf path = GIT_BUF_INIT;
1952+
git_buf gitpath = GIT_BUF_INIT;
19521953
refdb_fs_backend *backend;
19531954

19541955
backend = git__calloc(1, sizeof(refdb_fs_backend));
19551956
GITERR_CHECK_ALLOC(backend);
19561957

19571958
backend->repo = repository;
19581959

1959-
if (setup_namespace(&path, repository) < 0)
1960+
if (setup_namespace(&gitpath, repository) < 0)
19601961
goto fail;
19611962

1962-
backend->path = git_buf_detach(&path);
1963+
backend->gitpath = git_buf_detach(&gitpath);
19631964

1964-
if (git_buf_joinpath(&path, backend->path, GIT_PACKEDREFS_FILE) < 0 ||
1965+
if (git_buf_joinpath(&gitpath, backend->gitpath, GIT_PACKEDREFS_FILE) < 0 ||
19651966
git_sortedcache_new(
19661967
&backend->refcache, offsetof(struct packref, name),
1967-
NULL, NULL, packref_cmp, git_buf_cstr(&path)) < 0)
1968+
NULL, NULL, packref_cmp, git_buf_cstr(&gitpath)) < 0)
19681969
goto fail;
19691970

1970-
git_buf_free(&path);
1971+
git_buf_free(&gitpath);
19711972

19721973
if (!git_repository__cvar(&t, backend->repo, GIT_CVAR_IGNORECASE) && t) {
19731974
backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
@@ -1999,8 +2000,8 @@ int git_refdb_backend_fs(
19992000
return 0;
20002001

20012002
fail:
2002-
git_buf_free(&path);
2003-
git__free(backend->path);
2003+
git_buf_free(&gitpath);
2004+
git__free(backend->gitpath);
20042005
git__free(backend);
20052006
return -1;
20062007
}

0 commit comments

Comments
 (0)