| 340 | } |
| 341 | |
| 342 | static void parse_cmd_symref_update(struct ref_transaction *transaction, |
| 343 | const char *next, const char *end UNUSED, |
| 344 | struct command_options *opts) |
| 345 | { |
| 346 | char *refname, *new_target, *old_arg; |
| 347 | enum ref_transaction_error tx_err; |
| 348 | char *old_target = NULL; |
| 349 | struct strbuf err = STRBUF_INIT; |
| 350 | struct object_id old_oid; |
| 351 | int have_old_oid = 0; |
| 352 | |
| 353 | refname = parse_refname(&next); |
| 354 | if (!refname) |
| 355 | die("symref-update: missing <ref>"); |
| 356 | |
| 357 | new_target = parse_next_refname(&next); |
| 358 | if (!new_target) |
| 359 | die("symref-update %s: missing <new-target>", refname); |
| 360 | |
| 361 | old_arg = parse_next_arg(&next); |
| 362 | if (old_arg) { |
| 363 | old_target = parse_next_arg(&next); |
| 364 | if (!old_target) |
| 365 | die("symref-update %s: expected old value", refname); |
| 366 | |
| 367 | if (!strcmp(old_arg, "oid")) { |
| 368 | if (repo_get_oid_with_flags(the_repository, old_target, &old_oid, |
| 369 | GET_OID_SKIP_AMBIGUITY_CHECK)) |
| 370 | die("symref-update %s: invalid oid: %s", refname, old_target); |
| 371 | |
| 372 | have_old_oid = 1; |
| 373 | } else if (!strcmp(old_arg, "ref")) { |
| 374 | if (check_refname_format(old_target, REFNAME_ALLOW_ONELEVEL)) |
| 375 | die("symref-update %s: invalid ref: %s", refname, old_target); |
| 376 | } else { |
| 377 | die("symref-update %s: invalid arg '%s' for old value", refname, old_arg); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if (*next != line_termination) |
| 382 | die("symref-update %s: extra input: %s", refname, next); |
| 383 | |
| 384 | tx_err = ref_transaction_update(transaction, refname, NULL, |
| 385 | have_old_oid ? &old_oid : NULL, |
| 386 | new_target, |
| 387 | have_old_oid ? NULL : old_target, |
| 388 | update_flags | create_reflog_flag, |
| 389 | msg, &err); |
| 390 | handle_ref_transaction_error(refname, NULL, have_old_oid ? &old_oid : NULL, |
| 391 | new_target, have_old_oid ? NULL : old_target, |
| 392 | tx_err, &err, opts); |
| 393 | |
| 394 | update_flags = default_flags; |
| 395 | free(refname); |
| 396 | free(old_arg); |
| 397 | free(old_target); |
| 398 | free(new_target); |
| 399 | strbuf_release(&err); |
nothing calls this directly
no test coverage detected