Skip to content

Commit ea09dff

Browse files
committed
Merge branch 'ps/receive-pack-unlock-before-die'
"git receive-pack" that responds to "git push" requests failed to clean a stale lockfile when killed in the middle, which has been corrected. * ps/receive-pack-unlock-before-die: receive-pack: fix stale packfile locks when dying
2 parents 1071dea + c55c306 commit ea09dff

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

builtin/receive-pack.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,7 +2183,7 @@ static const char *parse_pack_header(struct pack_header *hdr)
21832183
}
21842184
}
21852185

2186-
static const char *pack_lockfile;
2186+
static struct tempfile *pack_lockfile;
21872187

21882188
static void push_header_arg(struct strvec *args, struct pack_header *hdr)
21892189
{
@@ -2250,6 +2250,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
22502250
return "unpack-objects abnormal exit";
22512251
} else {
22522252
char hostname[HOST_NAME_MAX + 1];
2253+
char *lockfile;
22532254

22542255
strvec_pushl(&child.args, "index-pack", "--stdin", NULL);
22552256
push_header_arg(&child.args, &hdr);
@@ -2279,8 +2280,14 @@ static const char *unpack(int err_fd, struct shallow_info *si)
22792280
status = start_command(&child);
22802281
if (status)
22812282
return "index-pack fork failed";
2282-
pack_lockfile = index_pack_lockfile(child.out, NULL);
2283+
2284+
lockfile = index_pack_lockfile(child.out, NULL);
2285+
if (lockfile) {
2286+
pack_lockfile = register_tempfile(lockfile);
2287+
free(lockfile);
2288+
}
22832289
close(child.out);
2290+
22842291
status = finish_command(&child);
22852292
if (status)
22862293
return "index-pack abnormal exit";
@@ -2567,8 +2574,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
25672574
use_keepalive = KEEPALIVE_ALWAYS;
25682575
execute_commands(commands, unpack_status, &si,
25692576
&push_options);
2570-
if (pack_lockfile)
2571-
unlink_or_warn(pack_lockfile);
2577+
delete_tempfile(&pack_lockfile);
25722578
sigchain_push(SIGPIPE, SIG_IGN);
25732579
if (report_status_v2)
25742580
report_v2(commands, unpack_status);

0 commit comments

Comments
 (0)