]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/notes.c
Merge branch 'en/ort-perf-batch-9'
[thirdparty/git.git] / builtin / notes.c
index c05cd004abcbdcd1e4c3d140f3cf4251c416df36..74bba39ca8293208d3d577a47e2617a11d856c20 100644 (file)
@@ -215,6 +215,8 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
 {
        struct note_data *d = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        strbuf_grow(&d->buf, strlen(arg) + 2);
        if (d->buf.len)
                strbuf_addch(&d->buf, '\n');
@@ -229,6 +231,8 @@ static int parse_file_arg(const struct option *opt, const char *arg, int unset)
 {
        struct note_data *d = opt->value;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (d->buf.len)
                strbuf_addch(&d->buf, '\n');
        if (!strcmp(arg, "-")) {
@@ -250,15 +254,15 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
        enum object_type type;
        unsigned long len;
 
+       BUG_ON_OPT_NEG(unset);
+
        if (d->buf.len)
                strbuf_addch(&d->buf, '\n');
 
        if (get_oid(arg, &object))
                die(_("failed to resolve '%s' as a valid ref."), arg);
-       if (!(buf = read_object_file(&object, &type, &len))) {
-               free(buf);
+       if (!(buf = read_object_file(&object, &type, &len)))
                die(_("failed to read object '%s'."), arg);
-       }
        if (type != OBJ_BLOB) {
                free(buf);
                die(_("cannot read note data from non-blob object '%s'."), arg);
@@ -273,6 +277,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
 static int parse_reedit_arg(const struct option *opt, const char *arg, int unset)
 {
        struct note_data *d = opt->value;
+       BUG_ON_OPT_NEG(unset);
        d->use_editor = 1;
        return parse_reuse_arg(opt, arg, unset);
 }
@@ -325,10 +330,10 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
        }
 
        if (!rewrite_cmd) {
-               commit_notes(t, msg);
+               commit_notes(the_repository, t, msg);
                free_notes(t);
        } else {
-               finish_copy_notes_for_rewrite(c, msg);
+               finish_copy_notes_for_rewrite(the_repository, c, msg);
        }
        strbuf_release(&buf);
        return ret;
@@ -368,7 +373,7 @@ static int list(int argc, const char **argv, const char *prefix)
                                     git_notes_list_usage, 0);
 
        if (1 < argc) {
-               error(_("too many parameters"));
+               error(_("too many arguments"));
                usage_with_options(git_notes_list_usage, options);
        }
 
@@ -401,18 +406,18 @@ static int add(int argc, const char **argv, const char *prefix)
        const struct object_id *note;
        struct note_data d = { 0, 0, NULL, STRBUF_INIT };
        struct option options[] = {
-               { OPTION_CALLBACK, 'm', "message", &d, N_("message"),
+               OPT_CALLBACK_F('m', "message", &d, N_("message"),
                        N_("note contents as a string"), PARSE_OPT_NONEG,
-                       parse_msg_arg},
-               { OPTION_CALLBACK, 'F', "file", &d, N_("file"),
+                       parse_msg_arg),
+               OPT_CALLBACK_F('F', "file", &d, N_("file"),
                        N_("note contents in a file"), PARSE_OPT_NONEG,
-                       parse_file_arg},
-               { OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"),
+                       parse_file_arg),
+               OPT_CALLBACK_F('c', "reedit-message", &d, N_("object"),
                        N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
-                       parse_reedit_arg},
-               { OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"),
+                       parse_reedit_arg),
+               OPT_CALLBACK_F('C', "reuse-message", &d, N_("object"),
                        N_("reuse specified note object"), PARSE_OPT_NONEG,
-                       parse_reuse_arg},
+                       parse_reuse_arg),
                OPT_BOOL(0, "allow-empty", &allow_empty,
                        N_("allow storing empty note")),
                OPT__FORCE(&force, N_("replace existing notes"), PARSE_OPT_NOCOMPLETE),
@@ -423,7 +428,7 @@ static int add(int argc, const char **argv, const char *prefix)
                             PARSE_OPT_KEEP_ARGV0);
 
        if (2 < argc) {
-               error(_("too many parameters"));
+               error(_("too many arguments"));
                usage_with_options(git_notes_add_usage, options);
        }
 
@@ -464,12 +469,14 @@ static int add(int argc, const char **argv, const char *prefix)
                write_note_data(&d, &new_note);
                if (add_note(t, &object, &new_note, combine_notes_overwrite))
                        BUG("combine_notes_overwrite failed");
-               commit_notes(t, "Notes added by 'git notes add'");
+               commit_notes(the_repository, t,
+                            "Notes added by 'git notes add'");
        } else {
                fprintf(stderr, _("Removing note for object %s\n"),
                        oid_to_hex(&object));
                remove_note(t, object.hash);
-               commit_notes(t, "Notes removed by 'git notes add'");
+               commit_notes(the_repository, t,
+                            "Notes removed by 'git notes add'");
        }
 
        free_note_data(&d);
@@ -499,19 +506,19 @@ static int copy(int argc, const char **argv, const char *prefix)
 
        if (from_stdin || rewrite_cmd) {
                if (argc) {
-                       error(_("too many parameters"));
+                       error(_("too many arguments"));
                        usage_with_options(git_notes_copy_usage, options);
                } else {
                        return notes_copy_from_stdin(force, rewrite_cmd);
                }
        }
 
-       if (argc < 2) {
-               error(_("too few parameters"));
+       if (argc < 1) {
+               error(_("too few arguments"));
                usage_with_options(git_notes_copy_usage, options);
        }
        if (2 < argc) {
-               error(_("too many parameters"));
+               error(_("too many arguments"));
                usage_with_options(git_notes_copy_usage, options);
        }
 
@@ -547,7 +554,8 @@ static int copy(int argc, const char **argv, const char *prefix)
 
        if (add_note(t, &object, from_note, combine_notes_overwrite))
                BUG("combine_notes_overwrite failed");
-       commit_notes(t, "Notes added by 'git notes copy'");
+       commit_notes(the_repository, t,
+                    "Notes added by 'git notes copy'");
 out:
        free_notes(t);
        return retval;
@@ -564,18 +572,18 @@ static int append_edit(int argc, const char **argv, const char *prefix)
        const char * const *usage;
        struct note_data d = { 0, 0, NULL, STRBUF_INIT };
        struct option options[] = {
-               { OPTION_CALLBACK, 'm', "message", &d, N_("message"),
+               OPT_CALLBACK_F('m', "message", &d, N_("message"),
                        N_("note contents as a string"), PARSE_OPT_NONEG,
-                       parse_msg_arg},
-               { OPTION_CALLBACK, 'F', "file", &d, N_("file"),
+                       parse_msg_arg),
+               OPT_CALLBACK_F('F', "file", &d, N_("file"),
                        N_("note contents in a file"), PARSE_OPT_NONEG,
-                       parse_file_arg},
-               { OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"),
+                       parse_file_arg),
+               OPT_CALLBACK_F('c', "reedit-message", &d, N_("object"),
                        N_("reuse and edit specified note object"), PARSE_OPT_NONEG,
-                       parse_reedit_arg},
-               { OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"),
+                       parse_reedit_arg),
+               OPT_CALLBACK_F('C', "reuse-message", &d, N_("object"),
                        N_("reuse specified note object"), PARSE_OPT_NONEG,
-                       parse_reuse_arg},
+                       parse_reuse_arg),
                OPT_BOOL(0, "allow-empty", &allow_empty,
                        N_("allow storing empty note")),
                OPT_END()
@@ -587,7 +595,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
                             PARSE_OPT_KEEP_ARGV0);
 
        if (2 < argc) {
-               error(_("too many parameters"));
+               error(_("too many arguments"));
                usage_with_options(usage, options);
        }
 
@@ -614,7 +622,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
 
                strbuf_grow(&d.buf, size + 1);
                if (d.buf.len && prev_buf && size)
-                       strbuf_insert(&d.buf, 0, "\n", 1);
+                       strbuf_insertstr(&d.buf, 0, "\n");
                if (prev_buf && size)
                        strbuf_insert(&d.buf, 0, prev_buf, size);
                free(prev_buf);
@@ -631,7 +639,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
                remove_note(t, object.hash);
                logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]);
        }
