| 1257 | } |
| 1258 | |
| 1259 | int update_head_with_reflog(const struct commit *old_head, |
| 1260 | const struct object_id *new_head, |
| 1261 | const char *action, const struct strbuf *msg, |
| 1262 | struct strbuf *err) |
| 1263 | { |
| 1264 | struct ref_transaction *transaction; |
| 1265 | struct strbuf sb = STRBUF_INIT; |
| 1266 | const char *nl; |
| 1267 | int ret = 0; |
| 1268 | |
| 1269 | if (action) { |
| 1270 | strbuf_addstr(&sb, action); |
| 1271 | strbuf_addstr(&sb, ": "); |
| 1272 | } |
| 1273 | |
| 1274 | nl = strchr(msg->buf, '\n'); |
| 1275 | if (nl) { |
| 1276 | strbuf_add(&sb, msg->buf, nl + 1 - msg->buf); |
| 1277 | } else { |
| 1278 | strbuf_addbuf(&sb, msg); |
| 1279 | strbuf_addch(&sb, '\n'); |
| 1280 | } |
| 1281 | |
| 1282 | transaction = ref_store_transaction_begin(get_main_ref_store(the_repository), |
| 1283 | 0, err); |
| 1284 | if (!transaction || |
| 1285 | ref_transaction_update(transaction, "HEAD", new_head, |
| 1286 | old_head ? &old_head->object.oid : null_oid(the_hash_algo), |
| 1287 | NULL, NULL, 0, sb.buf, err) || |
| 1288 | ref_transaction_commit(transaction, err)) { |
| 1289 | ret = -1; |
| 1290 | } |
| 1291 | ref_transaction_free(transaction); |
| 1292 | strbuf_release(&sb); |
| 1293 | |
| 1294 | return ret; |
| 1295 | } |
| 1296 | |
| 1297 | static int pipe_from_strbuf(int hook_stdin_fd, void *pp_cb, void *pp_task_cb UNUSED) |
| 1298 | { |
no test coverage detected