| 476 | struct repository *repo UNUSED); |
| 477 | |
| 478 | static int add(int argc, const char **argv, const char *prefix, |
| 479 | struct repository *repo) |
| 480 | { |
| 481 | int force = 0, allow_empty = 0; |
| 482 | const char *object_ref; |
| 483 | struct notes_tree *t; |
| 484 | struct object_id object, new_note; |
| 485 | const struct object_id *note; |
| 486 | struct note_data d = { .buf = STRBUF_INIT, .stripspace = UNSPECIFIED }; |
| 487 | |
| 488 | struct option options[] = { |
| 489 | OPT_CALLBACK_F('m', "message", &d, N_("message"), |
| 490 | N_("note contents as a string"), PARSE_OPT_NONEG, |
| 491 | parse_msg_arg), |
| 492 | OPT_CALLBACK_F('F', "file", &d, N_("file"), |
| 493 | N_("note contents in a file"), PARSE_OPT_NONEG, |
| 494 | parse_file_arg), |
| 495 | OPT_CALLBACK_F('c', "reedit-message", &d, N_("object"), |
| 496 | N_("reuse and edit specified note object"), PARSE_OPT_NONEG, |
| 497 | parse_reedit_arg), |
| 498 | OPT_BOOL('e', "edit", &d.use_editor, |
| 499 | N_("edit note message in editor")), |
| 500 | OPT_CALLBACK_F('C', "reuse-message", &d, N_("object"), |
| 501 | N_("reuse specified note object"), PARSE_OPT_NONEG, |
| 502 | parse_reuse_arg), |
| 503 | OPT_BOOL(0, "allow-empty", &allow_empty, |
| 504 | N_("allow storing empty note")), |
| 505 | OPT__FORCE(&force, N_("replace existing notes"), PARSE_OPT_NOCOMPLETE), |
| 506 | OPT_CALLBACK_F(0, "separator", &separator, |
| 507 | N_("<paragraph-break>"), |
| 508 | N_("insert <paragraph-break> between paragraphs"), |
| 509 | PARSE_OPT_OPTARG, parse_separator_arg), |
| 510 | OPT_BOOL(0, "stripspace", &d.stripspace, |
| 511 | N_("remove unnecessary whitespace")), |
| 512 | OPT_END() |
| 513 | }; |
| 514 | |
| 515 | argc = parse_options(argc, argv, prefix, options, git_notes_add_usage, |
| 516 | PARSE_OPT_KEEP_ARGV0); |
| 517 | |
| 518 | if (2 < argc) { |
| 519 | error(_("too many arguments")); |
| 520 | usage_with_options(git_notes_add_usage, options); |
| 521 | } |
| 522 | |
| 523 | if (d.msg_nr) |
| 524 | concat_messages(&d); |
| 525 | |
| 526 | object_ref = argc > 1 ? argv[1] : "HEAD"; |
| 527 | |
| 528 | if (repo_get_oid(the_repository, object_ref, &object)) |
| 529 | die(_("failed to resolve '%s' as a valid ref."), object_ref); |
| 530 | |
| 531 | t = init_notes_check("add", NOTES_INIT_WRITABLE); |
| 532 | note = get_note(t, &object); |
| 533 | |
| 534 | if (note) { |
| 535 | if (!force) { |
nothing calls this directly
no test coverage detected