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 void expand_notes_ref(struct strbuf
*sb
)
88 if (!prefixcmp(sb
->buf
, "refs/notes/"))
89 return; /* we're happy */
90 else if (!prefixcmp(sb
->buf
, "notes/"))
91 strbuf_insert(sb
, 0, "refs/", 5);
93 strbuf_insert(sb
, 0, "refs/notes/", 11);
96 static int list_each_note(const unsigned char *object_sha1
,
97 const unsigned char *note_sha1
, char *note_path
,
100 printf("%s %s\n", sha1_to_hex(note_sha1
), sha1_to_hex(object_sha1
));
104 static void write_note_data(int fd
, const unsigned char *sha1
)
107 enum object_type type
;
108 char *buf
= read_sha1_file(sha1
, &type
, &size
);
111 write_or_die(fd
, buf
, size
);
116 static void write_commented_object(int fd
, const unsigned char *object
)
118 const char *show_args
[5] =
119 {"show", "--stat", "--no-notes", sha1_to_hex(object
), NULL
};
120 struct child_process show
;
121 struct strbuf buf
= STRBUF_INIT
;
124 /* Invoke "git show --stat --no-notes $object" */
125 memset(&show
, 0, sizeof(show
));
126 show
.argv
= show_args
;
131 if (start_command(&show
))
132 die("unable to start 'show' for object '%s'",
133 sha1_to_hex(object
));
135 /* Open the output as FILE* so strbuf_getline() can be used. */
136 show_out
= xfdopen(show
.out
, "r");
137 if (show_out
== NULL
)
138 die_errno("can't fdopen 'show' output fd");
140 /* Prepend "# " to each output line and write result to 'fd' */
141 while (strbuf_getline(&buf
, show_out
, '\n') != EOF
) {
142 write_or_die(fd
, "# ", 2);
143 write_or_die(fd
, buf
.buf
, buf
.len
);
144 write_or_die(fd
, "\n", 1);
146 strbuf_release(&buf
);
147 if (fclose(show_out
))
148 die_errno("failed to close pipe to 'show' for object '%s'",
149 sha1_to_hex(object
));
150 if (finish_command(&show
))
151 die("failed to finish 'show' for object '%s'",
152 sha1_to_hex(object
));
155 static void create_note(const unsigned char *object
, struct msg_arg
*msg
,
156 int append_only
, const unsigned char *prev
,
157 unsigned char *result
)
161 if (msg
->use_editor
|| !msg
->given
) {
164 /* write the template message before editing: */
165 path
= git_pathdup("NOTES_EDITMSG");
166 fd
= open(path
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600);
168 die_errno("could not create file '%s'", path
);
171 write_or_die(fd
, msg
->buf
.buf
, msg
->buf
.len
);
172 else if (prev
&& !append_only
)
173 write_note_data(fd
, prev
);
174 write_or_die(fd
, note_template
, strlen(note_template
));
176 write_commented_object(fd
, object
);
179 strbuf_reset(&(msg
->buf
));
181 if (launch_editor(path
, &(msg
->buf
), NULL
)) {
182 die("Please supply the note contents using either -m" \
185 stripspace(&(msg
->buf
), 1);
188 if (prev
&& append_only
) {
189 /* Append buf to previous note contents */
191 enum object_type type
;
192 char *prev_buf
= read_sha1_file(prev
, &type
, &size
);
194 strbuf_grow(&(msg
->buf
), size
+ 1);
195 if (msg
->buf
.len
&& prev_buf
&& size
)
196 strbuf_insert(&(msg
->buf
), 0, "\n", 1);
197 if (prev_buf
&& size
)
198 strbuf_insert(&(msg
->buf
), 0, prev_buf
, size
);
203 fprintf(stderr
, "Removing note for object %s\n",
204 sha1_to_hex(object
));
207 if (write_sha1_file(msg
->buf
.buf
, msg
->buf
.len
, blob_type
, result
)) {
208 error("unable to write note object");
210 error("The note contents has been left in %s",
217 unlink_or_warn(path
);
222 static int parse_msg_arg(const struct option
*opt
, const char *arg
, int unset
)
224 struct msg_arg
*msg
= opt
->value
;
226 strbuf_grow(&(msg
->buf
), strlen(arg
) + 2);
228 strbuf_addch(&(msg
->buf
), '\n');
229 strbuf_addstr(&(msg
->buf
), arg
);
230 stripspace(&(msg
->buf
), 0);
236 static int parse_file_arg(const struct option
*opt
, const char *arg
, int unset
)
238 struct msg_arg
*msg
= opt
->value
;
241 strbuf_addch(&(msg
->buf
), '\n');
242 if (!strcmp(arg
, "-")) {
243 if (strbuf_read(&(msg
->buf
), 0, 1024) < 0)
244 die_errno("cannot read '%s'", arg
);
245 } else if (strbuf_read_file(&(msg
->buf
), arg
, 1024) < 0)
246 die_errno("could not open or read '%s'", arg
);
247 stripspace(&(msg
->buf
), 0);
253 static int parse_reuse_arg(const struct option
*opt
, const char *arg
, int unset
)
255 struct msg_arg
*msg
= opt
->value
;
257 unsigned char object
[20];
258 enum object_type type
;
262 strbuf_addch(&(msg
->buf
), '\n');
264 if (get_sha1(arg
, object
))
265 die("Failed to resolve '%s' as a valid ref.", arg
);
266 if (!(buf
= read_sha1_file(object
, &type
, &len
)) || !len
) {
268 die("Failed to read object '%s'.", arg
);;
270 strbuf_add(&(msg
->buf
), buf
, len
);
277 static int parse_reedit_arg(const struct option
*opt
, const char *arg
, int unset
)
279 struct msg_arg
*msg
= opt
->value
;
281 return parse_reuse_arg(opt
, arg
, unset
);
284 int commit_notes(struct notes_tree
*t
, const char *msg
)
286 struct commit_list
*parent
;
287 unsigned char tree_sha1
[20], prev_commit
[20], new_commit
[20];
288 struct strbuf buf
= STRBUF_INIT
;
291 t
= &default_notes_tree
;
292 if (!t
->initialized
|| !t
->ref
|| !*t
->ref
)
293 die("Cannot commit uninitialized/unreferenced notes tree");
295 return 0; /* don't have to commit an unchanged tree */
297 /* Prepare commit message and reflog message */
298 strbuf_addstr(&buf
, "notes: "); /* commit message starts at index 7 */
299 strbuf_addstr(&buf
, msg
);
300 if (buf
.buf
[buf
.len
- 1] != '\n')
301 strbuf_addch(&buf
, '\n'); /* Make sure msg ends with newline */
303 /* Convert notes tree to tree object */
304 if (write_notes_tree(t
, tree_sha1
))
305 die("Failed to write current notes tree to database");
307 /* Create new commit for the tree object */
308 if (!read_ref(t
->ref
, prev_commit
)) { /* retrieve parent commit */
309 parent
= xmalloc(sizeof(*parent
));
310 parent
->item
= lookup_commit(prev_commit
);
313 hashclr(prev_commit
);
316 if (commit_tree(buf
.buf
+ 7, tree_sha1
, parent
, new_commit
, NULL
))
317 die("Failed to commit notes tree to database");
319 /* Update notes ref with new commit */
320 update_ref(buf
.buf
, t
->ref
, new_commit
, prev_commit
, 0, DIE_ON_ERR
);
322 strbuf_release(&buf
);
326 combine_notes_fn
parse_combine_notes_fn(const char *v
)
328 if (!strcasecmp(v
, "overwrite"))
329 return combine_notes_overwrite
;
330 else if (!strcasecmp(v
, "ignore"))
331 return combine_notes_ignore
;
332 else if (!strcasecmp(v
, "concatenate"))
333 return combine_notes_concatenate
;
338 static int notes_rewrite_config(const char *k
, const char *v
, void *cb
)
340 struct notes_rewrite_cfg
*c
= cb
;
341 if (!prefixcmp(k
, "notes.rewrite.") && !strcmp(k
+14, c
->cmd
)) {
342 c
->enabled
= git_config_bool(k
, v
);
344 } else if (!c
->mode_from_env
&& !strcmp(k
, "notes.rewritemode")) {
346 config_error_nonbool(k
);
347 c
->combine
= parse_combine_notes_fn(v
);
349 error("Bad notes.rewriteMode value: '%s'", v
);
353 } else if (!c
->refs_from_env
&& !strcmp(k
, "notes.rewriteref")) {
354 /* note that a refs/ prefix is implied in the
355 * underlying for_each_glob_ref */
356 if (!prefixcmp(v
, "refs/notes/"))
357 string_list_add_refs_by_glob(c
->refs
, v
);
359 warning("Refusing to rewrite notes in %s"
360 " (outside of refs/notes/)", v
);
368 struct notes_rewrite_cfg
*init_copy_notes_for_rewrite(const char *cmd
)
370 struct notes_rewrite_cfg
*c
= xmalloc(sizeof(struct notes_rewrite_cfg
));
371 const char *rewrite_mode_env
= getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT
);
372 const char *rewrite_refs_env
= getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT
);
375 c
->combine
= combine_notes_concatenate
;
376 c
->refs
= xcalloc(1, sizeof(struct string_list
));
377 c
->refs
->strdup_strings
= 1;
378 c
->refs_from_env
= 0;
379 c
->mode_from_env
= 0;
380 if (rewrite_mode_env
) {
381 c
->mode_from_env
= 1;
382 c
->combine
= parse_combine_notes_fn(rewrite_mode_env
);
384 error("Bad " GIT_NOTES_REWRITE_MODE_ENVIRONMENT
385 " value: '%s'", rewrite_mode_env
);
387 if (rewrite_refs_env
) {
388 c
->refs_from_env
= 1;
389 string_list_add_refs_from_colon_sep(c
->refs
, rewrite_refs_env
);
391 git_config(notes_rewrite_config
, c
);
392 if (!c
->enabled
|| !c
->refs
->nr
) {
393 string_list_clear(c
->refs
, 0);
398 c
->trees
= load_notes_trees(c
->refs
);
399 string_list_clear(c
->refs
, 0);
404 int copy_note_for_rewrite(struct notes_rewrite_cfg
*c
,
405 const unsigned char *from_obj
, const unsigned char *to_obj
)
409 for (i
= 0; c
->trees
[i
]; i
++)
410 ret
= copy_note(c
->trees
[i
], from_obj
, to_obj
, 1, c
->combine
) || ret
;
414 void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg
*c
)
417 for (i
= 0; c
->trees
[i
]; i
++) {
418 commit_notes(c
->trees
[i
], "Notes added by 'git notes copy'");
419 free_notes(c
->trees
[i
]);
425 int notes_copy_from_stdin(int force
, const char *rewrite_cmd
)
427 struct strbuf buf
= STRBUF_INIT
;
428 struct notes_rewrite_cfg
*c
= NULL
;
429 struct notes_tree
*t
= NULL
;
433 c
= init_copy_notes_for_rewrite(rewrite_cmd
);
437 init_notes(NULL
, NULL
, NULL
, 0);
438 t
= &default_notes_tree
;
441 while (strbuf_getline(&buf
, stdin
, '\n') != EOF
) {
442 unsigned char from_obj
[20], to_obj
[20];
443 struct strbuf
**split
;
446 split
= strbuf_split(&buf
, ' ');
447 if (!split
[0] || !split
[1])
448 die("Malformed input line: '%s'.", buf
.buf
);
449 strbuf_rtrim(split
[0]);
450 strbuf_rtrim(split
[1]);
451 if (get_sha1(split
[0]->buf
, from_obj
))
452 die("Failed to resolve '%s' as a valid ref.", split
[0]->buf
);
453 if (get_sha1(split
[1]->buf
, to_obj
))
454 die("Failed to resolve '%s' as a valid ref.", split
[1]->buf
);
457 err
= copy_note_for_rewrite(c
, from_obj
, to_obj
);
459 err
= copy_note(t
, from_obj
, to_obj
, force
,
460 combine_notes_overwrite
);
463 error("Failed to copy notes from '%s' to '%s'",
464 split
[0]->buf
, split
[1]->buf
);
468 strbuf_list_free(split
);
472 commit_notes(t
, "Notes added by 'git notes copy'");
475 finish_copy_notes_for_rewrite(c
);
480 static struct notes_tree
*init_notes_check(const char *subcommand
)
482 struct notes_tree
*t
;
483 init_notes(NULL
, NULL
, NULL
, 0);
484 t
= &default_notes_tree
;
486 if (prefixcmp(t
->ref
, "refs/notes/"))
487 die("Refusing to %s notes in %s (outside of refs/notes/)",
492 static int list(int argc
, const char **argv
, const char *prefix
)
494 struct notes_tree
*t
;
495 unsigned char object
[20];
496 const unsigned char *note
;
498 struct option options
[] = {
503 argc
= parse_options(argc
, argv
, prefix
, options
,
504 git_notes_list_usage
, 0);
507 error("too many parameters");
508 usage_with_options(git_notes_list_usage
, options
);
511 t
= init_notes_check("list");
513 if (get_sha1(argv
[0], object
))
514 die("Failed to resolve '%s' as a valid ref.", argv
[0]);
515 note
= get_note(t
, object
);
517 puts(sha1_to_hex(note
));
520 retval
= error("No note found for object %s.",
521 sha1_to_hex(object
));
523 retval
= for_each_note(t
, 0, list_each_note
, NULL
);
529 static int add(int argc
, const char **argv
, const char *prefix
)
531 int retval
= 0, force
= 0;
532 const char *object_ref
;
533 struct notes_tree
*t
;
534 unsigned char object
[20], new_note
[20];
536 const unsigned char *note
;
537 struct msg_arg msg
= { 0, 0, STRBUF_INIT
};
538 struct option options
[] = {
539 { OPTION_CALLBACK
, 'm', "message", &msg
, "MSG",
540 "note contents as a string", PARSE_OPT_NONEG
,
542 { OPTION_CALLBACK
, 'F', "file", &msg
, "FILE",
543 "note contents in a file", PARSE_OPT_NONEG
,
545 { OPTION_CALLBACK
, 'c', "reedit-message", &msg
, "OBJECT",
546 "reuse and edit specified note object", PARSE_OPT_NONEG
,
548 { OPTION_CALLBACK
, 'C', "reuse-message", &msg
, "OBJECT",
549 "reuse specified note object", PARSE_OPT_NONEG
,
551 OPT_BOOLEAN('f', "force", &force
, "replace existing notes"),
555 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_add_usage
,
559 error("too many parameters");
560 usage_with_options(git_notes_add_usage
, options
);
563 object_ref
= argc
? argv
[0] : "HEAD";
565 if (get_sha1(object_ref
, object
))
566 die("Failed to resolve '%s' as a valid ref.", object_ref
);
568 t
= init_notes_check("add");
569 note
= get_note(t
, object
);
573 retval
= error("Cannot add notes. Found existing notes "
574 "for object %s. Use '-f' to overwrite "
575 "existing notes", sha1_to_hex(object
));
578 fprintf(stderr
, "Overwriting existing notes for object %s\n",
579 sha1_to_hex(object
));
582 create_note(object
, &msg
, 0, note
, new_note
);
584 if (is_null_sha1(new_note
))
585 remove_note(t
, object
);
586 else if (add_note(t
, object
, new_note
, combine_notes_overwrite
))
587 die("BUG: combine_notes_overwrite failed");
589 snprintf(logmsg
, sizeof(logmsg
), "Notes %s by 'git notes %s'",
590 is_null_sha1(new_note
) ? "removed" : "added", "add");
591 commit_notes(t
, logmsg
);
594 strbuf_release(&(msg
.buf
));
598 static int copy(int argc
, const char **argv
, const char *prefix
)
600 int retval
= 0, force
= 0, from_stdin
= 0;
601 const unsigned char *from_note
, *note
;
602 const char *object_ref
;
603 unsigned char object
[20], from_obj
[20];
604 struct notes_tree
*t
;
605 const char *rewrite_cmd
= NULL
;
606 struct option options
[] = {
607 OPT_BOOLEAN('f', "force", &force
, "replace existing notes"),
608 OPT_BOOLEAN(0, "stdin", &from_stdin
, "read objects from stdin"),
609 OPT_STRING(0, "for-rewrite", &rewrite_cmd
, "command",
610 "load rewriting config for <command> (implies "
615 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_copy_usage
,
618 if (from_stdin
|| rewrite_cmd
) {
620 error("too many parameters");
621 usage_with_options(git_notes_copy_usage
, options
);
623 return notes_copy_from_stdin(force
, rewrite_cmd
);
628 error("too few parameters");
629 usage_with_options(git_notes_copy_usage
, options
);
632 error("too many parameters");
633 usage_with_options(git_notes_copy_usage
, options
);
636 if (get_sha1(argv
[0], from_obj
))
637 die("Failed to resolve '%s' as a valid ref.", argv
[0]);
639 object_ref
= 1 < argc
? argv
[1] : "HEAD";
641 if (get_sha1(object_ref
, object
))
642 die("Failed to resolve '%s' as a valid ref.", object_ref
);
644 t
= init_notes_check("copy");
645 note
= get_note(t
, object
);
649 retval
= error("Cannot copy notes. Found existing "
650 "notes for object %s. Use '-f' to "
651 "overwrite existing notes",
652 sha1_to_hex(object
));
655 fprintf(stderr
, "Overwriting existing notes for object %s\n",
656 sha1_to_hex(object
));
659 from_note
= get_note(t
, from_obj
);
661 retval
= error("Missing notes on source object %s. Cannot "
662 "copy.", sha1_to_hex(from_obj
));
666 if (add_note(t
, object
, from_note
, combine_notes_overwrite
))
667 die("BUG: combine_notes_overwrite failed");
668 commit_notes(t
, "Notes added by 'git notes copy'");
674 static int append_edit(int argc
, const char **argv
, const char *prefix
)
676 const char *object_ref
;
677 struct notes_tree
*t
;
678 unsigned char object
[20], new_note
[20];
679 const unsigned char *note
;
681 const char * const *usage
;
682 struct msg_arg msg
= { 0, 0, STRBUF_INIT
};
683 struct option options
[] = {
684 { OPTION_CALLBACK
, 'm', "message", &msg
, "MSG",
685 "note contents as a string", PARSE_OPT_NONEG
,
687 { OPTION_CALLBACK
, 'F', "file", &msg
, "FILE",
688 "note contents in a file", PARSE_OPT_NONEG
,
690 { OPTION_CALLBACK
, 'c', "reedit-message", &msg
, "OBJECT",
691 "reuse and edit specified note object", PARSE_OPT_NONEG
,
693 { OPTION_CALLBACK
, 'C', "reuse-message", &msg
, "OBJECT",
694 "reuse specified note object", PARSE_OPT_NONEG
,
698 int edit
= !strcmp(argv
[0], "edit");
700 usage
= edit
? git_notes_edit_usage
: git_notes_append_usage
;
701 argc
= parse_options(argc
, argv
, prefix
, options
, usage
,
702 PARSE_OPT_KEEP_ARGV0
);
705 error("too many parameters");
706 usage_with_options(usage
, options
);
709 if (msg
.given
&& edit
)
710 fprintf(stderr
, "The -m/-F/-c/-C options have been deprecated "
711 "for the 'edit' subcommand.\n"
712 "Please use 'git notes add -f -m/-F/-c/-C' instead.\n");
714 object_ref
= 1 < argc
? argv
[1] : "HEAD";
716 if (get_sha1(object_ref
, object
))
717 die("Failed to resolve '%s' as a valid ref.", object_ref
);
719 t
= init_notes_check(argv
[0]);
720 note
= get_note(t
, object
);
722 create_note(object
, &msg
, !edit
, note
, new_note
);
724 if (is_null_sha1(new_note
))
725 remove_note(t
, object
);
726 else if (add_note(t
, object
, new_note
, combine_notes_overwrite
))
727 die("BUG: combine_notes_overwrite failed");
729 snprintf(logmsg
, sizeof(logmsg
), "Notes %s by 'git notes %s'",
730 is_null_sha1(new_note
) ? "removed" : "added", argv
[0]);
731 commit_notes(t
, logmsg
);
733 strbuf_release(&(msg
.buf
));
737 static int show(int argc
, const char **argv
, const char *prefix
)
739 const char *object_ref
;
740 struct notes_tree
*t
;
741 unsigned char object
[20];
742 const unsigned char *note
;
744 struct option options
[] = {
748 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_show_usage
,
752 error("too many parameters");
753 usage_with_options(git_notes_show_usage
, options
);
756 object_ref
= argc
? argv
[0] : "HEAD";
758 if (get_sha1(object_ref
, object
))
759 die("Failed to resolve '%s' as a valid ref.", object_ref
);
761 t
= init_notes_check("show");
762 note
= get_note(t
, object
);
765 retval
= error("No note found for object %s.",
766 sha1_to_hex(object
));
768 const char *show_args
[3] = {"show", sha1_to_hex(note
), NULL
};
769 retval
= execv_git_cmd(show_args
);
775 static int remove_cmd(int argc
, const char **argv
, const char *prefix
)
777 struct option options
[] = {
780 const char *object_ref
;
781 struct notes_tree
*t
;
782 unsigned char object
[20];
784 argc
= parse_options(argc
, argv
, prefix
, options
,
785 git_notes_remove_usage
, 0);
788 error("too many parameters");
789 usage_with_options(git_notes_remove_usage
, options
);
792 object_ref
= argc
? argv
[0] : "HEAD";
794 if (get_sha1(object_ref
, object
))
795 die("Failed to resolve '%s' as a valid ref.", object_ref
);
797 t
= init_notes_check("remove");
799 fprintf(stderr
, "Removing note for object %s\n", sha1_to_hex(object
));
800 remove_note(t
, object
);
802 commit_notes(t
, "Notes removed by 'git notes remove'");
807 static int prune(int argc
, const char **argv
, const char *prefix
)
809 struct notes_tree
*t
;
810 int show_only
= 0, verbose
= 0;
811 struct option options
[] = {
812 OPT_BOOLEAN('n', "dry-run", &show_only
,
813 "do not remove, show only"),
814 OPT_BOOLEAN('v', "verbose", &verbose
, "report pruned notes"),
818 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_prune_usage
,
822 error("too many parameters");
823 usage_with_options(git_notes_prune_usage
, options
);
826 t
= init_notes_check("prune");
828 prune_notes(t
, (verbose
? NOTES_PRUNE_VERBOSE
: 0) |
829 (show_only
? NOTES_PRUNE_VERBOSE
|NOTES_PRUNE_DRYRUN
: 0) );
831 commit_notes(t
, "Notes removed by 'git notes prune'");
836 int cmd_notes(int argc
, const char **argv
, const char *prefix
)
839 const char *override_notes_ref
= NULL
;
840 struct option options
[] = {
841 OPT_STRING(0, "ref", &override_notes_ref
, "notes_ref",
842 "use notes from <notes_ref>"),
846 git_config(git_default_config
, NULL
);
847 argc
= parse_options(argc
, argv
, prefix
, options
, git_notes_usage
,
848 PARSE_OPT_STOP_AT_NON_OPTION
);
850 if (override_notes_ref
) {
851 struct strbuf sb
= STRBUF_INIT
;
852 strbuf_addstr(&sb
, override_notes_ref
);
853 expand_notes_ref(&sb
);
854 setenv("GIT_NOTES_REF", sb
.buf
, 1);
858 if (argc
< 1 || !strcmp(argv
[0], "list"))
859 result
= list(argc
, argv
, prefix
);
860 else if (!strcmp(argv
[0], "add"))
861 result
= add(argc
, argv
, prefix
);
862 else if (!strcmp(argv
[0], "copy"))
863 result
= copy(argc
, argv
, prefix
);
864 else if (!strcmp(argv
[0], "append") || !strcmp(argv
[0], "edit"))
865 result
= append_edit(argc
, argv
, prefix
);
866 else if (!strcmp(argv
[0], "show"))
867 result
= show(argc
, argv
, prefix
);
868 else if (!strcmp(argv
[0], "remove"))
869 result
= remove_cmd(argc
, argv
, prefix
);
870 else if (!strcmp(argv
[0], "prune"))
871 result
= prune(argc
, argv
, prefix
);
873 result
= error("Unknown subcommand: %s", argv
[0]);
874 usage_with_options(git_notes_usage
, options
);
877 return result
? 1 : 0;