git-notes(1): add a section about the meaning of history
[git/git.git] / builtin-notes.c
CommitLineData
cd067d3b
JH
1/*
2 * Builtin "git notes"
3 *
4 * Copyright (c) 2010 Johan Herland <johan@herland.net>
5 *
6 * Based on git-notes.sh by Johannes Schindelin,
7 * and builtin-tag.c by Kristian Høgsberg and Carlos Rica.
8 */
9
10#include "cache.h"
11#include "builtin.h"
12#include "notes.h"
13#include "blob.h"
14#include "commit.h"
15#include "refs.h"
16#include "exec_cmd.h"
17#include "run-command.h"
18#include "parse-options.h"
6956f858 19#include "string-list.h"
cd067d3b
JH
20
21static const char * const git_notes_usage[] = {
e397421a 22 "git notes [list [<object>]]",
0691cff7 23 "git notes add [-f] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]",
e73bbd96 24 "git notes copy [-f] <from-object> <to-object>",
0691cff7 25 "git notes append [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]",
aaec9bcf 26 "git notes edit [<object>]",
cd067d3b 27 "git notes show [<object>]",
92b3385f 28 "git notes remove [<object>]",
d6576e1f 29 "git notes prune",
cd067d3b
JH
30 NULL
31};
32
33static const char note_template[] =
34 "\n"
35 "#\n"
36 "# Write/edit the notes for the following object:\n"
37 "#\n";
38
348f199b
JH
39struct msg_arg {
40 int given;
0691cff7 41 int use_editor;
348f199b
JH
42 struct strbuf buf;
43};
44
e397421a
JH
45static int list_each_note(const unsigned char *object_sha1,
46 const unsigned char *note_sha1, char *note_path,
47 void *cb_data)
48{
49 printf("%s %s\n", sha1_to_hex(note_sha1), sha1_to_hex(object_sha1));
50 return 0;
51}
52
cd067d3b
JH
53static void write_note_data(int fd, const unsigned char *sha1)
54{
55 unsigned long size;
56 enum object_type type;
57 char *buf = read_sha1_file(sha1, &type, &size);
58 if (buf) {
59 if (size)
60 write_or_die(fd, buf, size);
61 free(buf);
62 }
63}
64
65static void write_commented_object(int fd, const unsigned char *object)
66{
67 const char *show_args[5] =
68 {"show", "--stat", "--no-notes", sha1_to_hex(object), NULL};
69 struct child_process show;
70 struct strbuf buf = STRBUF_INIT;
71 FILE *show_out;
72
73 /* Invoke "git show --stat --no-notes $object" */
74 memset(&show, 0, sizeof(show));
75 show.argv = show_args;
76 show.no_stdin = 1;
77 show.out = -1;
78 show.err = 0;
79 show.git_cmd = 1;
80 if (start_command(&show))
81 die("unable to start 'show' for object '%s'",
82 sha1_to_hex(object));
83
84 /* Open the output as FILE* so strbuf_getline() can be used. */
85 show_out = xfdopen(show.out, "r");
86 if (show_out == NULL)
87 die_errno("can't fdopen 'show' output fd");
88
89 /* Prepend "# " to each output line and write result to 'fd' */
90 while (strbuf_getline(&buf, show_out, '\n') != EOF) {
91 write_or_die(fd, "# ", 2);
92 write_or_die(fd, buf.buf, buf.len);
93 write_or_die(fd, "\n", 1);
94 }
95 strbuf_release(&buf);
96 if (fclose(show_out))
97 die_errno("failed to close pipe to 'show' for object '%s'",
98 sha1_to_hex(object));
99 if (finish_command(&show))
100 die("failed to finish 'show' for object '%s'",
101 sha1_to_hex(object));
102}
103
348f199b
JH
104static void create_note(const unsigned char *object, struct msg_arg *msg,
105 int append_only, const unsigned char *prev,
cd067d3b
JH
106 unsigned char *result)
107{
108 char *path = NULL;
109
0691cff7 110 if (msg->use_editor || !msg->given) {
cd067d3b
JH
111 int fd;
112
113 /* write the template message before editing: */
114 path = git_pathdup("NOTES_EDITMSG");
115 fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600);
116 if (fd < 0)
117 die_errno("could not create file '%s'", path);
118
0691cff7
JH
119 if (msg->given)
120 write_or_die(fd, msg->buf.buf, msg->buf.len);
121 else if (prev && !append_only)
cd067d3b
JH
122 write_note_data(fd, prev);
123 write_or_die(fd, note_template, strlen(note_template));
124
125 write_commented_object(fd, object);
126
127 close(fd);
0691cff7 128 strbuf_reset(&(msg->buf));
cd067d3b 129
348f199b 130 if (launch_editor(path, &(msg->buf), NULL)) {
cd067d3b
JH
131 die("Please supply the note contents using either -m" \
132 " or -F option");
133 }
348f199b 134 stripspace(&(msg->buf), 1);
cd067d3b
JH
135 }
136
2347fae5
JH
137 if (prev && append_only) {
138 /* Append buf to previous note contents */
139 unsigned long size;
140 enum object_type type;
141 char *prev_buf = read_sha1_file(prev, &type, &size);
142
348f199b
JH
143 strbuf_grow(&(msg->buf), size + 1);
144 if (msg->buf.len && prev_buf && size)
145 strbuf_insert(&(msg->buf), 0, "\n", 1);
2347fae5 146 if (prev_buf && size)
348f199b 147 strbuf_insert(&(msg->buf), 0, prev_buf, size);
2347fae5
JH
148 free(prev_buf);
149 }
150
348f199b 151 if (!msg->buf.len) {
cd067d3b
JH
152 fprintf(stderr, "Removing note for object %s\n",
153 sha1_to_hex(object));
154 hashclr(result);
155 } else {
348f199b 156 if (write_sha1_file(msg->buf.buf, msg->buf.len, blob_type, result)) {
cd067d3b
JH
157 error("unable to write note object");
158 if (path)
159 error("The note contents has been left in %s",
160 path);
161 exit(128);
162 }
163 }
164
165 if (path) {
166 unlink_or_warn(path);
167 free(path);
168 }
169}
170
cd067d3b
JH
171static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
172{
173 struct msg_arg *msg = opt->value;
174
175 if (!arg)
176 return -1;
348f199b
JH
177
178 strbuf_grow(&(msg->buf), strlen(arg) + 2);
cd067d3b 179 if (msg->buf.len)
348f199b 180 strbuf_addstr(&(msg->buf), "\n");
cd067d3b 181 strbuf_addstr(&(msg->buf), arg);
348f199b
JH
182 stripspace(&(msg->buf), 0);
183
184 msg->given = 1;
185 return 0;
186}
187
188static int parse_file_arg(const struct option *opt, const char *arg, int unset)
189{
190 struct msg_arg *msg = opt->value;
191
192 if (!arg)
193 return -1;
194
195 if (msg->buf.len)
196 strbuf_addstr(&(msg->buf), "\n");
197 if (!strcmp(arg, "-")) {
198 if (strbuf_read(&(msg->buf), 0, 1024) < 0)
199 die_errno("cannot read '%s'", arg);
200 } else if (strbuf_read_file(&(msg->buf), arg, 1024) < 0)
201 die_errno("could not open or read '%s'", arg);
202 stripspace(&(msg->buf), 0);
203
cd067d3b
JH
204 msg->given = 1;
205 return 0;
206}
207
0691cff7
JH
208static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
209{
210 struct msg_arg *msg = opt->value;
211 char *buf;
212 unsigned char object[20];
213 enum object_type type;
214 unsigned long len;
215
216 if (!arg)
217 return -1;
218
219 if (msg->buf.len)
220 strbuf_addstr(&(msg->buf), "\n");
221
222 if (get_sha1(arg, object))
223 die("Failed to resolve '%s' as a valid ref.", arg);
224 if (!(buf = read_sha1_file(object, &type, &len)) || !len) {
225 free(buf);
226 die("Failed to read object '%s'.", arg);;
227 }
228 strbuf_add(&(msg->buf), buf, len);
229 free(buf);
230
231 msg->given = 1;
232 return 0;
233}
234
235static int parse_reedit_arg(const struct option *opt, const char *arg, int unset)
236{
237 struct msg_arg *msg = opt->value;
238 msg->use_editor = 1;
239 return parse_reuse_arg(opt, arg, unset);
240}
241
cd067d3b
JH
242int commit_notes(struct notes_tree *t, const char *msg)
243{
244 struct commit_list *parent;
245 unsigned char tree_sha1[20], prev_commit[20], new_commit[20];
246 struct strbuf buf = STRBUF_INIT;
247
248 if (!t)
249 t = &default_notes_tree;
250 if (!t->initialized || !t->ref || !*t->ref)
251 die("Cannot commit uninitialized/unreferenced notes tree");
7f710ea9
TR
252 if (!t->dirty)
253 return 0; /* don't have to commit an unchanged tree */
cd067d3b
JH
254
255 /* Prepare commit message and reflog message */
256 strbuf_addstr(&buf, "notes: "); /* commit message starts at index 7 */
257 strbuf_addstr(&buf, msg);
258 if (buf.buf[buf.len - 1] != '\n')
259 strbuf_addch(&buf, '\n'); /* Make sure msg ends with newline */
260
261 /* Convert notes tree to tree object */
262 if (write_notes_tree(t, tree_sha1))
263 die("Failed to write current notes tree to database");
264
265 /* Create new commit for the tree object */
266 if (!read_ref(t->ref, prev_commit)) { /* retrieve parent commit */
267 parent = xmalloc(sizeof(*parent));
268 parent->item = lookup_commit(prev_commit);
269 parent->next = NULL;
270 } else {
271 hashclr(prev_commit);
272 parent = NULL;
273 }
274 if (commit_tree(buf.buf + 7, tree_sha1, parent, new_commit, NULL))
275 die("Failed to commit notes tree to database");
276
277 /* Update notes ref with new commit */
278 update_ref(buf.buf, t->ref, new_commit, prev_commit, 0, DIE_ON_ERR);
279
280 strbuf_release(&buf);
281 return 0;
282}
283
6956f858
TR
284
285combine_notes_fn *parse_combine_notes_fn(const char *v)
286{
287 if (!strcasecmp(v, "overwrite"))
288 return combine_notes_overwrite;
289 else if (!strcasecmp(v, "ignore"))
290 return combine_notes_ignore;
291 else if (!strcasecmp(v, "concatenate"))
292 return combine_notes_concatenate;
293 else
294 return NULL;
295}
296
297static int notes_rewrite_config(const char *k, const char *v, void *cb)
298{
299 struct notes_rewrite_cfg *c = cb;
300 if (!prefixcmp(k, "notes.rewrite.") && !strcmp(k+14, c->cmd)) {
301 c->enabled = git_config_bool(k, v);
302 return 0;
303 } else if (!c->mode_from_env && !strcmp(k, "notes.rewritemode")) {
304 if (!v)
305 config_error_nonbool(k);
306 c->combine = parse_combine_notes_fn(v);
307 if (!c->combine) {
308 error("Bad notes.rewriteMode value: '%s'", v);
309 return 1;
310 }
311 return 0;
312 } else if (!c->refs_from_env && !strcmp(k, "notes.rewriteref")) {
313 /* note that a refs/ prefix is implied in the
314 * underlying for_each_glob_ref */
315 if (!prefixcmp(v, "refs/notes/"))
316 string_list_add_refs_by_glob(c->refs, v);
317 else
318 warning("Refusing to rewrite notes in %s"
319 " (outside of refs/notes/)", v);
320 return 0;
321 }
322
323 return 0;
324}
325
326
327struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
328{
329 struct notes_rewrite_cfg *c = xmalloc(sizeof(struct notes_rewrite_cfg));
330 const char *rewrite_mode_env = getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT);
331 const char *rewrite_refs_env = getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT);
332 c->cmd = cmd;
333 c->enabled = 1;
334 c->combine = combine_notes_concatenate;
335 c->refs = xcalloc(1, sizeof(struct string_list));
336 c->refs->strdup_strings = 1;
337 c->refs_from_env = 0;
338 c->mode_from_env = 0;
339 if (rewrite_mode_env) {
340 c->mode_from_env = 1;
341 c->combine = parse_combine_notes_fn(rewrite_mode_env);
342 if (!c->combine)
343 error("Bad " GIT_NOTES_REWRITE_MODE_ENVIRONMENT
344 " value: '%s'", rewrite_mode_env);
345 }
346 if (rewrite_refs_env) {
347 c->refs_from_env = 1;
348 string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env);
349 }
350 git_config(notes_rewrite_config, c);
351 if (!c->enabled || !c->refs->nr) {
352 string_list_clear(c->refs, 0);
353 free(c->refs);
354 free(c);
355 return NULL;
356 }
357 c->trees = load_notes_trees(c->refs);
358 string_list_clear(c->refs, 0);
359 free(c->refs);
360 return c;
361}
362
363int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
364 const unsigned char *from_obj, const unsigned char *to_obj)
365{
366 int ret = 0;
367 int i;
368 for (i = 0; c->trees[i]; i++)
369 ret = copy_note(c->trees[i], from_obj, to_obj, 1, c->combine) || ret;
370 return ret;
371}
372
373void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c)
374{
375 int i;
376 for (i = 0; c->trees[i]; i++) {
377 commit_notes(c->trees[i], "Notes added by 'git notes copy'");
378 free_notes(c->trees[i]);
379 }
380 free(c->trees);
381 free(c);
382}
383
384int notes_copy_from_stdin(int force, const char *rewrite_cmd)
160baa0d
TR
385{
386 struct strbuf buf = STRBUF_INIT;
6956f858 387 struct notes_rewrite_cfg *c = NULL;
160baa0d
TR
388 struct notes_tree *t;
389 int ret = 0;
390
6956f858
TR
391 if (rewrite_cmd) {
392 c = init_copy_notes_for_rewrite(rewrite_cmd);
393 if (!c)
394 return 0;
395 } else {
396 init_notes(NULL, NULL, NULL, 0);
397 t = &default_notes_tree;
398 }
160baa0d
TR
399
400 while (strbuf_getline(&buf, stdin, '\n') != EOF) {
401 unsigned char from_obj[20], to_obj[20];
402 struct strbuf **split;
403 int err;
404
405 split = strbuf_split(&buf, ' ');
406 if (!split[0] || !split[1])
407 die("Malformed input line: '%s'.", buf.buf);
408 strbuf_rtrim(split[0]);
409 strbuf_rtrim(split[1]);
410 if (get_sha1(split[0]->buf, from_obj))
411 die("Failed to resolve '%s' as a valid ref.", split[0]->buf);
412 if (get_sha1(split[1]->buf, to_obj))
413 die("Failed to resolve '%s' as a valid ref.", split[1]->buf);
414
6956f858
TR
415 if (rewrite_cmd)
416 err = copy_note_for_rewrite(c, from_obj, to_obj);
417 else
418 err = copy_note(t, from_obj, to_obj, force,
419 combine_notes_overwrite);
160baa0d
TR
420
421 if (err) {
422 error("Failed to copy notes from '%s' to '%s'",
423 split[0]->buf, split[1]->buf);
424 ret = 1;
425 }
426
427 strbuf_list_free(split);
428 }
429
6956f858
TR
430 if (!rewrite_cmd) {
431 commit_notes(t, "Notes added by 'git notes copy'");
432 free_notes(t);
433 } else {
434 finish_copy_notes_for_rewrite(c);
435 }
160baa0d
TR
436 return ret;
437}
438
cd067d3b
JH
439int cmd_notes(int argc, const char **argv, const char *prefix)
440{
cd067d3b 441 struct notes_tree *t;
e73bbd96 442 unsigned char object[20], from_obj[20], new_note[20];
cd067d3b 443 const unsigned char *note;
92b3385f
JH
444 const char *object_ref;
445 char logmsg[100];
a0b4dfa9 446
e73bbd96 447 int list = 0, add = 0, copy = 0, append = 0, edit = 0, show = 0,
160baa0d 448 remove = 0, prune = 0, force = 0, from_stdin = 0;
5848769f 449 int given_object = 0, i = 1, retval = 0;
0691cff7 450 struct msg_arg msg = { 0, 0, STRBUF_INIT };
6956f858 451 const char *rewrite_cmd = NULL;
dcf783a2 452 const char *override_notes_ref = NULL;
cd067d3b 453 struct option options[] = {
aaec9bcf 454 OPT_GROUP("Notes options"),
348f199b 455 OPT_CALLBACK('m', "message", &msg, "MSG",
cd067d3b 456 "note contents as a string", parse_msg_arg),
348f199b
JH
457 OPT_CALLBACK('F', "file", &msg, "FILE",
458 "note contents in a file", parse_file_arg),
0691cff7
JH
459 OPT_CALLBACK('c', "reedit-message", &msg, "OBJECT",
460 "reuse and edit specified note object", parse_reedit_arg),
461 OPT_CALLBACK('C', "reuse-message", &msg, "OBJECT",
462 "reuse specified note object", parse_reuse_arg),
7aa4754e 463 OPT_BOOLEAN('f', "force", &force, "replace existing notes"),
160baa0d 464 OPT_BOOLEAN(0, "stdin", &from_stdin, "read objects from stdin"),
dcf783a2
TR
465 OPT_STRING(0, "ref", &override_notes_ref, "notes_ref",
466 "use notes from <notes_ref>"),
6956f858
TR
467 OPT_STRING(0, "for-rewrite", &rewrite_cmd, "command",
468 "load rewriting config for <command> (implies --stdin)"),
cd067d3b
JH
469 OPT_END()
470 };
471
472 git_config(git_default_config, NULL);
473
474 argc = parse_options(argc, argv, prefix, options, git_notes_usage, 0);
475
dcf783a2
TR
476 if (override_notes_ref) {
477 struct strbuf sb = STRBUF_INIT;
478 if (!prefixcmp(override_notes_ref, "refs/notes/"))
479 /* we're happy */;
480 else if (!prefixcmp(override_notes_ref, "notes/"))
481 strbuf_addstr(&sb, "refs/");
482 else
483 strbuf_addstr(&sb, "refs/notes/");
484 strbuf_addstr(&sb, override_notes_ref);
485 setenv("GIT_NOTES_REF", sb.buf, 1);
486 strbuf_release(&sb);
487 }
488
e397421a
JH
489 if (argc && !strcmp(argv[0], "list"))
490 list = 1;
7aa4754e
JH
491 else if (argc && !strcmp(argv[0], "add"))
492 add = 1;
e73bbd96
JH
493 else if (argc && !strcmp(argv[0], "copy"))
494 copy = 1;
2347fae5
JH
495 else if (argc && !strcmp(argv[0], "append"))
496 append = 1;
e397421a 497 else if (argc && !strcmp(argv[0], "edit"))
cd067d3b
JH
498 edit = 1;
499 else if (argc && !strcmp(argv[0], "show"))
500 show = 1;
92b3385f
JH
501 else if (argc && !strcmp(argv[0], "remove"))
502 remove = 1;
d6576e1f
JH
503 else if (argc && !strcmp(argv[0], "prune"))
504 prune = 1;
5848769f 505 else if (!argc) {
e397421a 506 list = 1; /* Default to 'list' if no other subcommand given */
5848769f
JH
507 i = 0;
508 }
cd067d3b 509
e73bbd96 510 if (list + add + copy + append + edit + show + remove + prune != 1)
cd067d3b
JH
511 usage_with_options(git_notes_usage, options);
512
348f199b 513 if (msg.given && !(add || append || edit)) {
0691cff7
JH
514 error("cannot use -m/-F/-c/-C options with %s subcommand.",
515 argv[0]);
92b3385f
JH
516 usage_with_options(git_notes_usage, options);
517 }
518
348f199b 519 if (msg.given && edit) {
0691cff7
JH
520 fprintf(stderr, "The -m/-F/-c/-C options have been deprecated "
521 "for the 'edit' subcommand.\n"
522 "Please use 'git notes add -f -m/-F/-c/-C' instead.\n");
aaec9bcf
JH
523 }
524
e73bbd96 525 if (force && !(add || copy)) {
7aa4754e
JH
526 error("cannot use -f option with %s subcommand.", argv[0]);
527 usage_with_options(git_notes_usage, options);
528 }
529
6956f858
TR
530 if (!copy && rewrite_cmd) {
531 error("cannot use --for-rewrite with %s subcommand.", argv[0]);
532 usage_with_options(git_notes_usage, options);
533 }
160baa0d
TR
534 if (!copy && from_stdin) {
535 error("cannot use --stdin with %s subcommand.", argv[0]);
536 usage_with_options(git_notes_usage, options);
537 }
538
e73bbd96
JH
539 if (copy) {
540 const char *from_ref;
6956f858 541 if (from_stdin || rewrite_cmd) {
160baa0d
TR
542 if (argc > 1) {
543 error("too many parameters");
544 usage_with_options(git_notes_usage, options);
545 } else {
6956f858 546 return notes_copy_from_stdin(force, rewrite_cmd);
160baa0d
TR
547 }
548 }
e73bbd96
JH
549 if (argc < 3) {
550 error("too few parameters");
551 usage_with_options(git_notes_usage, options);
552 }
553 from_ref = argv[i++];
554 if (get_sha1(from_ref, from_obj))
555 die("Failed to resolve '%s' as a valid ref.", from_ref);
556 }
557
5848769f
JH
558 given_object = argc > i;
559 object_ref = given_object ? argv[i++] : "HEAD";
560
561 if (argc > i || (prune && given_object)) {
cd067d3b
JH
562 error("too many parameters");
563 usage_with_options(git_notes_usage, options);
564 }
565
566 if (get_sha1(object_ref, object))
567 die("Failed to resolve '%s' as a valid ref.", object_ref);
568
569 init_notes(NULL, NULL, NULL, 0);
570 t = &default_notes_tree;
571
572 if (prefixcmp(t->ref, "refs/notes/"))
573 die("Refusing to %s notes in %s (outside of refs/notes/)",
92b3385f 574 argv[0], t->ref);
cd067d3b
JH
575
576 note = get_note(t, object);
577
e397421a
JH
578 /* list command */
579
580 if (list) {
581 if (given_object) {
582 if (note) {
583 puts(sha1_to_hex(note));
5848769f 584 goto end;
e397421a 585 }
5848769f
JH
586 } else {
587 retval = for_each_note(t, 0, list_each_note, NULL);
588 goto end;
589 }
e397421a
JH
590 }
591
cd067d3b
JH
592 /* show command */
593
e397421a 594 if ((list || show) && !note) {
cd067d3b 595 error("No note found for object %s.", sha1_to_hex(object));
5848769f
JH
596 retval = 1;
597 goto end;
cd067d3b
JH
598 } else if (show) {
599 const char *show_args[3] = {"show", sha1_to_hex(note), NULL};
5848769f
JH
600 retval = execv_git_cmd(show_args);
601 goto end;
cd067d3b
JH
602 }
603
2347fae5 604 /* add/append/edit/remove/prune command */
7aa4754e 605
e73bbd96 606 if ((add || copy) && note) {
5848769f 607 if (!force) {
e73bbd96 608 error("Cannot %s notes. Found existing notes for object"
5848769f 609 " %s. Use '-f' to overwrite existing notes",
e73bbd96 610 argv[0], sha1_to_hex(object));
5848769f
JH
611 retval = 1;
612 goto end;
7aa4754e 613 }
5848769f
JH
614 fprintf(stderr, "Overwriting existing notes for object %s\n",
615 sha1_to_hex(object));
7aa4754e 616 }
92b3385f 617
348f199b
JH
618 if (remove) {
619 msg.given = 1;
0691cff7 620 msg.use_editor = 0;
348f199b 621 strbuf_reset(&(msg.buf));
cd067d3b
JH
622 }
623
d6576e1f
JH
624 if (prune) {
625 hashclr(new_note);
626 prune_notes(t);
5848769f 627 goto commit;
e73bbd96
JH
628 } else if (copy) {
629 const unsigned char *from_note = get_note(t, from_obj);
630 if (!from_note) {
631 error("Missing notes on source object %s. Cannot copy.",
632 sha1_to_hex(from_obj));
633 retval = 1;
634 goto end;
635 }
636 hashcpy(new_note, from_note);
5848769f 637 } else
348f199b 638 create_note(object, &msg, append, note, new_note);
5848769f
JH
639
640 if (is_null_sha1(new_note))
641 remove_note(t, object);
642 else
643 add_note(t, object, new_note, combine_notes_overwrite);
644
645commit:
646 snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'",
92b3385f 647 is_null_sha1(new_note) ? "removed" : "added", argv[0]);
a0b4dfa9 648 commit_notes(t, logmsg);
cd067d3b 649
5848769f 650end:
cd067d3b 651 free_notes(t);
348f199b 652 strbuf_release(&(msg.buf));
5848769f 653 return retval;
cd067d3b 654}