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>
Michael Haggerty committed
Aug 10, 2015 at 11:47 UTC
00539cef390dc860d9eda399dc99d14f6f258a5b
1 file changed
+6
-3
builtin/gc.c
+6
-3
@@ -199,6 +199,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
199
uintmax_t pid;
200
FILE *fp;
201
int fd;
202
+ char *pidfile_path;
203
204
if (pidfile)
205
/* already locked */
@@ -207,12 +208,13 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
208
if (gethostname(my_host, sizeof(my_host)))
209
strcpy(my_host, "unknown");
210
210
- fd = hold_lock_file_for_update(&lock, git_path("gc.pid"),
211
+ pidfile_path = git_pathdup("gc.pid");
212
+ fd = hold_lock_file_for_update(&lock, pidfile_path,
213
LOCK_DIE_ON_ERROR);
214
if (!force) {
215
static char locking_host[128];
216
int should_exit;
215
- fp = fopen(git_path("gc.pid"), "r");
217
+ fp = fopen(pidfile_path, "r");
218
memset(locking_host, 0, sizeof(locking_host));
219
should_exit =
220
fp != NULL &&
@@ -236,6 +238,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
238
if (fd >= 0)
239
rollback_lock_file(&lock);
240
*ret_pid = pid;
241
+ free(pidfile_path);
242
return locking_host;
243
}
244
}
@@ -246,7 +249,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
249
strbuf_release(&sb);
250
commit_lock_file(&lock);
251
249
- pidfile = git_pathdup("gc.pid");
252
+ pidfile = pidfile_path;
253
sigchain_push_common(remove_pidfile_on_signal);
254
atexit(remove_pidfile);
255