| 1143 | } |
| 1144 | |
| 1145 | static void append_fetch_head(struct fetch_head *fetch_head, |
| 1146 | const struct object_id *old_oid, |
| 1147 | enum fetch_head_status fetch_head_status, |
| 1148 | const char *note, |
| 1149 | const char *url, size_t url_len) |
| 1150 | { |
| 1151 | char old_oid_hex[GIT_MAX_HEXSZ + 1]; |
| 1152 | const char *merge_status_marker; |
| 1153 | size_t i; |
| 1154 | |
| 1155 | if (!fetch_head->fp) |
| 1156 | return; |
| 1157 | |
| 1158 | switch (fetch_head_status) { |
| 1159 | case FETCH_HEAD_NOT_FOR_MERGE: |
| 1160 | merge_status_marker = "not-for-merge"; |
| 1161 | break; |
| 1162 | case FETCH_HEAD_MERGE: |
| 1163 | merge_status_marker = ""; |
| 1164 | break; |
| 1165 | default: |
| 1166 | /* do not write anything to FETCH_HEAD */ |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | strbuf_addf(&fetch_head->buf, "%s\t%s\t%s", |
| 1171 | oid_to_hex_r(old_oid_hex, old_oid), merge_status_marker, note); |
| 1172 | for (i = 0; i < url_len; ++i) |
| 1173 | if ('\n' == url[i]) |
| 1174 | strbuf_addstr(&fetch_head->buf, "\\n"); |
| 1175 | else |
| 1176 | strbuf_addch(&fetch_head->buf, url[i]); |
| 1177 | strbuf_addch(&fetch_head->buf, '\n'); |
| 1178 | |
| 1179 | /* |
| 1180 | * When using an atomic fetch, we do not want to update FETCH_HEAD if |
| 1181 | * any of the reference updates fails. We thus have to write all |
| 1182 | * updates to a buffer first and only commit it as soon as all |
| 1183 | * references have been successfully updated. |
| 1184 | */ |
| 1185 | if (!atomic_fetch) { |
| 1186 | strbuf_write(&fetch_head->buf, fetch_head->fp); |
| 1187 | strbuf_reset(&fetch_head->buf); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | static void commit_fetch_head(struct fetch_head *fetch_head) |
| 1192 | { |
no test coverage detected