File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 14
14
#include "cache.h"
15
15
#include "parse-options.h"
16
16
#include "run-command.h"
17
+ #include "sigchain.h"
17
18
#include "argv-array.h"
18
19
19
20
#define FAILED_RUN "failed to run %s"
@@ -35,6 +36,21 @@ static struct argv_array repack = ARGV_ARRAY_INIT;
35
36
static struct argv_array prune = ARGV_ARRAY_INIT ;
36
37
static struct argv_array rerere = ARGV_ARRAY_INIT ;
37
38
39
+ static char * pidfile ;
40
+
41
+ static void remove_pidfile (void )
42
+ {
43
+ if (pidfile )
44
+ unlink (pidfile );
45
+ }
46
+
47
+ static void remove_pidfile_on_signal (int signo )
48
+ {
49
+ remove_pidfile ();
50
+ sigchain_pop (signo );
51
+ raise (signo );
52
+ }
53
+
38
54
static int gc_config (const char * var , const char * value , void * cb )
39
55
{
40
56
if (!strcmp (var , "gc.packrefs" )) {
@@ -179,6 +195,10 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
179
195
FILE * fp ;
180
196
int fd , should_exit ;
181
197
198
+ if (pidfile )
199
+ /* already locked */
200
+ return NULL ;
201
+
182
202
if (gethostname (my_host , sizeof (my_host )))
183
203
strcpy (my_host , "unknown" );
184
204
@@ -219,6 +239,10 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
219
239
strbuf_release (& sb );
220
240
commit_lock_file (& lock );
221
241
242
+ pidfile = git_pathdup ("gc.pid" );
243
+ sigchain_push_common (remove_pidfile_on_signal );
244
+ atexit (remove_pidfile );
245
+
222
246
return NULL ;
223
247
}
224
248
Original file line number Diff line number Diff line change @@ -9,6 +9,11 @@ test_expect_success 'gc empty repository' '
9
9
git gc
10
10
'
11
11
12
+ test_expect_success ' gc does not leave behind pid file' '
13
+ git gc &&
14
+ test_path_is_missing .git/gc.pid
15
+ '
16
+
12
17
test_expect_success ' gc --gobbledegook' '
13
18
test_expect_code 129 git gc --nonsense 2>err &&
14
19
test_i18ngrep "[Uu]sage: git gc" err
You can’t perform that action at this time.
0 commit comments