-       commit_notes(t, logmsg);
+       commit_notes(the_repository, t, logmsg);
 
        free(logmsg);
        free_note_data(&d);
@@ -654,7 +662,7 @@ static int show(int argc, const char **argv, const char *prefix)
                             0);
 
        if (1 < argc) {
-               error(_("too many parameters"));
+               error(_("too many arguments"));
                usage_with_options(git_notes_show_usage, options);
        }
 
@@ -722,7 +730,7 @@ static int merge_commit(struct notes_merge_options *o)
        else
                oidclr(&parent_oid);
 
-       t = xcalloc(1, sizeof(struct notes_tree));
+       CALLOC_ARRAY(t, 1);
        init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
 
        o->local_ref = local_ref_to_free =
@@ -737,7 +745,7 @@ static int merge_commit(struct notes_merge_options *o)
        memset(&pretty_ctx, 0, sizeof(pretty_ctx));
        format_commit_message(partial, "%s", &msg, &pretty_ctx);
        strbuf_trim(&msg);
-       strbuf_insert(&msg, 0, "notes: ", 7);
+       strbuf_insertstr(&msg, 0, "notes: ");
        update_ref(msg.buf, o->local_ref, &oid,
                   is_null_oid(&parent_oid) ? NULL : &parent_oid,
                   0, UPDATE_REFS_DIE_ON_ERR);
@@ -804,11 +812,11 @@ static int merge(int argc, const char **argv, const char *prefix)
                error(_("must specify a notes ref to merge"));
                usage_with_options(git_notes_merge_usage, options);
        } else if (!do_merge && argc) {
-               error(_("too many parameters"));
+               error(_("too many arguments"));
                usage_with_options(git_notes_merge_usage, options);
        }
 
-       init_notes_merge_options(&o);
+       init_notes_merge_options(the_repository, &o);
        o.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT;
 
        if (do_abort)
@@ -932,7 +940,8 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
                strbuf_release(&sb);
        }
        if (!retval)
-               commit_notes(t, "Notes removed by 'git notes remove'");
+               commit_notes(the_repository, t,
+                            "Notes removed by 'git notes remove'");
        free_notes(t);
        return retval;
 }
@@ -951,7 +960,7 @@ static int prune(int argc, const char **argv, const char *prefix)
                             0);
 
        if (argc) {
-               error(_("too many parameters"));
+               error(_("too many arguments"));
                usage_with_options(git_notes_prune_usage, options);
        }
 
@@ -960,7 +969,8 @@ static int prune(int argc, const char **argv, const char *prefix)
        prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
                (show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
        if (!show_only)
-               commit_notes(t, "Notes removed by 'git notes prune'");
+               commit_notes(the_repository, t,
+                            "Notes removed by 'git notes prune'");
        free_notes(t);
        return 0;
 }
@@ -972,7 +982,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)
                             git_notes_get_ref_usage, 0);
 
        if (argc) {
-               error(_("too many parameters"));
+               error(_("too many arguments"));
                usage_with_options(git_notes_get_ref_usage, options);
        }