summaryrefslogtreecommitdiff
path: root/builtin/gc.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2015-08-10 09:47:48 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-08-12 21:50:11 (GMT)
commit00539cef390dc860d9eda399dc99d14f6f258a5b (patch)
treecb3ffeeaf3ed9b6a14ed266a2c66fe5dbb21a4ef /builtin/gc.c
parent284098f13fd1c378883ed844fc2966e0b78bbbe7 (diff)
downloadgit-00539cef390dc860d9eda399dc99d14f6f258a5b.zip
git-00539cef390dc860d9eda399dc99d14f6f258a5b.tar.gz
git-00539cef390dc860d9eda399dc99d14f6f258a5b.tar.bz2
lock_repo_for_gc(): compute the path to "gc.pid" only once
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/gc.c')
-rw-r--r--builtin/gc.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 36fe333..c41354b 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -199,6 +199,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 */
@@ -207,12 +208,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 &&
@@ -236,6 +238,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;
}
}
@@ -246,7 +249,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);