aboutsummaryrefslogtreecommitdiffstats
path: root/builtin/gc.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-03-05 10:37:43 -0800
committerJunio C Hamano <gitster@pobox.com>2025-03-05 10:37:43 -0800
commitfeffb34257ee8eef18cc6a3a5a4f01d40720bda1 (patch)
tree02842b3ce862be72ad6a0ace18aca0fa1a4f1ca7 /builtin/gc.c
parent6a64ac7b014fa2cfa7a69af3c253bcd53a94b428 (diff)
parent028f618658e34230e1d65678f14b6876e0f9856d (diff)
downloadgit-feffb34257ee8eef18cc6a3a5a4f01d40720bda1.tar.gz
Merge branch 'ps/path-sans-the-repository'
The path.[ch] API takes an explicit repository parameter passed throughout the callchain, instead of relying on the_repository singleton instance. * ps/path-sans-the-repository: path: adjust last remaining users of `the_repository` environment: move access to "core.sharedRepository" into repo settings environment: move access to "core.hooksPath" into repo settings repo-settings: introduce function to clear struct path: drop `git_path()` in favor of `repo_git_path()` rerere: let `rerere_path()` write paths into a caller-provided buffer path: drop `git_common_path()` in favor of `repo_common_path()` worktree: return allocated string from `get_worktree_git_dir()` path: drop `git_path_buf()` in favor of `repo_git_path_replace()` path: drop `git_pathdup()` in favor of `repo_git_path()` path: drop unused `strbuf_git_path()` function path: refactor `repo_submodule_path()` family of functions submodule: refactor `submodule_to_gitdir()` to accept a repo path: refactor `repo_worktree_path()` family of functions path: refactor `repo_git_path()` family of functions path: refactor `repo_common_path()` family of functions
Diffstat (limited to 'builtin/gc.c')
-rw-r--r--builtin/gc.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 409d454a4b..99431fd467 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -99,9 +99,11 @@ static void process_log_file(void)
/* There was some error recorded in the lock file */
commit_lock_file(&log_lock);
} else {
+ char *path = repo_git_path(the_repository, "gc.log");
/* No error, clean up any old gc.log */
- unlink(git_path("gc.log"));
+ unlink(path);
rollback_lock_file(&log_lock);
+ free(path);
}
}
@@ -300,8 +302,11 @@ static int too_many_loose_objects(struct gc_config *cfg)
int num_loose = 0;
int needed = 0;
const unsigned hexsz_loose = the_hash_algo->hexsz - 2;
+ char *path;
- dir = opendir(git_path("objects/17"));
+ path = repo_git_path(the_repository, "objects/17");
+ dir = opendir(path);
+ free(path);
if (!dir)
return 0;
@@ -550,7 +555,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
if (xgethostname(my_host, sizeof(my_host)))
xsnprintf(my_host, sizeof(my_host), "unknown");
- pidfile_path = git_pathdup("gc.pid");
+ pidfile_path = repo_git_path(the_repository, "gc.pid");
fd = hold_lock_file_for_update(&lock, pidfile_path,
LOCK_DIE_ON_ERROR);
if (!force) {
@@ -611,7 +616,7 @@ static int report_last_gc_error(void)
int ret = 0;
ssize_t len;
struct stat st;
- char *gc_log_path = git_pathdup("gc.log");
+ char *gc_log_path = repo_git_path(the_repository, "gc.log");
if (stat(gc_log_path, &st)) {
if (errno == ENOENT)
@@ -826,11 +831,12 @@ struct repository *repo UNUSED)
}
if (daemonized) {
- hold_lock_file_for_update(&log_lock,
- git_path("gc.log"),
+ char *path = repo_git_path(the_repository, "gc.log");
+ hold_lock_file_for_update(&log_lock, path,
LOCK_DIE_ON_ERROR);
dup2(get_lock_file_fd(&log_lock), 2);
atexit(process_log_file_at_exit);
+ free(path);
}
gc_before_repack(&opts, &cfg);
@@ -892,8 +898,11 @@ struct repository *repo UNUSED)
warning(_("There are too many unreachable loose objects; "
"run 'git prune' to remove them."));
- if (!daemonized)
- unlink(git_path("gc.log"));
+ if (!daemonized) {
+ char *path = repo_git_path(the_repository, "gc.log");
+ unlink(path);
+ free(path);
+ }
out:
gc_config_release(&cfg);