MCPcopy Index your code
hub / github.com/git/git / add

Function add

builtin/notes.c:478–576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476 struct repository *repo UNUSED);
477
478static 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) {

Callers

nothing calls this directly

Calls 15

parse_optionsFunction · 0.85
errorFunction · 0.85
usage_with_optionsFunction · 0.85
concat_messagesFunction · 0.85
repo_get_oidFunction · 0.85
init_notes_checkFunction · 0.85
get_noteFunction · 0.85
free_notesFunction · 0.85
free_note_dataFunction · 0.85
oid_to_hexFunction · 0.85
append_editFunction · 0.85
prepare_note_dataFunction · 0.85

Tested by

no test coverage detected