Skip to content

Commit 06a0eea

Browse files
committed
Merge branch 'ps/update-ref-batch-flush'
"git update-ref --stdin" failed to flush its output as needed, which potentially led the conversation to a deadlock. * ps/update-ref-batch-flush: t1400: avoid SIGPIPE race condition on fifo update-ref: fix streaming of status updates
2 parents 99c99ed + 7c12007 commit 06a0eea

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

builtin/update-ref.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
302302
strbuf_release(&err);
303303
}
304304

305+
static void report_ok(const char *command)
306+
{
307+
fprintf(stdout, "%s: ok\n", command);
308+
fflush(stdout);
309+
}
310+
305311
static void parse_cmd_option(struct ref_transaction *transaction,
306312
const char *next, const char *end)
307313
{
@@ -317,7 +323,7 @@ static void parse_cmd_start(struct ref_transaction *transaction,
317323
{
318324
if (*next != line_termination)
319325
die("start: extra input: %s", next);
320-
puts("start: ok");
326+
report_ok("start");
321327
}
322328

323329
static void parse_cmd_prepare(struct ref_transaction *transaction,
@@ -328,7 +334,7 @@ static void parse_cmd_prepare(struct ref_transaction *transaction,
328334
die("prepare: extra input: %s", next);
329335
if (ref_transaction_prepare(transaction, &error))
330336
die("prepare: %s", error.buf);
331-
puts("prepare: ok");
337+
report_ok("prepare");
332338
}
333339

334340
static void parse_cmd_abort(struct ref_transaction *transaction,
@@ -339,7 +345,7 @@ static void parse_cmd_abort(struct ref_transaction *transaction,
339345
die("abort: extra input: %s", next);
340346
if (ref_transaction_abort(transaction, &error))
341347
die("abort: %s", error.buf);
342-
puts("abort: ok");
348+
report_ok("abort");
343349
}
344350

345351
static void parse_cmd_commit(struct ref_transaction *transaction,
@@ -350,7 +356,7 @@ static void parse_cmd_commit(struct ref_transaction *transaction,
350356
die("commit: extra input: %s", next);
351357
if (ref_transaction_commit(transaction, &error))
352358
die("commit: %s", error.buf);
353-
puts("commit: ok");
359+
report_ok("commit");
354360
ref_transaction_free(transaction);
355361
}
356362

t/t1400-update-ref.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,40 @@ test_expect_success 'transaction cannot restart ongoing transaction' '
15981598
test_must_fail git show-ref --verify refs/heads/restart
15991599
'
16001600

1601+
test_expect_success PIPE 'transaction flushes status updates' '
1602+
mkfifo in out &&
1603+
(git update-ref --stdin <in >out &) &&
1604+
1605+
exec 9>in &&
1606+
exec 8<out &&
1607+
test_when_finished "exec 9>&-" &&
1608+
test_when_finished "exec 8<&-" &&
1609+
1610+
echo "start" >&9 &&
1611+
echo "start: ok" >expected &&
1612+
read line <&8 &&
1613+
echo "$line" >actual &&
1614+
test_cmp expected actual &&
1615+
1616+
echo "create refs/heads/flush $A" >&9 &&
1617+
1618+
echo prepare >&9 &&
1619+
echo "prepare: ok" >expected &&
1620+
read line <&8 &&
1621+
echo "$line" >actual &&
1622+
test_cmp expected actual &&
1623+
1624+
# This must now fail given that we have locked the ref.
1625+
test_must_fail git update-ref refs/heads/flush $B 2>stderr &&
1626+
grep "fatal: update_ref failed for ref ${SQ}refs/heads/flush${SQ}: cannot lock ref" stderr &&
1627+
1628+
echo commit >&9 &&
1629+
echo "commit: ok" >expected &&
1630+
read line <&8 &&
1631+
echo "$line" >actual &&
1632+
test_cmp expected actual
1633+
'
1634+
16011635
test_expect_success 'directory not created deleting packed ref' '
16021636
git branch d1/d2/r1 HEAD &&
16031637
git pack-refs --all &&

0 commit comments

Comments
 (0)