From: Michael Haggerty Date: Mon, 08 Jun 2015 09:07:42 GMT Subject: [PATCH 11/14] lock_repo_for_gc(): compute the path to "gc.pid" only once Message-ID: <532e3a4e4beea4e94f22ac4b11aafa6095763e0b.1433751986.git.mhagger@alum.mit.edu> In-Reply-To: Signed-off-by: Michael Haggerty --- builtin/gc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/gc.c b/builtin/gc.c index 6e18d35..4dc21b2 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -200,6 +200,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) uintmax_t pid; FILE *fp; int fd; + char *pidfile_path; if (pidfile) /* already locked */ @@ -208,12 +209,13 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) if (gethostname(my_host, sizeof(my_host))) strcpy(my_host, "unknown"); - fd = hold_lock_file_for_update(&lock, git_path("gc.pid"), + pidfile_path = git_pathdup("gc.pid"); + fd = hold_lock_file_for_update(&lock, pidfile_path, LOCK_DIE_ON_ERROR); if (!force) { static char locking_host[128]; int should_exit; - fp = fopen(git_path("gc.pid"), "r"); + fp = fopen(pidfile_path, "r"); memset(locking_host, 0, sizeof(locking_host)); should_exit = fp != NULL && @@ -237,6 +239,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) if (fd >= 0) rollback_lock_file(&lock); *ret_pid = pid; + free(pidfile_path); return locking_host; } } @@ -247,7 +250,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) strbuf_release(&sb); commit_lock_file(&lock); - pidfile = git_pathdup("gc.pid"); + pidfile = pidfile_path; sigchain_push_common(remove_pidfile_on_signal); atexit(remove_pidfile); -- 2.1.4