Skip to content

Commit 18ce489

Browse files
jiangxingitster
authored andcommitted
fetch: no redundant error message for atomic fetch
If an error occurs during an atomic fetch, a redundant error message will appear at the end of do_fetch(). It was introduced in b3a8046 (fetch: make `--atomic` flag cover backfilling of tags, 2022-02-17). Because a failure message is displayed before setting retcode in the function do_fetch(), calling error() on the err message at the end of this function may result in redundant or empty error message to be displayed. We can remove the redundant error() function, because we know that the function ref_transaction_abort() never fails. While we can find a common pattern for calling ref_transaction_abort() by running command "git grep -A1 ref_transaction_abort", e.g.: if (ref_transaction_abort(transaction, &error)) error("abort: %s", error.buf); Following this pattern, we can tolerate the return value of the function ref_transaction_abort() being changed in the future. We also delay the output of the err message to the end of do_fetch() to reduce redundant code. With these changes, the test case "fetch porcelain output (atomic)" in t5574 will also be fixed. Helped-by: Patrick Steinhardt <[email protected]> Signed-off-by: Jiang Xin <[email protected]> Acked-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 97d82b2 commit 18ce489

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

builtin/fetch.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ static int do_fetch(struct transport *transport,
16511651
if (atomic_fetch) {
16521652
transaction = ref_transaction_begin(&err);
16531653
if (!transaction) {
1654-
retcode = error("%s", err.buf);
1654+
retcode = -1;
16551655
goto cleanup;
16561656
}
16571657
}
@@ -1711,7 +1711,6 @@ static int do_fetch(struct transport *transport,
17111711

17121712
retcode = ref_transaction_commit(transaction, &err);
17131713
if (retcode) {
1714-
error("%s", err.buf);
17151714
ref_transaction_free(transaction);
17161715
transaction = NULL;
17171716
goto cleanup;
@@ -1775,9 +1774,14 @@ static int do_fetch(struct transport *transport,
17751774
}
17761775

17771776
cleanup:
1778-
if (retcode && transaction) {
1779-
ref_transaction_abort(transaction, &err);
1780-
error("%s", err.buf);
1777+
if (retcode) {
1778+
if (err.len) {
1779+
error("%s", err.buf);
1780+
strbuf_reset(&err);
1781+
}
1782+
if (transaction && ref_transaction_abort(transaction, &err) &&
1783+
err.len)
1784+
error("%s", err.buf);
17811785
}
17821786

17831787
display_state_release(&display_state);

t/t5574-fetch-output.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ test_expect_success 'setup for fetch porcelain output' '
9090

9191
for opt in "" "--atomic"
9292
do
93-
test_expect_failure "fetch porcelain output ${opt:+(atomic)}" '
93+
test_expect_success "fetch porcelain output ${opt:+(atomic)}" '
9494
test_when_finished "rm -rf porcelain" &&
9595
9696
# Clone and pre-seed the repositories. We fetch references into two

0 commit comments

Comments
 (0)