| 1304 | } |
| 1305 | |
| 1306 | struct ref_update *ref_transaction_add_update( |
| 1307 | struct ref_transaction *transaction, |
| 1308 | const char *refname, unsigned int flags, |
| 1309 | const struct object_id *new_oid, |
| 1310 | const struct object_id *old_oid, |
| 1311 | const struct object_id *peeled, |
| 1312 | const char *new_target, const char *old_target, |
| 1313 | const char *committer_info, |
| 1314 | const char *msg) |
| 1315 | { |
| 1316 | struct string_list_item *item; |
| 1317 | struct ref_update *update; |
| 1318 | |
| 1319 | if (transaction->state != REF_TRANSACTION_OPEN) |
| 1320 | BUG("update called for transaction that is not open"); |
| 1321 | |
| 1322 | if (old_oid && old_target) |
| 1323 | BUG("only one of old_oid and old_target should be non NULL"); |
| 1324 | if (new_oid && new_target) |
| 1325 | BUG("only one of new_oid and new_target should be non NULL"); |
| 1326 | |
| 1327 | FLEX_ALLOC_STR(update, refname, refname); |
| 1328 | ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc); |
| 1329 | transaction->updates[transaction->nr++] = update; |
| 1330 | |
| 1331 | update->flags = flags; |
| 1332 | update->rejection_err = 0; |
| 1333 | |
| 1334 | update->new_target = xstrdup_or_null(new_target); |
| 1335 | update->old_target = xstrdup_or_null(old_target); |
| 1336 | if ((flags & REF_HAVE_NEW) && new_oid) |
| 1337 | oidcpy(&update->new_oid, new_oid); |
| 1338 | if ((flags & REF_HAVE_OLD) && old_oid) |
| 1339 | oidcpy(&update->old_oid, old_oid); |
| 1340 | if (!(flags & REF_SKIP_CREATE_REFLOG)) { |
| 1341 | update->committer_info = xstrdup_or_null(committer_info); |
| 1342 | update->msg = normalize_reflog_message(msg); |
| 1343 | } |
| 1344 | if (flags & REF_HAVE_PEELED) |
| 1345 | oidcpy(&update->peeled, peeled); |
| 1346 | |
| 1347 | /* |
| 1348 | * This list is generally used by the backends to avoid duplicates. |
| 1349 | * But we do support multiple log updates for a given refname within |
| 1350 | * a single transaction. |
| 1351 | */ |
| 1352 | if (!(update->flags & REF_LOG_ONLY)) { |
| 1353 | item = string_list_append(&transaction->refnames, refname); |
| 1354 | item->util = update; |
| 1355 | } |
| 1356 | |
| 1357 | return update; |
| 1358 | } |
| 1359 | |
| 1360 | static int transaction_refname_valid(const char *refname, |
| 1361 | const struct object_id *new_oid, |
no test coverage detected