4 * Copyright (c) 2010 Johan Herland <johan@herland.net>
6 * Based on git-notes.sh by Johannes Schindelin,
7 * and builtin-tag.c by Kristian Høgsberg and Carlos Rica.
17 #include "run-command.h"
18 #include "parse-options.h"
19 #include "string-list.h"
21 static const char * const git_notes_usage
[] = {
22 "git notes [--ref <notes_ref>] [list [<object>]]",
23 "git notes [--ref <notes_ref>] add [-f] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]",
24 "git notes [--ref <notes_ref>] copy [-f] <from-object> <to-object>",
25 "git notes [--ref <notes_ref>] append [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]",
26 "git notes [--ref <notes_ref>] edit [<object>]",
27 "git notes [--ref <notes_ref>] show [<object>]",
28 "git notes [--ref <notes_ref>] remove [<object>]",
29 "git notes [--ref <notes_ref>] prune",
33 static const char * const git_notes_list_usage
[] = {
34 "git notes [list [<object>]]",
38 static const char * const git_notes_add_usage
[] = {
39 "git notes add [<options>] [<object>]",
43 static const char * const git_notes_copy_usage
[] = {
44 "git notes copy [<options>] <from-object> <to-object>",
45 "git notes copy --stdin [<from-object> <to-object>]...",
49 static const char * const git_notes_append_usage
[] = {
50 "git notes append [<options>] [<object>]",
54 static const char * const git_notes_edit_usage
[] = {
55 "git notes edit [<object>]",
59 static const char * const git_notes_show_usage
[] = {
60 "git notes show [<object>]",
64 static const char * const git_notes_remove_usage
[] = {
65 "git notes remove [<object>]",
69 static const char * const git_notes_prune_usage
[] = {
74 static const char note_template
[] =
77 "# Write/edit the notes for the following object:\n"
86 static int list_each_note(const unsigned char *object_sha1
,
87 const unsigned char *note_sha1
, char *note_path
,
90 printf("%s %s\n", sha1_to_hex(note_sha1
), sha1_to_hex(object_sha1
));
94 static void write_note_data(int fd
, const unsigned char *sha1
)
97 enum object_type type
;
98 char *buf
= read_sha1_file(sha1
, &type
, &size
);
101 write_or_die(fd
, buf
, size
);
106 static void write_commented_object(int fd
, const unsigned char *object
)
108 const char *show_args
[5] =
109 {"show", "--stat", "--no-notes", sha1_to_hex(object
), NULL
};
110 struct child_process show
;
111 struct strbuf buf
= STRBUF_INIT
;
114 /* Invoke "git show --stat --no-notes $object" */
115 memset(&show
, 0, sizeof(show
));
116 show
.argv
= show_args
;
121 if (start_command(&show
))
122 die("unable to start 'show' for object '%s'",
123 sha1_to_hex(object
));
125 /* Open the output as FILE* so strbuf_getline() can be used. */
126 show_out
= xfdopen(show
.out
, "r");
127 if (show_out
== NULL
)
128 die_errno("can't fdopen 'show' output fd");
130 /* Prepend "# " to each output line and write result to 'fd' */
131 while (strbuf_getline(&buf
, show_out
, '\n') != EOF
) {
132 write_or_die(fd
, "# ", 2);
133 write_or_die(fd
, buf
.buf
, buf
.len
);
134 write_or_die(fd
, "\n", 1);
136 strbuf_release(&buf
);
137 if (fclose(show_out
))
138 die_errno("failed to close pipe to 'show' for object '%s'",
139 sha1_to_hex(object
));
140 if (finish_command(&show
))
141 die("failed to finish 'show' for object '%s'",
142 sha1_to_hex(object
));
145 static void create_note(const unsigned char *object
, struct msg_arg
*msg
,
146 int append_only
, const unsigned char *prev
,
147 unsigned char *result
)
151 if (msg
->use_editor
|| !msg
->given
) {
154 /* write the template message before editing: */
155 path
= git_pathdup("NOTES_EDITMSG");
156 fd
= open(path
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600);
158 die_errno("could not create file '%s'", path
);
161 write_or_die(fd
, msg
->buf
.buf
, msg
->buf
.len
);
162 else if (prev
&& !append_only
)
163 write_note_data(fd
, prev
);
164 write_or_die(fd
, note_template
, strlen(note_template
));
166 write_commented_object(fd
, object
);
169 strbuf_reset(&(msg
->buf
));
171 if (launch_editor(path
, &(msg
->buf
), NULL
)) {
172 die("Please supply the note contents using either -m" \
175 stripspace(&(msg
->buf
), 1);
178 if (prev
&& append_only
) {
179 /* Append buf to previous note contents */
181 enum object_type type
;
182 char *prev_buf
= read_sha1_file(prev
, &type
, &size
);
184 strbuf_grow(&(msg
->buf
), size
+ 1);
185 if (msg
->buf
.len
&& prev_buf
&& size
)
186 strbuf_insert(&(msg
->buf
), 0, "\n", 1);
187 if (prev_buf
&& size
)
188 strbuf_insert(&(msg
->buf
), 0, prev_buf
, size
);
193 fprintf(stderr
, "Removing note for object %s\n",
194 sha1_to_hex(object
));
197 if (write_sha1_file(msg
->buf
.buf
, msg
->buf
.len
, blob_type
, result
)) {
198 error("unable to write note object");
200 error("The note contents has been left in %s",
207 unlink_or_warn(path
);
212 static int parse_msg_arg(const struct option
*opt
, const char *arg
, int unset
)
214 struct msg_arg
*msg
= opt
->value
;
219 strbuf_grow(&(msg
->buf
), strlen(arg
) + 2);
221 strbuf_addstr(&(msg
->buf
), "\n");
222 strbuf_addstr(&(msg
->buf
), arg
);
223 stripspace(&(msg
->buf
), 0);
229 static int parse_file_arg(const struct option
*opt
, const char *arg
, int unset
)
231 struct msg_arg
*msg
= opt
->value
;
237 strbuf_addstr(&(msg
->buf
), "\n");
238 if (!strcmp(arg
, "-")) {
239 if (strbuf_read(&(msg
->buf
), 0, 1024) < 0)
240 die_errno("cannot read '%s'", arg
);
241 } else if (strbuf_read_file(&(msg
->buf
), arg
, 1024) < 0)
242 die_errno("could not open or read '%s'", arg
);
243 stripspace(&(msg
->buf
), 0);
249 static int parse_reuse_arg(const struct option
*opt
, const char *arg
, int unset
)
251 struct msg_arg
*msg
= opt
->value
;
253 unsigned char object
[20];
254 enum object_type type
;
261 strbuf_addstr(&(msg
->buf
), "\n");
263 if (get_sha1(arg
, object
))
264 die("Failed to resolve '%s' as a valid ref.", arg
);
265 if (!(buf
= read_sha1_file(object
, &type
, &len
)) || !len
) {
267 die("Failed to read object '%s'.", arg
);;
269 strbuf_add(&(msg
->buf
), buf
, len
);
276 static int parse_reedit_arg(const struct option
*opt
, const char *arg
, int unset
)
278 struct msg_arg
*msg
= opt
->value
;
280 return parse_reuse_arg(opt
, arg
, unset
);
283 int commit_notes(struct notes_tree
*t
, const char *msg
)
285 struct commit_list
*parent
;
286 unsigned char tree_sha1
[20], prev_commit
[20], new_commit
[20];
287 struct strbuf buf
= STRBUF_INIT
;
290 t
= &default_notes_tree
;
291 if (!t
->initialized
|| !t
->ref
|| !*t
->ref
)
292 die("Cannot commit uninitialized/unreferenced notes tree");
294 return 0; /* don't have to commit an unchanged tree */
296 /* Prepare commit message and reflog message */
297 strbuf_addstr(&buf
, "notes: "); /* commit message starts at index 7 */
298 strbuf_addstr(&buf
, msg
);
299 if (buf
.buf
[buf
.len
- 1] != '\n')
300 strbuf_addch(&buf
, '\n'); /* Make sure msg ends with newline */
302 /* Convert notes tree to tree object */
303 if (write_notes_tree(t
, tree_sha1
))
304 die("Failed to write current notes tree to database");
306 /* Create new commit for the tree object */
307 if (!read_ref(t
->ref
, prev_commit
)) { /* retrieve parent commit */
308 parent
= xmalloc(sizeof(*parent
));
309 parent
->item
= lookup_commit(prev_commit
);
312 hashclr(prev_commit
);
315 if (commit_tree(buf
.buf
+ 7, tree_sha1
, parent
, new_commit
, NULL
))
316 die("Failed to commit notes tree to database");
318 /* Update notes ref with new commit */
319 update_ref(buf
.buf
, t
->ref
, new_commit
, prev_commit
, 0, DIE_ON_ERR
);
321 strbuf_release(&buf
);
325 combine_notes_fn
*parse_combine_notes_fn(const char *v
)
327 if (!strcasecmp(v
, "overwrite"))
328 return combine_notes_overwrite
;
329 else if (!strcasecmp(v
, "ignore"))
330 return combine_notes_ignore
;
331 else if (!strcasecmp(v
, "concatenate"))
332 return combine_notes_concatenate
;
337 static int notes_rewrite_config(const char *k
, const char *v
, void *cb
)
339 struct notes_rewrite_cfg
*c
= cb
;
340 if (!prefixcmp(k
, "notes.rewrite.") && !strcmp(k
+14, c
->cmd
)) {
341 c
->enabled
= git_config_bool(k
, v
);
343 } else if (!c
->mode_from_env
&& !strcmp(k
, "notes.rewritemode")) {
345 config_error_nonbool(k
);
346 c
->combine
= parse_combine_notes_fn(v
);
348 error("Bad notes.rewriteMode value: '%s'", v
);
352 } else if (!c
->refs_from_env
&& !strcmp(k
, "notes.rewriteref")) {
353 /* note that a refs/ prefix is implied in the
354 * underlying for_each_glob_ref */
355 if (!prefixcmp(v
, "refs/notes/"))
356 string_list_add_refs_by_glob(c
->refs
, v
);
358 warning("Refusing to rewrite notes in %s"
359 " (outside of refs/notes/)", v
);
367 struct notes_rewrite_cfg
*init_copy_notes_for_rewrite(const char *cmd
)
369 struct notes_rewrite_cfg
*c
= xmalloc(sizeof(struct notes_rewrite_cfg
));
370 const char *rewrite_mode_env
= getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT
);
371 const char *rewrite_refs_env
= getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT
);
374 c
->combine
= combine_notes_concatenate
;
375 c
->refs
= xcalloc(1, sizeof(struct string_list
));
376 c
->refs
->strdup_strings
= 1;
377 c
->refs_from_env
= 0;
378 c
->mode_from_env
= 0;
379 if (rewrite_mode_env
) {
380 c
->mode_from_env
= 1;
381 c
->combine
= parse_combine_notes_fn(rewrite_mode_env
);
383 error("Bad " GIT_NOTES_REWRITE_MODE_ENVIRONMENT
384 " value: '%s'", rewrite_mode_env
);
386 if (rewrite_refs_env
) {
387 c
->refs_from_env
= 1;
388 string_list_add_refs_from_colon_sep(c
->refs
, rewrite_refs_env
);
390 git_config(notes_rewrite_config
, c
);
391 if (!c
->enabled
|| !c
->refs
->nr
) {
392 string_list_clear(c
->refs
, 0);
397 c
->trees
= load_notes_trees(c
->refs
);
398 string_list_clear(c
->refs
, 0);
403 int copy_note_for_rewrite(struct notes_rewrite_cfg
*c
,
404 const unsigned char *from_obj
, const unsigned char *to_obj
)
408 for (i
= 0; c
->trees
[i
]; i
++)
409 ret
= copy_note(c
->trees
[i
], from_obj
, to_obj
, 1, c
->combine
) || ret
;
413 void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg
*c
)
416 for (i
= 0; c
->trees
[i
]; i
++) {
417 commit_notes(c
->trees
[i
], "Notes added by 'git notes copy'");
418 free_notes(c
->trees
[i
]);
424 int notes_copy_from_stdin(int force
, const char *rewrite_cmd
)
426 struct strbuf buf
= STRBUF_INIT
;
427 struct notes_rewrite_cfg
*c
= NULL
;
428 struct notes_tree
*t
;
432 c
= init_copy_notes_for_rewrite(rewrite_cmd
);
436 init_notes(NULL
, NULL
, NULL
, 0);
437 t
= &default_notes_tree
;
440 while (strbuf_getline(&buf
, stdin
, '\n') != EOF
) {
441 unsigned char from_obj
[20], to_obj
[20];
442 struct strbuf
**split
;
445 split
= strbuf_split(&buf
, ' ');
446 if (!split
[0] || !split
[1])
447 die("Malformed input line: '%s'.", buf
.buf
);
448 strbuf_rtrim(split
[0]);
449 strbuf_rtrim(split
[1]);
450 if (get_sha1(split
[0]->buf
, from_obj
))
451 die("Failed to resolve '%s' as a valid ref.", split
[0]->buf
);
452 if (get_sha1(split
[1]->buf
, to_obj
))
453 die("Failed to resolve '%s' as a valid ref.", split
[1]->buf
);
456 err
= copy_note_for_rewrite(c
, from_obj
, to_obj
);
458 err
= copy_note(t
, from_obj
, to_obj
, force
,
459 combine_notes_overwrite
);
462 error("Failed to copy notes from '%s' to '%s'",
463 split
[0]->buf
, split
[1]->buf
);
467 strbuf_list_free(split
);
471 commit_notes(t
, "Notes added by 'git notes copy'");
474 finish_copy_notes_for_rewrite(c
);
479 static struct notes_tree
*init_notes_check(const char *subcommand
)
481 struct notes_tree
*t
;
482 init_notes(NULL
, NULL
, NULL
, 0);
483 t
= &default_notes_tree
;
485 if (prefixcmp(t
->ref
, "refs/notes/"))
486 die("Refusing to %s notes in %s (outside of refs/notes/)",
491 static int list(int argc
, const char **argv
, const char *prefix
)
493 struct notes_tree
*t
;
494 unsigned char object
[20];
495 const unsigned char *note
;
497 struct option options
[] = {
502 argc
= parse_options(argc
, argv
, prefix
, options
,
503 git_notes_list_usage
, 0);
506 error("too many parameters");
507 usage_with_options(git_notes_list_usage
, options
);
510 t
= init_notes_check("list");
512 if (get_sha1(argv
[0], object
))
513 die("Failed to resolve '%s' as a valid ref.", argv
[0]);
514 note
= get_note(t
, object
);
516 puts(sha1_to_hex(note
));
519 retval
= error("No note found for object %s.",
520 sha1_to_hex(object
));
522 retval
= for_each_note(t
, 0, list_each_note
, NULL
);
528 static int add(int argc
, const char **argv
, const char *prefix
)
530 int retval
= 0, force
= 0;
531 const char *object_ref
;
532 struct notes_tree
*t
;
533 unsigned char object
[20], new_note
[20];
535 const unsigned char *note
;
536 struct msg_arg msg
= { 0, 0, STRBUF_INIT
};
537 struct option options
[] = {
538 { OPTION_CALLBACK
, 'm', "message", &msg
, "MSG",
539 "note contents as a string", PARSE_OPT_NONEG
,
541 { OPTION_CALLBACK
, 'F', "file", &msg
, "FILE",
542 "note contents in a file", PARSE_OPT_NONEG
,
544 { OPTION_CALLBACK
, 'c', "reedit-message", &msg
, "OBJECT",
545 "reuse and edit specified note object", PARSE_OPT_NONEG
,
547 { OPTION_CALLBACK
, 'C', "reuse-message", &msg
, "OBJECT",
548 "reuse specified note object", PARSE_OPT_NONEG
,
550 OPT_BOOLEAN('f', "force", &force
, "replace existing notes"),
554 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_add_usage
,
558 error("too many parameters");
559 usage_with_options(git_notes_add_usage
, options
);
562 object_ref
= argc
? argv
[0] : "HEAD";
564 if (get_sha1(object_ref
, object
))
565 die("Failed to resolve '%s' as a valid ref.", object_ref
);
567 t
= init_notes_check("add");
568 note
= get_note(t
, object
);
572 retval
= error("Cannot add notes. Found existing notes "
573 "for object %s. Use '-f' to overwrite "
574 "existing notes", sha1_to_hex(object
));
577 fprintf(stderr
, "Overwriting existing notes for object %s\n",
578 sha1_to_hex(object
));
581 create_note(object
, &msg
, 0, note
, new_note
);
583 if (is_null_sha1(new_note
))
584 remove_note(t
, object
);
586 add_note(t
, object
, new_note
, combine_notes_overwrite
);
588 snprintf(logmsg
, sizeof(logmsg
), "Notes %s by 'git notes %s'",
589 is_null_sha1(new_note
) ? "removed" : "added", "add");
590 commit_notes(t
, logmsg
);
593 strbuf_release(&(msg
.buf
));
597 static int copy(int argc
, const char **argv
, const char *prefix
)
599 int retval
= 0, force
= 0, from_stdin
= 0;
600 const unsigned char *from_note
, *note
;
601 const char *object_ref
;
602 unsigned char object
[20], from_obj
[20];
603 struct notes_tree
*t
;
604 const char *rewrite_cmd
= NULL
;
605 struct option options
[] = {
606 OPT_BOOLEAN('f', "force", &force
, "replace existing notes"),
607 OPT_BOOLEAN(0, "stdin", &from_stdin
, "read objects from stdin"),
608 OPT_STRING(0, "for-rewrite", &rewrite_cmd
, "command",
609 "load rewriting config for <command> (implies "
614 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_copy_usage
,
617 if (from_stdin
|| rewrite_cmd
) {
619 error("too many parameters");
620 usage_with_options(git_notes_copy_usage
, options
);
622 return notes_copy_from_stdin(force
, rewrite_cmd
);
627 error("too many parameters");
628 usage_with_options(git_notes_copy_usage
, options
);
631 if (get_sha1(argv
[0], from_obj
))
632 die("Failed to resolve '%s' as a valid ref.", argv
[0]);
634 object_ref
= 1 < argc
? argv
[1] : "HEAD";
636 if (get_sha1(object_ref
, object
))
637 die("Failed to resolve '%s' as a valid ref.", object_ref
);
639 t
= init_notes_check("copy");
640 note
= get_note(t
, object
);
644 retval
= error("Cannot copy notes. Found existing "
645 "notes for object %s. Use '-f' to "
646 "overwrite existing notes",
647 sha1_to_hex(object
));
650 fprintf(stderr
, "Overwriting existing notes for object %s\n",
651 sha1_to_hex(object
));
654 from_note
= get_note(t
, from_obj
);
656 retval
= error("Missing notes on source object %s. Cannot "
657 "copy.", sha1_to_hex(from_obj
));
661 add_note(t
, object
, from_note
, combine_notes_overwrite
);
662 commit_notes(t
, "Notes added by 'git notes copy'");
668 static int append_edit(int argc
, const char **argv
, const char *prefix
)
670 const char *object_ref
;
671 struct notes_tree
*t
;
672 unsigned char object
[20], new_note
[20];
673 const unsigned char *note
;
675 const char * const *usage
;
676 struct msg_arg msg
= { 0, 0, STRBUF_INIT
};
677 struct option options
[] = {
678 { OPTION_CALLBACK
, 'm', "message", &msg
, "MSG",
679 "note contents as a string", PARSE_OPT_NONEG
,
681 { OPTION_CALLBACK
, 'F', "file", &msg
, "FILE",
682 "note contents in a file", PARSE_OPT_NONEG
,
684 { OPTION_CALLBACK
, 'c', "reedit-message", &msg
, "OBJECT",
685 "reuse and edit specified note object", PARSE_OPT_NONEG
,
687 { OPTION_CALLBACK
, 'C', "reuse-message", &msg
, "OBJECT",
688 "reuse specified note object", PARSE_OPT_NONEG
,
692 int edit
= !strcmp(argv
[0], "edit");
694 usage
= edit
? git_notes_edit_usage
: git_notes_append_usage
;
695 argc
= parse_options(argc
, argv
, prefix
, options
, usage
,
696 PARSE_OPT_KEEP_ARGV0
);
699 error("too many parameters");
700 usage_with_options(usage
, options
);
703 if (msg
.given
&& edit
)
704 fprintf(stderr
, "The -m/-F/-c/-C options have been deprecated "
705 "for the 'edit' subcommand.\n"
706 "Please use 'git notes add -f -m/-F/-c/-C' instead.\n");
708 object_ref
= 1 < argc
? argv
[1] : "HEAD";
710 if (get_sha1(object_ref
, object
))
711 die("Failed to resolve '%s' as a valid ref.", object_ref
);
713 t
= init_notes_check(argv
[0]);
714 note
= get_note(t
, object
);
716 create_note(object
, &msg
, !edit
, note
, new_note
);
718 if (is_null_sha1(new_note
))
719 remove_note(t
, object
);
721 add_note(t
, object
, new_note
, combine_notes_overwrite
);
723 snprintf(logmsg
, sizeof(logmsg
), "Notes %s by 'git notes %s'",
724 is_null_sha1(new_note
) ? "removed" : "added", argv
[0]);
725 commit_notes(t
, logmsg
);
727 strbuf_release(&(msg
.buf
));
731 static int show(int argc
, const char **argv
, const char *prefix
)
733 const char *object_ref
;
734 struct notes_tree
*t
;
735 unsigned char object
[20];
736 const unsigned char *note
;
738 struct option options
[] = {
742 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_show_usage
,
746 error("too many parameters");
747 usage_with_options(git_notes_show_usage
, options
);
750 object_ref
= argc
? argv
[0] : "HEAD";
752 if (get_sha1(object_ref
, object
))
753 die("Failed to resolve '%s' as a valid ref.", object_ref
);
755 t
= init_notes_check("show");
756 note
= get_note(t
, object
);
759 retval
= error("No note found for object %s.",
760 sha1_to_hex(object
));
762 const char *show_args
[3] = {"show", sha1_to_hex(note
), NULL
};
763 retval
= execv_git_cmd(show_args
);
769 static int remove_cmd(int argc
, const char **argv
, const char *prefix
)
771 struct option options
[] = {
774 const char *object_ref
;
775 struct notes_tree
*t
;
776 unsigned char object
[20];
778 argc
= parse_options(argc
, argv
, prefix
, options
,
779 git_notes_remove_usage
, 0);
782 error("too many parameters");
783 usage_with_options(git_notes_remove_usage
, options
);
786 object_ref
= argc
? argv
[0] : "HEAD";
788 if (get_sha1(object_ref
, object
))
789 die("Failed to resolve '%s' as a valid ref.", object_ref
);
791 t
= init_notes_check("remove");
793 fprintf(stderr
, "Removing note for object %s\n", sha1_to_hex(object
));
794 remove_note(t
, object
);
796 commit_notes(t
, "Notes removed by 'git notes remove'");
801 static int prune(int argc
, const char **argv
, const char *prefix
)
803 struct notes_tree
*t
;
804 struct option options
[] = {
808 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_prune_usage
,
812 error("too many parameters");
813 usage_with_options(git_notes_prune_usage
, options
);
816 t
= init_notes_check("prune");
819 commit_notes(t
, "Notes removed by 'git notes prune'");
824 int cmd_notes(int argc
, const char **argv
, const char *prefix
)
827 const char *override_notes_ref
= NULL
;
828 struct option options
[] = {
829 OPT_STRING(0, "ref", &override_notes_ref
, "notes_ref",
830 "use notes from <notes_ref>"),
834 git_config(git_default_config
, NULL
);
835 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_usage
,
836 PARSE_OPT_STOP_AT_NON_OPTION
);
838 if (override_notes_ref
) {
839 struct strbuf sb
= STRBUF_INIT
;
840 if (!prefixcmp(override_notes_ref
, "refs/notes/"))
842 else if (!prefixcmp(override_notes_ref
, "notes/"))
843 strbuf_addstr(&sb
, "refs/");
845 strbuf_addstr(&sb
, "refs/notes/");
846 strbuf_addstr(&sb
, override_notes_ref
);
847 setenv("GIT_NOTES_REF", sb
.buf
, 1);
851 if (argc
< 1 || !strcmp(argv
[0], "list"))
852 result
= list(argc
, argv
, prefix
);
853 else if (!strcmp(argv
[0], "add"))
854 result
= add(argc
, argv
, prefix
);
855 else if (!strcmp(argv
[0], "copy"))
856 result
= copy(argc
, argv
, prefix
);
857 else if (!strcmp(argv
[0], "append") || !strcmp(argv
[0], "edit"))
858 result
= append_edit(argc
, argv
, prefix
);
859 else if (!strcmp(argv
[0], "show"))
860 result
= show(argc
, argv
, prefix
);
861 else if (!strcmp(argv
[0], "remove"))
862 result
= remove_cmd(argc
, argv
, prefix
);
863 else if (!strcmp(argv
[0], "prune"))
864 result
= prune(argc
, argv
, prefix
);
866 result
= error("Unknown subcommand: %s", argv
[0]);
867 usage_with_options(git_notes_usage
, options
);
870 return result
? 1 : 0;