1686
*data->retcode = 1;
1687
}
1688
1689
+/*
1690
+ * Commit the reference transaction. If it isn't an atomic transaction, handle
1691
+ * rejected updates as part of using batched updates.
1692
+ */
1693
+static int commit_ref_transaction(struct ref_transaction **transaction,
1694
+ bool is_atomic, const char *remote_name,
1695
+ struct strbuf *err)
1696
+{
1697
+ int retcode = ref_transaction_commit(*transaction, err);
1698
+ if (retcode)
1699
+ goto out;
1700
+
1701
+ if (!is_atomic) {
1702
+ struct ref_rejection_data data = {
1703
+ .conflict_msg_shown = 0,
1704
+ .remote_name = remote_name,
1705
+ .retcode = &retcode,
1706
+ };
1707
+
1708
+ ref_transaction_for_each_rejected_update(*transaction,
1709
+ ref_transaction_rejection_handler,
1710
+ &data);
1711
+ }
1712
+
1713
+out:
1714
+ ref_transaction_free(*transaction);
1715
+ *transaction = NULL;
1716
+ return retcode;
1717
+}
1718
+
1719
static int do_fetch(struct transport *transport,
1720
struct refspec *rs,
1721
const struct fetch_config *config)
1888
if (retcode)
1889
goto cleanup;
1890
1861
- retcode = ref_transaction_commit(transaction, &err);
1862
- if (retcode) {
1863
- /*
1864
- * Explicitly handle transaction cleanup to avoid
1865
- * aborting an already closed transaction.
1866
- */
1867
- ref_transaction_free(transaction);
1868
- transaction = NULL;
1891
+ retcode = commit_ref_transaction(&transaction, atomic_fetch,
1892
+ transport->remote->name, &err);
1893
+ if (retcode)
1894
goto cleanup;
1870
- }
1871
-
1872
- if (!atomic_fetch) {
1873
- struct ref_rejection_data data = {
1874
- .retcode = &retcode,
1875
- .conflict_msg_shown = 0,
1876
- .remote_name = transport->remote->name,
1877
- };
1878
-
1879
- ref_transaction_for_each_rejected_update(transaction,
1880
- ref_transaction_rejection_handler,
1881
- &data);
1882
- if (retcode) {
1883
- ref_transaction_free(transaction);
1884
- transaction = NULL;
1885
- goto cleanup;
1886
- }
1887
- }
1895
1896
commit_fetch_head(&fetch_head);
1897