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 [-n | -v]",
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
[] = {
70 "git notes prune [<options>]",
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
;
216 strbuf_grow(&(msg
->buf
), strlen(arg
) + 2);
218 strbuf_addch(&(msg
->buf
), '\n');
219 strbuf_addstr(&(msg
->buf
), arg
);
220 stripspace(&(msg
->buf
), 0);
226 static int parse_file_arg(const struct option
*opt
, const char *arg
, int unset
)
228 struct msg_arg
*msg
= opt
->value
;
231 strbuf_addch(&(msg
->buf
), '\n');
232 if (!strcmp(arg
, "-")) {
233 if (strbuf_read(&(msg
->buf
), 0, 1024) < 0)
234 die_errno("cannot read '%s'", arg
);
235 } else if (strbuf_read_file(&(msg
->buf
), arg
, 1024) < 0)
236 die_errno("could not open or read '%s'", arg
);
237 stripspace(&(msg
->buf
), 0);
243 static int parse_reuse_arg(const struct option
*opt
, const char *arg
, int unset
)
245 struct msg_arg
*msg
= opt
->value
;
247 unsigned char object
[20];
248 enum object_type type
;
252 strbuf_addch(&(msg
->buf
), '\n');
254 if (get_sha1(arg
, object
))
255 die("Failed to resolve '%s' as a valid ref.", arg
);
256 if (!(buf
= read_sha1_file(object
, &type
, &len
)) || !len
) {
258 die("Failed to read object '%s'.", arg
);;
260 strbuf_add(&(msg
->buf
), buf
, len
);
267 static int parse_reedit_arg(const struct option
*opt
, const char *arg
, int unset
)
269 struct msg_arg
*msg
= opt
->value
;
271 return parse_reuse_arg(opt
, arg
, unset
);
274 int commit_notes(struct notes_tree
*t
, const char *msg
)
276 struct commit_list
*parent
;
277 unsigned char tree_sha1
[20], prev_commit
[20], new_commit
[20];
278 struct strbuf buf
= STRBUF_INIT
;
281 t
= &default_notes_tree
;
282 if (!t
->initialized
|| !t
->ref
|| !*t
->ref
)
283 die("Cannot commit uninitialized/unreferenced notes tree");
285 return 0; /* don't have to commit an unchanged tree */
287 /* Prepare commit message and reflog message */
288 strbuf_addstr(&buf
, "notes: "); /* commit message starts at index 7 */
289 strbuf_addstr(&buf
, msg
);
290 if (buf
.buf
[buf
.len
- 1] != '\n')
291 strbuf_addch(&buf
, '\n'); /* Make sure msg ends with newline */
293 /* Convert notes tree to tree object */
294 if (write_notes_tree(t
, tree_sha1
))
295 die("Failed to write current notes tree to database");
297 /* Create new commit for the tree object */
298 if (!read_ref(t
->ref
, prev_commit
)) { /* retrieve parent commit */
299 parent
= xmalloc(sizeof(*parent
));
300 parent
->item
= lookup_commit(prev_commit
);
303 hashclr(prev_commit
);
306 if (commit_tree(buf
.buf
+ 7, tree_sha1
, parent
, new_commit
, NULL
))
307 die("Failed to commit notes tree to database");
309 /* Update notes ref with new commit */
310 update_ref(buf
.buf
, t
->ref
, new_commit
, prev_commit
, 0, DIE_ON_ERR
);
312 strbuf_release(&buf
);
316 combine_notes_fn
parse_combine_notes_fn(const char *v
)
318 if (!strcasecmp(v
, "overwrite"))
319 return combine_notes_overwrite
;
320 else if (!strcasecmp(v
, "ignore"))
321 return combine_notes_ignore
;
322 else if (!strcasecmp(v
, "concatenate"))
323 return combine_notes_concatenate
;
328 static int notes_rewrite_config(const char *k
, const char *v
, void *cb
)
330 struct notes_rewrite_cfg
*c
= cb
;
331 if (!prefixcmp(k
, "notes.rewrite.") && !strcmp(k
+14, c
->cmd
)) {
332 c
->enabled
= git_config_bool(k
, v
);
334 } else if (!c
->mode_from_env
&& !strcmp(k
, "notes.rewritemode")) {
336 config_error_nonbool(k
);
337 c
->combine
= parse_combine_notes_fn(v
);
339 error("Bad notes.rewriteMode value: '%s'", v
);
343 } else if (!c
->refs_from_env
&& !strcmp(k
, "notes.rewriteref")) {
344 /* note that a refs/ prefix is implied in the
345 * underlying for_each_glob_ref */
346 if (!prefixcmp(v
, "refs/notes/"))
347 string_list_add_refs_by_glob(c
->refs
, v
);
349 warning("Refusing to rewrite notes in %s"
350 " (outside of refs/notes/)", v
);
358 struct notes_rewrite_cfg
*init_copy_notes_for_rewrite(const char *cmd
)
360 struct notes_rewrite_cfg
*c
= xmalloc(sizeof(struct notes_rewrite_cfg
));
361 const char *rewrite_mode_env
= getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT
);
362 const char *rewrite_refs_env
= getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT
);
365 c
->combine
= combine_notes_concatenate
;
366 c
->refs
= xcalloc(1, sizeof(struct string_list
));
367 c
->refs
->strdup_strings
= 1;
368 c
->refs_from_env
= 0;
369 c
->mode_from_env
= 0;
370 if (rewrite_mode_env
) {
371 c
->mode_from_env
= 1;
372 c
->combine
= parse_combine_notes_fn(rewrite_mode_env
);
374 error("Bad " GIT_NOTES_REWRITE_MODE_ENVIRONMENT
375 " value: '%s'", rewrite_mode_env
);
377 if (rewrite_refs_env
) {
378 c
->refs_from_env
= 1;
379 string_list_add_refs_from_colon_sep(c
->refs
, rewrite_refs_env
);
381 git_config(notes_rewrite_config
, c
);
382 if (!c
->enabled
|| !c
->refs
->nr
) {
383 string_list_clear(c
->refs
, 0);
388 c
->trees
= load_notes_trees(c
->refs
);
389 string_list_clear(c
->refs
, 0);
394 int copy_note_for_rewrite(struct notes_rewrite_cfg
*c
,
395 const unsigned char *from_obj
, const unsigned char *to_obj
)
399 for (i
= 0; c
->trees
[i
]; i
++)
400 ret
= copy_note(c
->trees
[i
], from_obj
, to_obj
, 1, c
->combine
) || ret
;
404 void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg
*c
)
407 for (i
= 0; c
->trees
[i
]; i
++) {
408 commit_notes(c
->trees
[i
], "Notes added by 'git notes copy'");
409 free_notes(c
->trees
[i
]);
415 int notes_copy_from_stdin(int force
, const char *rewrite_cmd
)
417 struct strbuf buf
= STRBUF_INIT
;
418 struct notes_rewrite_cfg
*c
= NULL
;
419 struct notes_tree
*t
= NULL
;
423 c
= init_copy_notes_for_rewrite(rewrite_cmd
);
427 init_notes(NULL
, NULL
, NULL
, 0);
428 t
= &default_notes_tree
;
431 while (strbuf_getline(&buf
, stdin
, '\n') != EOF
) {
432 unsigned char from_obj
[20], to_obj
[20];
433 struct strbuf
**split
;
436 split
= strbuf_split(&buf
, ' ');
437 if (!split
[0] || !split
[1])
438 die("Malformed input line: '%s'.", buf
.buf
);
439 strbuf_rtrim(split
[0]);
440 strbuf_rtrim(split
[1]);
441 if (get_sha1(split
[0]->buf
, from_obj
))
442 die("Failed to resolve '%s' as a valid ref.", split
[0]->buf
);
443 if (get_sha1(split
[1]->buf
, to_obj
))
444 die("Failed to resolve '%s' as a valid ref.", split
[1]->buf
);
447 err
= copy_note_for_rewrite(c
, from_obj
, to_obj
);
449 err
= copy_note(t
, from_obj
, to_obj
, force
,
450 combine_notes_overwrite
);
453 error("Failed to copy notes from '%s' to '%s'",
454 split
[0]->buf
, split
[1]->buf
);
458 strbuf_list_free(split
);
462 commit_notes(t
, "Notes added by 'git notes copy'");
465 finish_copy_notes_for_rewrite(c
);
470 static struct notes_tree
*init_notes_check(const char *subcommand
)
472 struct notes_tree
*t
;
473 init_notes(NULL
, NULL
, NULL
, 0);
474 t
= &default_notes_tree
;
476 if (prefixcmp(t
->ref
, "refs/notes/"))
477 die("Refusing to %s notes in %s (outside of refs/notes/)",
482 static int list(int argc
, const char **argv
, const char *prefix
)
484 struct notes_tree
*t
;
485 unsigned char object
[20];
486 const unsigned char *note
;
488 struct option options
[] = {
493 argc
= parse_options(argc
, argv
, prefix
, options
,
494 git_notes_list_usage
, 0);
497 error("too many parameters");
498 usage_with_options(git_notes_list_usage
, options
);
501 t
= init_notes_check("list");
503 if (get_sha1(argv
[0], object
))
504 die("Failed to resolve '%s' as a valid ref.", argv
[0]);
505 note
= get_note(t
, object
);
507 puts(sha1_to_hex(note
));
510 retval
= error("No note found for object %s.",
511 sha1_to_hex(object
));
513 retval
= for_each_note(t
, 0, list_each_note
, NULL
);
519 static int add(int argc
, const char **argv
, const char *prefix
)
521 int retval
= 0, force
= 0;
522 const char *object_ref
;
523 struct notes_tree
*t
;
524 unsigned char object
[20], new_note
[20];
526 const unsigned char *note
;
527 struct msg_arg msg
= { 0, 0, STRBUF_INIT
};
528 struct option options
[] = {
529 { OPTION_CALLBACK
, 'm', "message", &msg
, "MSG",
530 "note contents as a string", PARSE_OPT_NONEG
,
532 { OPTION_CALLBACK
, 'F', "file", &msg
, "FILE",
533 "note contents in a file", PARSE_OPT_NONEG
,
535 { OPTION_CALLBACK
, 'c', "reedit-message", &msg
, "OBJECT",
536 "reuse and edit specified note object", PARSE_OPT_NONEG
,
538 { OPTION_CALLBACK
, 'C', "reuse-message", &msg
, "OBJECT",
539 "reuse specified note object", PARSE_OPT_NONEG
,
541 OPT__FORCE(&force
, "replace existing notes"),
545 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_add_usage
,
549 error("too many parameters");
550 usage_with_options(git_notes_add_usage
, options
);
553 object_ref
= argc
? argv
[0] : "HEAD";
555 if (get_sha1(object_ref
, object
))
556 die("Failed to resolve '%s' as a valid ref.", object_ref
);
558 t
= init_notes_check("add");
559 note
= get_note(t
, object
);
563 retval
= error("Cannot add notes. Found existing notes "
564 "for object %s. Use '-f' to overwrite "
565 "existing notes", sha1_to_hex(object
));
568 fprintf(stderr
, "Overwriting existing notes for object %s\n",
569 sha1_to_hex(object
));
572 create_note(object
, &msg
, 0, note
, new_note
);
574 if (is_null_sha1(new_note
))
575 remove_note(t
, object
);
577 add_note(t
, object
, new_note
, combine_notes_overwrite
);
579 snprintf(logmsg
, sizeof(logmsg
), "Notes %s by 'git notes %s'",
580 is_null_sha1(new_note
) ? "removed" : "added", "add");
581 commit_notes(t
, logmsg
);
584 strbuf_release(&(msg
.buf
));
588 static int copy(int argc
, const char **argv
, const char *prefix
)
590 int retval
= 0, force
= 0, from_stdin
= 0;
591 const unsigned char *from_note
, *note
;
592 const char *object_ref
;
593 unsigned char object
[20], from_obj
[20];
594 struct notes_tree
*t
;
595 const char *rewrite_cmd
= NULL
;
596 struct option options
[] = {
597 OPT__FORCE(&force
, "replace existing notes"),
598 OPT_BOOLEAN(0, "stdin", &from_stdin
, "read objects from stdin"),
599 OPT_STRING(0, "for-rewrite", &rewrite_cmd
, "command",
600 "load rewriting config for <command> (implies "
605 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_copy_usage
,
608 if (from_stdin
|| rewrite_cmd
) {
610 error("too many parameters");
611 usage_with_options(git_notes_copy_usage
, options
);
613 return notes_copy_from_stdin(force
, rewrite_cmd
);
618 error("too few parameters");
619 usage_with_options(git_notes_copy_usage
, options
);
622 error("too many parameters");
623 usage_with_options(git_notes_copy_usage
, options
);
626 if (get_sha1(argv
[0], from_obj
))
627 die("Failed to resolve '%s' as a valid ref.", argv
[0]);
629 object_ref
= 1 < argc
? argv
[1] : "HEAD";
631 if (get_sha1(object_ref
, object
))
632 die("Failed to resolve '%s' as a valid ref.", object_ref
);
634 t
= init_notes_check("copy");
635 note
= get_note(t
, object
);
639 retval
= error("Cannot copy notes. Found existing "
640 "notes for object %s. Use '-f' to "
641 "overwrite existing notes",
642 sha1_to_hex(object
));
645 fprintf(stderr
, "Overwriting existing notes for object %s\n",
646 sha1_to_hex(object
));
649 from_note
= get_note(t
, from_obj
);
651 retval
= error("Missing notes on source object %s. Cannot "
652 "copy.", sha1_to_hex(from_obj
));
656 add_note(t
, object
, from_note
, combine_notes_overwrite
);
657 commit_notes(t
, "Notes added by 'git notes copy'");
663 static int append_edit(int argc
, const char **argv
, const char *prefix
)
665 const char *object_ref
;
666 struct notes_tree
*t
;
667 unsigned char object
[20], new_note
[20];
668 const unsigned char *note
;
670 const char * const *usage
;
671 struct msg_arg msg
= { 0, 0, STRBUF_INIT
};
672 struct option options
[] = {
673 { OPTION_CALLBACK
, 'm', "message", &msg
, "MSG",
674 "note contents as a string", PARSE_OPT_NONEG
,
676 { OPTION_CALLBACK
, 'F', "file", &msg
, "FILE",
677 "note contents in a file", PARSE_OPT_NONEG
,
679 { OPTION_CALLBACK
, 'c', "reedit-message", &msg
, "OBJECT",
680 "reuse and edit specified note object", PARSE_OPT_NONEG
,
682 { OPTION_CALLBACK
, 'C', "reuse-message", &msg
, "OBJECT",
683 "reuse specified note object", PARSE_OPT_NONEG
,
687 int edit
= !strcmp(argv
[0], "edit");
689 usage
= edit
? git_notes_edit_usage
: git_notes_append_usage
;
690 argc
= parse_options(argc
, argv
, prefix
, options
, usage
,
691 PARSE_OPT_KEEP_ARGV0
);
694 error("too many parameters");
695 usage_with_options(usage
, options
);
698 if (msg
.given
&& edit
)
699 fprintf(stderr
, "The -m/-F/-c/-C options have been deprecated "
700 "for the 'edit' subcommand.\n"
701 "Please use 'git notes add -f -m/-F/-c/-C' instead.\n");
703 object_ref
= 1 < argc
? argv
[1] : "HEAD";
705 if (get_sha1(object_ref
, object
))
706 die("Failed to resolve '%s' as a valid ref.", object_ref
);
708 t
= init_notes_check(argv
[0]);
709 note
= get_note(t
, object
);
711 create_note(object
, &msg
, !edit
, note
, new_note
);
713 if (is_null_sha1(new_note
))
714 remove_note(t
, object
);
716 add_note(t
, object
, new_note
, combine_notes_overwrite
);
718 snprintf(logmsg
, sizeof(logmsg
), "Notes %s by 'git notes %s'",
719 is_null_sha1(new_note
) ? "removed" : "added", argv
[0]);
720 commit_notes(t
, logmsg
);
722 strbuf_release(&(msg
.buf
));
726 static int show(int argc
, const char **argv
, const char *prefix
)
728 const char *object_ref
;
729 struct notes_tree
*t
;
730 unsigned char object
[20];
731 const unsigned char *note
;
733 struct option options
[] = {
737 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_show_usage
,
741 error("too many parameters");
742 usage_with_options(git_notes_show_usage
, options
);
745 object_ref
= argc
? argv
[0] : "HEAD";
747 if (get_sha1(object_ref
, object
))
748 die("Failed to resolve '%s' as a valid ref.", object_ref
);
750 t
= init_notes_check("show");
751 note
= get_note(t
, object
);
754 retval
= error("No note found for object %s.",
755 sha1_to_hex(object
));
757 const char *show_args
[3] = {"show", sha1_to_hex(note
), NULL
};
758 retval
= execv_git_cmd(show_args
);
764 static int remove_cmd(int argc
, const char **argv
, const char *prefix
)
766 struct option options
[] = {
769 const char *object_ref
;
770 struct notes_tree
*t
;
771 unsigned char object
[20];
774 argc
= parse_options(argc
, argv
, prefix
, options
,
775 git_notes_remove_usage
, 0);
778 error("too many parameters");
779 usage_with_options(git_notes_remove_usage
, options
);
782 object_ref
= argc
? argv
[0] : "HEAD";
784 if (get_sha1(object_ref
, object
))
785 die("Failed to resolve '%s' as a valid ref.", object_ref
);
787 t
= init_notes_check("remove");
789 retval
= remove_note(t
, object
);
791 fprintf(stderr
, "Object %s has no note\n", sha1_to_hex(object
));
793 fprintf(stderr
, "Removing note for object %s\n",
794 sha1_to_hex(object
));
796 commit_notes(t
, "Notes removed by 'git notes remove'");
802 static int prune(int argc
, const char **argv
, const char *prefix
)
804 struct notes_tree
*t
;
805 int show_only
= 0, verbose
= 0;
806 struct option options
[] = {
807 OPT__DRY_RUN(&show_only
, "do not remove, show only"),
808 OPT__VERBOSE(&verbose
, "report pruned notes"),
812 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_prune_usage
,
816 error("too many parameters");
817 usage_with_options(git_notes_prune_usage
, options
);
820 t
= init_notes_check("prune");
822 prune_notes(t
, (verbose
? NOTES_PRUNE_VERBOSE
: 0) |
823 (show_only
? NOTES_PRUNE_VERBOSE
|NOTES_PRUNE_DRYRUN
: 0) );
825 commit_notes(t
, "Notes removed by 'git notes prune'");
830 int cmd_notes(int argc
, const char **argv
, const char *prefix
)
833 const char *override_notes_ref
= NULL
;
834 struct option options
[] = {
835 OPT_STRING(0, "ref", &override_notes_ref
, "notes_ref",
836 "use notes from <notes_ref>"),
840 git_config(git_default_config
, NULL
);
841 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_usage
,
842 PARSE_OPT_STOP_AT_NON_OPTION
);
844 if (override_notes_ref
) {
845 struct strbuf sb
= STRBUF_INIT
;
846 if (!prefixcmp(override_notes_ref
, "refs/notes/"))
848 else if (!prefixcmp(override_notes_ref
, "notes/"))
849 strbuf_addstr(&sb
, "refs/");
851 strbuf_addstr(&sb
, "refs/notes/");
852 strbuf_addstr(&sb
, override_notes_ref
);
853 setenv("GIT_NOTES_REF", sb
.buf
, 1);
857 if (argc
< 1 || !strcmp(argv
[0], "list"))
858 result
= list(argc
, argv
, prefix
);
859 else if (!strcmp(argv
[0], "add"))
860 result
= add(argc
, argv
, prefix
);
861 else if (!strcmp(argv
[0], "copy"))
862 result
= copy(argc
, argv
, prefix
);
863 else if (!strcmp(argv
[0], "append") || !strcmp(argv
[0], "edit"))
864 result
= append_edit(argc
, argv
, prefix
);
865 else if (!strcmp(argv
[0], "show"))
866 result
= show(argc
, argv
, prefix
);
867 else if (!strcmp(argv
[0], "remove"))
868 result
= remove_cmd(argc
, argv
, prefix
);
869 else if (!strcmp(argv
[0], "prune"))
870 result
= prune(argc
, argv
, prefix
);
872 result
= error("Unknown subcommand: %s", argv
[0]);
873 usage_with_options(git_notes_usage
, options
);
876 return result
? 1 : 0;