Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 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, |
Phil Hord | 09b7e22 | 2013-06-18 13:44:58 -0400 | [diff] [blame] | 7 | * and builtin/tag.c by Kristian Høgsberg and Carlos Rica. |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 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" |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 19 | #include "string-list.h" |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 20 | #include "notes-merge.h" |
Johan Herland | 49c2470 | 2013-06-12 02:13:00 +0200 | [diff] [blame] | 21 | #include "notes-utils.h" |
Michael Rappazzo | ac6c561 | 2015-10-02 07:55:31 -0400 | [diff] [blame] | 22 | #include "worktree.h" |
Junio C Hamano | f50fee4 | 2012-09-15 13:56:07 -0700 | [diff] [blame] | 23 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 24 | static const char * const git_notes_usage[] = { |
Alex Henrie | 9c9b4f2 | 2015-01-13 00:44:47 -0700 | [diff] [blame] | 25 | N_("git notes [--ref <notes-ref>] [list [<object>]]"), |
| 26 | N_("git notes [--ref <notes-ref>] add [-f] [--allow-empty] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"), |
| 27 | N_("git notes [--ref <notes-ref>] copy [-f] <from-object> <to-object>"), |
| 28 | N_("git notes [--ref <notes-ref>] append [--allow-empty] [-m <msg> | -F <file> | (-c | -C) <object>] [<object>]"), |
| 29 | N_("git notes [--ref <notes-ref>] edit [--allow-empty] [<object>]"), |
| 30 | N_("git notes [--ref <notes-ref>] show [<object>]"), |
| 31 | N_("git notes [--ref <notes-ref>] merge [-v | -q] [-s <strategy>] <notes-ref>"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 32 | N_("git notes merge --commit [-v | -q]"), |
| 33 | N_("git notes merge --abort [-v | -q]"), |
Alex Henrie | 9c9b4f2 | 2015-01-13 00:44:47 -0700 | [diff] [blame] | 34 | N_("git notes [--ref <notes-ref>] remove [<object>...]"), |
| 35 | N_("git notes [--ref <notes-ref>] prune [-n | -v]"), |
| 36 | N_("git notes [--ref <notes-ref>] get-ref"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 37 | NULL |
| 38 | }; |
| 39 | |
| 40 | static const char * const git_notes_list_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 41 | N_("git notes [list [<object>]]"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 42 | NULL |
| 43 | }; |
| 44 | |
| 45 | static const char * const git_notes_add_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 46 | N_("git notes add [<options>] [<object>]"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 47 | NULL |
| 48 | }; |
| 49 | |
| 50 | static const char * const git_notes_copy_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 51 | N_("git notes copy [<options>] <from-object> <to-object>"), |
| 52 | N_("git notes copy --stdin [<from-object> <to-object>]..."), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 53 | NULL |
| 54 | }; |
| 55 | |
| 56 | static const char * const git_notes_append_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 57 | N_("git notes append [<options>] [<object>]"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 58 | NULL |
| 59 | }; |
| 60 | |
| 61 | static const char * const git_notes_edit_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 62 | N_("git notes edit [<object>]"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 63 | NULL |
| 64 | }; |
| 65 | |
| 66 | static const char * const git_notes_show_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 67 | N_("git notes show [<object>]"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 68 | NULL |
| 69 | }; |
| 70 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 71 | static const char * const git_notes_merge_usage[] = { |
Alex Henrie | 9c9b4f2 | 2015-01-13 00:44:47 -0700 | [diff] [blame] | 72 | N_("git notes merge [<options>] <notes-ref>"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 73 | N_("git notes merge --commit [<options>]"), |
| 74 | N_("git notes merge --abort [<options>]"), |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 75 | NULL |
| 76 | }; |
| 77 | |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 78 | static const char * const git_notes_remove_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 79 | N_("git notes remove [<object>]"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 80 | NULL |
| 81 | }; |
| 82 | |
| 83 | static const char * const git_notes_prune_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 84 | N_("git notes prune [<options>]"), |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 85 | NULL |
| 86 | }; |
| 87 | |
Johan Herland | 618cd75 | 2010-11-09 22:49:57 +0100 | [diff] [blame] | 88 | static const char * const git_notes_get_ref_usage[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 89 | N_("git notes get-ref"), |
Johan Herland | 618cd75 | 2010-11-09 22:49:57 +0100 | [diff] [blame] | 90 | NULL |
| 91 | }; |
| 92 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 93 | static const char note_template[] = |
Vasco Almeida | 996ee6d | 2016-07-28 11:26:15 +0000 | [diff] [blame] | 94 | N_("Write/edit the notes for the following object:"); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 95 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 96 | struct note_data { |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 97 | int given; |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 98 | int use_editor; |
Johan Herland | 4282af0 | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 99 | char *edit_path; |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 100 | struct strbuf buf; |
| 101 | }; |
| 102 | |
Johan Herland | 4282af0 | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 103 | static void free_note_data(struct note_data *d) |
| 104 | { |
| 105 | if (d->edit_path) { |
| 106 | unlink_or_warn(d->edit_path); |
| 107 | free(d->edit_path); |
| 108 | } |
| 109 | strbuf_release(&d->buf); |
| 110 | } |
| 111 | |
Johan Herland | e397421 | 2010-02-13 22:28:30 +0100 | [diff] [blame] | 112 | static int list_each_note(const unsigned char *object_sha1, |
| 113 | const unsigned char *note_sha1, char *note_path, |
| 114 | void *cb_data) |
| 115 | { |
| 116 | printf("%s %s\n", sha1_to_hex(note_sha1), sha1_to_hex(object_sha1)); |
| 117 | return 0; |
| 118 | } |
| 119 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 120 | static void copy_obj_to_fd(int fd, const unsigned char *sha1) |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 121 | { |
| 122 | unsigned long size; |
| 123 | enum object_type type; |
| 124 | char *buf = read_sha1_file(sha1, &type, &size); |
| 125 | if (buf) { |
| 126 | if (size) |
| 127 | write_or_die(fd, buf, size); |
| 128 | free(buf); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | static void write_commented_object(int fd, const unsigned char *object) |
| 133 | { |
| 134 | const char *show_args[5] = |
| 135 | {"show", "--stat", "--no-notes", sha1_to_hex(object), NULL}; |
René Scharfe | d318027 | 2014-08-19 21:09:35 +0200 | [diff] [blame] | 136 | struct child_process show = CHILD_PROCESS_INIT; |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 137 | struct strbuf buf = STRBUF_INIT; |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 138 | struct strbuf cbuf = STRBUF_INIT; |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 139 | |
| 140 | /* Invoke "git show --stat --no-notes $object" */ |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 141 | show.argv = show_args; |
| 142 | show.no_stdin = 1; |
| 143 | show.out = -1; |
| 144 | show.err = 0; |
| 145 | show.git_cmd = 1; |
| 146 | if (start_command(&show)) |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 147 | die(_("unable to start 'show' for object '%s'"), |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 148 | sha1_to_hex(object)); |
| 149 | |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 150 | if (strbuf_read(&buf, show.out, 0) < 0) |
| 151 | die_errno(_("could not read 'show' output")); |
| 152 | strbuf_add_commented_lines(&cbuf, buf.buf, buf.len); |
| 153 | write_or_die(fd, cbuf.buf, cbuf.len); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 154 | |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 155 | strbuf_release(&cbuf); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 156 | strbuf_release(&buf); |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 157 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 158 | if (finish_command(&show)) |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 159 | die(_("failed to finish 'show' for object '%s'"), |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 160 | sha1_to_hex(object)); |
| 161 | } |
| 162 | |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 163 | static void prepare_note_data(const unsigned char *object, struct note_data *d, |
| 164 | const unsigned char *old_note) |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 165 | { |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 166 | if (d->use_editor || !d->given) { |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 167 | int fd; |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 168 | struct strbuf buf = STRBUF_INIT; |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 169 | |
| 170 | /* write the template message before editing: */ |
Johan Herland | 4282af0 | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 171 | d->edit_path = git_pathdup("NOTES_EDITMSG"); |
| 172 | fd = open(d->edit_path, O_CREAT | O_TRUNC | O_WRONLY, 0600); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 173 | if (fd < 0) |
Johan Herland | 4282af0 | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 174 | die_errno(_("could not create file '%s'"), d->edit_path); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 175 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 176 | if (d->given) |
| 177 | write_or_die(fd, d->buf.buf, d->buf.len); |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 178 | else if (old_note) |
| 179 | copy_obj_to_fd(fd, old_note); |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 180 | |
| 181 | strbuf_addch(&buf, '\n'); |
Vasco Almeida | 996ee6d | 2016-07-28 11:26:15 +0000 | [diff] [blame] | 182 | strbuf_add_commented_lines(&buf, "\n", strlen("\n")); |
| 183 | strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template))); |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 184 | strbuf_addch(&buf, '\n'); |
| 185 | write_or_die(fd, buf.buf, buf.len); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 186 | |
| 187 | write_commented_object(fd, object); |
| 188 | |
| 189 | close(fd); |
Junio C Hamano | eff80a9 | 2013-01-16 20:18:48 +0100 | [diff] [blame] | 190 | strbuf_release(&buf); |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 191 | strbuf_reset(&d->buf); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 192 | |
Johan Herland | 4282af0 | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 193 | if (launch_editor(d->edit_path, &d->buf, NULL)) { |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 194 | die(_("please supply the note contents using either -m or -F option")); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 195 | } |
Tobias Klauser | 63af4a8 | 2015-10-16 17:16:42 +0200 | [diff] [blame] | 196 | strbuf_stripspace(&d->buf, 1); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 197 | } |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 198 | } |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 199 | |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 200 | static void write_note_data(struct note_data *d, unsigned char *sha1) |
| 201 | { |
| 202 | if (write_sha1_file(d->buf.buf, d->buf.len, blob_type, sha1)) { |
| 203 | error(_("unable to write note object")); |
| 204 | if (d->edit_path) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 205 | error(_("the note contents have been left in %s"), |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 206 | d->edit_path); |
| 207 | exit(128); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 208 | } |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 211 | static int parse_msg_arg(const struct option *opt, const char *arg, int unset) |
| 212 | { |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 213 | struct note_data *d = opt->value; |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 214 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 215 | strbuf_grow(&d->buf, strlen(arg) + 2); |
| 216 | if (d->buf.len) |
| 217 | strbuf_addch(&d->buf, '\n'); |
| 218 | strbuf_addstr(&d->buf, arg); |
Tobias Klauser | 63af4a8 | 2015-10-16 17:16:42 +0200 | [diff] [blame] | 219 | strbuf_stripspace(&d->buf, 0); |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 220 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 221 | d->given = 1; |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static int parse_file_arg(const struct option *opt, const char *arg, int unset) |
| 226 | { |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 227 | struct note_data *d = opt->value; |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 228 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 229 | if (d->buf.len) |
| 230 | strbuf_addch(&d->buf, '\n'); |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 231 | if (!strcmp(arg, "-")) { |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 232 | if (strbuf_read(&d->buf, 0, 1024) < 0) |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 233 | die_errno(_("cannot read '%s'"), arg); |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 234 | } else if (strbuf_read_file(&d->buf, arg, 1024) < 0) |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 235 | die_errno(_("could not open or read '%s'"), arg); |
Tobias Klauser | 63af4a8 | 2015-10-16 17:16:42 +0200 | [diff] [blame] | 236 | strbuf_stripspace(&d->buf, 0); |
Johan Herland | 348f199 | 2010-02-13 22:28:35 +0100 | [diff] [blame] | 237 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 238 | d->given = 1; |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 242 | static int parse_reuse_arg(const struct option *opt, const char *arg, int unset) |
| 243 | { |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 244 | struct note_data *d = opt->value; |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 245 | char *buf; |
| 246 | unsigned char object[20]; |
| 247 | enum object_type type; |
| 248 | unsigned long len; |
| 249 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 250 | if (d->buf.len) |
| 251 | strbuf_addch(&d->buf, '\n'); |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 252 | |
| 253 | if (get_sha1(arg, object)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 254 | die(_("failed to resolve '%s' as a valid ref."), arg); |
Johan Herland | 511726e | 2014-11-09 13:30:47 +0100 | [diff] [blame] | 255 | if (!(buf = read_sha1_file(object, &type, &len))) { |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 256 | free(buf); |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 257 | die(_("failed to read object '%s'."), arg); |
Johan Herland | ce8daa1 | 2014-02-12 10:54:16 +0100 | [diff] [blame] | 258 | } |
| 259 | if (type != OBJ_BLOB) { |
| 260 | free(buf); |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 261 | die(_("cannot read note data from non-blob object '%s'."), arg); |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 262 | } |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 263 | strbuf_add(&d->buf, buf, len); |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 264 | free(buf); |
| 265 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 266 | d->given = 1; |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | static int parse_reedit_arg(const struct option *opt, const char *arg, int unset) |
| 271 | { |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 272 | struct note_data *d = opt->value; |
| 273 | d->use_editor = 1; |
Johan Herland | 0691cff | 2010-02-13 22:28:36 +0100 | [diff] [blame] | 274 | return parse_reuse_arg(opt, arg, unset); |
| 275 | } |
| 276 | |
Stephen Boyd | c2e86ad | 2011-03-22 00:51:05 -0700 | [diff] [blame] | 277 | static int notes_copy_from_stdin(int force, const char *rewrite_cmd) |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 278 | { |
| 279 | struct strbuf buf = STRBUF_INIT; |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 280 | struct notes_rewrite_cfg *c = NULL; |
Ævar Arnfjörð Bjarmason | ef7a8e3 | 2010-06-14 23:40:05 +0000 | [diff] [blame] | 281 | struct notes_tree *t = NULL; |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 282 | int ret = 0; |
Johan Herland | 80a1466 | 2013-06-12 02:12:59 +0200 | [diff] [blame] | 283 | const char *msg = "Notes added by 'git notes copy'"; |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 284 | |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 285 | if (rewrite_cmd) { |
| 286 | c = init_copy_notes_for_rewrite(rewrite_cmd); |
| 287 | if (!c) |
| 288 | return 0; |
| 289 | } else { |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 290 | init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE); |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 291 | t = &default_notes_tree; |
| 292 | } |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 293 | |
Junio C Hamano | 8f309ae | 2016-01-13 15:31:17 -0800 | [diff] [blame] | 294 | while (strbuf_getline_lf(&buf, stdin) != EOF) { |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 295 | unsigned char from_obj[20], to_obj[20]; |
| 296 | struct strbuf **split; |
| 297 | int err; |
| 298 | |
| 299 | split = strbuf_split(&buf, ' '); |
| 300 | if (!split[0] || !split[1]) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 301 | die(_("malformed input line: '%s'."), buf.buf); |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 302 | strbuf_rtrim(split[0]); |
| 303 | strbuf_rtrim(split[1]); |
| 304 | if (get_sha1(split[0]->buf, from_obj)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 305 | die(_("failed to resolve '%s' as a valid ref."), split[0]->buf); |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 306 | if (get_sha1(split[1]->buf, to_obj)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 307 | die(_("failed to resolve '%s' as a valid ref."), split[1]->buf); |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 308 | |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 309 | if (rewrite_cmd) |
| 310 | err = copy_note_for_rewrite(c, from_obj, to_obj); |
| 311 | else |
| 312 | err = copy_note(t, from_obj, to_obj, force, |
| 313 | combine_notes_overwrite); |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 314 | |
| 315 | if (err) { |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 316 | error(_("failed to copy notes from '%s' to '%s'"), |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 317 | split[0]->buf, split[1]->buf); |
| 318 | ret = 1; |
| 319 | } |
| 320 | |
| 321 | strbuf_list_free(split); |
| 322 | } |
| 323 | |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 324 | if (!rewrite_cmd) { |
Johan Herland | 80a1466 | 2013-06-12 02:12:59 +0200 | [diff] [blame] | 325 | commit_notes(t, msg); |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 326 | free_notes(t); |
| 327 | } else { |
Johan Herland | 80a1466 | 2013-06-12 02:12:59 +0200 | [diff] [blame] | 328 | finish_copy_notes_for_rewrite(c, msg); |
Thomas Rast | 6956f85 | 2010-03-12 18:04:32 +0100 | [diff] [blame] | 329 | } |
Thomas Rast | 160baa0 | 2010-03-12 18:04:31 +0100 | [diff] [blame] | 330 | return ret; |
| 331 | } |
| 332 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 333 | static struct notes_tree *init_notes_check(const char *subcommand, |
| 334 | int flags) |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 335 | { |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 336 | struct notes_tree *t; |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 337 | const char *ref; |
| 338 | init_notes(NULL, NULL, NULL, flags); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 339 | t = &default_notes_tree; |
Johan Herland | a0b4dfa | 2010-02-13 22:28:24 +0100 | [diff] [blame] | 340 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 341 | ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref; |
| 342 | if (!starts_with(ref, "refs/notes/")) |
Vasco Almeida | 2d1252d | 2016-09-15 14:59:03 +0000 | [diff] [blame] | 343 | /* TRANSLATORS: the first %s will be replaced by a |
| 344 | git notes command: 'add', 'merge', 'remove', etc.*/ |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 345 | die(_("refusing to %s notes in %s (outside of refs/notes/)"), |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 346 | subcommand, ref); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 347 | return t; |
| 348 | } |
| 349 | |
| 350 | static int list(int argc, const char **argv, const char *prefix) |
| 351 | { |
| 352 | struct notes_tree *t; |
| 353 | unsigned char object[20]; |
| 354 | const unsigned char *note; |
| 355 | int retval = -1; |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 356 | struct option options[] = { |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 357 | OPT_END() |
| 358 | }; |
| 359 | |
| 360 | if (argc) |
| 361 | argc = parse_options(argc, argv, prefix, options, |
| 362 | git_notes_list_usage, 0); |
| 363 | |
| 364 | if (1 < argc) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 365 | error(_("too many parameters")); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 366 | usage_with_options(git_notes_list_usage, options); |
| 367 | } |
| 368 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 369 | t = init_notes_check("list", 0); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 370 | if (argc) { |
| 371 | if (get_sha1(argv[0], object)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 372 | die(_("failed to resolve '%s' as a valid ref."), argv[0]); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 373 | note = get_note(t, object); |
| 374 | if (note) { |
| 375 | puts(sha1_to_hex(note)); |
| 376 | retval = 0; |
| 377 | } else |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 378 | retval = error(_("no note found for object %s."), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 379 | sha1_to_hex(object)); |
| 380 | } else |
| 381 | retval = for_each_note(t, 0, list_each_note, NULL); |
| 382 | |
| 383 | free_notes(t); |
| 384 | return retval; |
| 385 | } |
| 386 | |
Johan Herland | 84a7e35 | 2011-03-30 02:02:55 +0200 | [diff] [blame] | 387 | static int append_edit(int argc, const char **argv, const char *prefix); |
| 388 | |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 389 | static int add(int argc, const char **argv, const char *prefix) |
| 390 | { |
Johan Herland | d73a5b9 | 2014-11-12 01:40:14 +0100 | [diff] [blame] | 391 | int force = 0, allow_empty = 0; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 392 | const char *object_ref; |
| 393 | struct notes_tree *t; |
| 394 | unsigned char object[20], new_note[20]; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 395 | const unsigned char *note; |
Johan Herland | 4282af0 | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 396 | struct note_data d = { 0, 0, NULL, STRBUF_INIT }; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 397 | struct option options[] = { |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 398 | { OPTION_CALLBACK, 'm', "message", &d, N_("message"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 399 | N_("note contents as a string"), PARSE_OPT_NONEG, |
Johan Herland | 43a61b8 | 2010-02-25 01:48:11 +0100 | [diff] [blame] | 400 | parse_msg_arg}, |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 401 | { OPTION_CALLBACK, 'F', "file", &d, N_("file"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 402 | N_("note contents in a file"), PARSE_OPT_NONEG, |
Johan Herland | 43a61b8 | 2010-02-25 01:48:11 +0100 | [diff] [blame] | 403 | parse_file_arg}, |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 404 | { OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 405 | N_("reuse and edit specified note object"), PARSE_OPT_NONEG, |
Johan Herland | 43a61b8 | 2010-02-25 01:48:11 +0100 | [diff] [blame] | 406 | parse_reedit_arg}, |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 407 | { OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 408 | N_("reuse specified note object"), PARSE_OPT_NONEG, |
Johan Herland | 43a61b8 | 2010-02-25 01:48:11 +0100 | [diff] [blame] | 409 | parse_reuse_arg}, |
Johan Herland | d73a5b9 | 2014-11-12 01:40:14 +0100 | [diff] [blame] | 410 | OPT_BOOL(0, "allow-empty", &allow_empty, |
| 411 | N_("allow storing empty note")), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 412 | OPT__FORCE(&force, N_("replace existing notes")), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 413 | OPT_END() |
| 414 | }; |
| 415 | |
| 416 | argc = parse_options(argc, argv, prefix, options, git_notes_add_usage, |
Johan Herland | 84a7e35 | 2011-03-30 02:02:55 +0200 | [diff] [blame] | 417 | PARSE_OPT_KEEP_ARGV0); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 418 | |
Johan Herland | 84a7e35 | 2011-03-30 02:02:55 +0200 | [diff] [blame] | 419 | if (2 < argc) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 420 | error(_("too many parameters")); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 421 | usage_with_options(git_notes_add_usage, options); |
| 422 | } |
| 423 | |
Johan Herland | 84a7e35 | 2011-03-30 02:02:55 +0200 | [diff] [blame] | 424 | object_ref = argc > 1 ? argv[1] : "HEAD"; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 425 | |
| 426 | if (get_sha1(object_ref, object)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 427 | die(_("failed to resolve '%s' as a valid ref."), object_ref); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 428 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 429 | t = init_notes_check("add", NOTES_INIT_WRITABLE); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 430 | note = get_note(t, object); |
| 431 | |
| 432 | if (note) { |
| 433 | if (!force) { |
Johan Herland | b0de56c | 2014-11-12 01:40:12 +0100 | [diff] [blame] | 434 | free_notes(t); |
| 435 | if (d.given) { |
Johan Herland | 4282af0 | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 436 | free_note_data(&d); |
Johan Herland | b0de56c | 2014-11-12 01:40:12 +0100 | [diff] [blame] | 437 | return error(_("Cannot add notes. " |
| 438 | "Found existing notes for object %s. " |
| 439 | "Use '-f' to overwrite existing notes"), |
| 440 | sha1_to_hex(object)); |
Johan Herland | 84a7e35 | 2011-03-30 02:02:55 +0200 | [diff] [blame] | 441 | } |
Johan Herland | b0de56c | 2014-11-12 01:40:12 +0100 | [diff] [blame] | 442 | /* |
| 443 | * Redirect to "edit" subcommand. |
| 444 | * |
| 445 | * We only end up here if none of -m/-F/-c/-C or -f are |
| 446 | * given. The original args are therefore still in |
| 447 | * argv[0-1]. |
| 448 | */ |
| 449 | argv[0] = "edit"; |
| 450 | return append_edit(argc, argv, prefix); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 451 | } |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 452 | fprintf(stderr, _("Overwriting existing notes for object %s\n"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 453 | sha1_to_hex(object)); |
| 454 | } |
| 455 | |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 456 | prepare_note_data(object, &d, note); |
Johan Herland | d73a5b9 | 2014-11-12 01:40:14 +0100 | [diff] [blame] | 457 | if (d.buf.len || allow_empty) { |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 458 | write_note_data(&d, new_note); |
| 459 | if (add_note(t, object, new_note, combine_notes_overwrite)) |
| 460 | die("BUG: combine_notes_overwrite failed"); |
| 461 | commit_notes(t, "Notes added by 'git notes add'"); |
| 462 | } else { |
| 463 | fprintf(stderr, _("Removing note for object %s\n"), |
| 464 | sha1_to_hex(object)); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 465 | remove_note(t, object); |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 466 | commit_notes(t, "Notes removed by 'git notes add'"); |
| 467 | } |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 468 | |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 469 | free_note_data(&d); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 470 | free_notes(t); |
Johan Herland | b0de56c | 2014-11-12 01:40:12 +0100 | [diff] [blame] | 471 | return 0; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static int copy(int argc, const char **argv, const char *prefix) |
| 475 | { |
| 476 | int retval = 0, force = 0, from_stdin = 0; |
| 477 | const unsigned char *from_note, *note; |
| 478 | const char *object_ref; |
| 479 | unsigned char object[20], from_obj[20]; |
| 480 | struct notes_tree *t; |
| 481 | const char *rewrite_cmd = NULL; |
| 482 | struct option options[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 483 | OPT__FORCE(&force, N_("replace existing notes")), |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 484 | OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 485 | OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"), |
| 486 | N_("load rewriting config for <command> (implies " |
| 487 | "--stdin)")), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 488 | OPT_END() |
| 489 | }; |
| 490 | |
| 491 | argc = parse_options(argc, argv, prefix, options, git_notes_copy_usage, |
| 492 | 0); |
| 493 | |
| 494 | if (from_stdin || rewrite_cmd) { |
| 495 | if (argc) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 496 | error(_("too many parameters")); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 497 | usage_with_options(git_notes_copy_usage, options); |
| 498 | } else { |
| 499 | return notes_copy_from_stdin(force, rewrite_cmd); |
| 500 | } |
| 501 | } |
| 502 | |
Jeff King | bbb1b8a | 2010-06-28 04:59:07 -0400 | [diff] [blame] | 503 | if (argc < 2) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 504 | error(_("too few parameters")); |
Jeff King | bbb1b8a | 2010-06-28 04:59:07 -0400 | [diff] [blame] | 505 | usage_with_options(git_notes_copy_usage, options); |
| 506 | } |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 507 | if (2 < argc) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 508 | error(_("too many parameters")); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 509 | usage_with_options(git_notes_copy_usage, options); |
| 510 | } |
| 511 | |
| 512 | if (get_sha1(argv[0], from_obj)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 513 | die(_("failed to resolve '%s' as a valid ref."), argv[0]); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 514 | |
| 515 | object_ref = 1 < argc ? argv[1] : "HEAD"; |
| 516 | |
| 517 | if (get_sha1(object_ref, object)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 518 | die(_("failed to resolve '%s' as a valid ref."), object_ref); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 519 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 520 | t = init_notes_check("copy", NOTES_INIT_WRITABLE); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 521 | note = get_note(t, object); |
| 522 | |
| 523 | if (note) { |
| 524 | if (!force) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 525 | retval = error(_("Cannot copy notes. Found existing " |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 526 | "notes for object %s. Use '-f' to " |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 527 | "overwrite existing notes"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 528 | sha1_to_hex(object)); |
| 529 | goto out; |
| 530 | } |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 531 | fprintf(stderr, _("Overwriting existing notes for object %s\n"), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 532 | sha1_to_hex(object)); |
| 533 | } |
| 534 | |
| 535 | from_note = get_note(t, from_obj); |
| 536 | if (!from_note) { |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 537 | retval = error(_("missing notes on source object %s. Cannot " |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 538 | "copy."), sha1_to_hex(from_obj)); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 539 | goto out; |
| 540 | } |
| 541 | |
Johan Herland | 180619a | 2010-11-15 00:52:26 +0100 | [diff] [blame] | 542 | if (add_note(t, object, from_note, combine_notes_overwrite)) |
| 543 | die("BUG: combine_notes_overwrite failed"); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 544 | commit_notes(t, "Notes added by 'git notes copy'"); |
| 545 | out: |
| 546 | free_notes(t); |
| 547 | return retval; |
| 548 | } |
| 549 | |
| 550 | static int append_edit(int argc, const char **argv, const char *prefix) |
| 551 | { |
Johan Herland | d73a5b9 | 2014-11-12 01:40:14 +0100 | [diff] [blame] | 552 | int allow_empty = 0; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 553 | const char *object_ref; |
| 554 | struct notes_tree *t; |
| 555 | unsigned char object[20], new_note[20]; |
| 556 | const unsigned char *note; |
Jeff King | 5b1ef2c | 2017-03-28 15:46:50 -0400 | [diff] [blame] | 557 | char *logmsg; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 558 | const char * const *usage; |
Johan Herland | 4282af0 | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 559 | struct note_data d = { 0, 0, NULL, STRBUF_INIT }; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 560 | struct option options[] = { |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 561 | { OPTION_CALLBACK, 'm', "message", &d, N_("message"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 562 | N_("note contents as a string"), PARSE_OPT_NONEG, |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 563 | parse_msg_arg}, |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 564 | { OPTION_CALLBACK, 'F', "file", &d, N_("file"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 565 | N_("note contents in a file"), PARSE_OPT_NONEG, |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 566 | parse_file_arg}, |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 567 | { OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 568 | N_("reuse and edit specified note object"), PARSE_OPT_NONEG, |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 569 | parse_reedit_arg}, |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 570 | { OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object"), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 571 | N_("reuse specified note object"), PARSE_OPT_NONEG, |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 572 | parse_reuse_arg}, |
Johan Herland | d73a5b9 | 2014-11-12 01:40:14 +0100 | [diff] [blame] | 573 | OPT_BOOL(0, "allow-empty", &allow_empty, |
| 574 | N_("allow storing empty note")), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 575 | OPT_END() |
| 576 | }; |
| 577 | int edit = !strcmp(argv[0], "edit"); |
| 578 | |
| 579 | usage = edit ? git_notes_edit_usage : git_notes_append_usage; |
| 580 | argc = parse_options(argc, argv, prefix, options, usage, |
| 581 | PARSE_OPT_KEEP_ARGV0); |
| 582 | |
| 583 | if (2 < argc) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 584 | error(_("too many parameters")); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 585 | usage_with_options(usage, options); |
| 586 | } |
| 587 | |
Johan Herland | bebf5c0 | 2014-11-09 13:30:49 +0100 | [diff] [blame] | 588 | if (d.given && edit) |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 589 | fprintf(stderr, _("The -m/-F/-c/-C options have been deprecated " |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 590 | "for the 'edit' subcommand.\n" |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 591 | "Please use 'git notes add -f -m/-F/-c/-C' instead.\n")); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 592 | |
| 593 | object_ref = 1 < argc ? argv[1] : "HEAD"; |
| 594 | |
| 595 | if (get_sha1(object_ref, object)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 596 | die(_("failed to resolve '%s' as a valid ref."), object_ref); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 597 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 598 | t = init_notes_check(argv[0], NOTES_INIT_WRITABLE); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 599 | note = get_note(t, object); |
| 600 | |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 601 | prepare_note_data(object, &d, edit ? note : NULL); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 602 | |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 603 | if (note && !edit) { |
| 604 | /* Append buf to previous note contents */ |
| 605 | unsigned long size; |
| 606 | enum object_type type; |
| 607 | char *prev_buf = read_sha1_file(note, &type, &size); |
| 608 | |
| 609 | strbuf_grow(&d.buf, size + 1); |
| 610 | if (d.buf.len && prev_buf && size) |
| 611 | strbuf_insert(&d.buf, 0, "\n", 1); |
| 612 | if (prev_buf && size) |
| 613 | strbuf_insert(&d.buf, 0, prev_buf, size); |
| 614 | free(prev_buf); |
| 615 | } |
| 616 | |
Johan Herland | d73a5b9 | 2014-11-12 01:40:14 +0100 | [diff] [blame] | 617 | if (d.buf.len || allow_empty) { |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 618 | write_note_data(&d, new_note); |
| 619 | if (add_note(t, object, new_note, combine_notes_overwrite)) |
| 620 | die("BUG: combine_notes_overwrite failed"); |
Jeff King | 5b1ef2c | 2017-03-28 15:46:50 -0400 | [diff] [blame] | 621 | logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]); |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 622 | } else { |
| 623 | fprintf(stderr, _("Removing note for object %s\n"), |
| 624 | sha1_to_hex(object)); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 625 | remove_note(t, object); |
Jeff King | 5b1ef2c | 2017-03-28 15:46:50 -0400 | [diff] [blame] | 626 | logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]); |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 627 | } |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 628 | commit_notes(t, logmsg); |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 629 | |
Jeff King | 5b1ef2c | 2017-03-28 15:46:50 -0400 | [diff] [blame] | 630 | free(logmsg); |
Johan Herland | 52694cd | 2014-11-12 01:40:13 +0100 | [diff] [blame] | 631 | free_note_data(&d); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 632 | free_notes(t); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int show(int argc, const char **argv, const char *prefix) |
| 637 | { |
| 638 | const char *object_ref; |
| 639 | struct notes_tree *t; |
| 640 | unsigned char object[20]; |
| 641 | const unsigned char *note; |
| 642 | int retval; |
| 643 | struct option options[] = { |
| 644 | OPT_END() |
| 645 | }; |
| 646 | |
| 647 | argc = parse_options(argc, argv, prefix, options, git_notes_show_usage, |
| 648 | 0); |
| 649 | |
| 650 | if (1 < argc) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 651 | error(_("too many parameters")); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 652 | usage_with_options(git_notes_show_usage, options); |
| 653 | } |
| 654 | |
| 655 | object_ref = argc ? argv[0] : "HEAD"; |
| 656 | |
| 657 | if (get_sha1(object_ref, object)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 658 | die(_("failed to resolve '%s' as a valid ref."), object_ref); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 659 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 660 | t = init_notes_check("show", 0); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 661 | note = get_note(t, object); |
| 662 | |
| 663 | if (!note) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 664 | retval = error(_("no note found for object %s."), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 665 | sha1_to_hex(object)); |
| 666 | else { |
| 667 | const char *show_args[3] = {"show", sha1_to_hex(note), NULL}; |
| 668 | retval = execv_git_cmd(show_args); |
| 669 | } |
| 670 | free_notes(t); |
| 671 | return retval; |
| 672 | } |
| 673 | |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 674 | static int merge_abort(struct notes_merge_options *o) |
| 675 | { |
| 676 | int ret = 0; |
| 677 | |
| 678 | /* |
| 679 | * Remove .git/NOTES_MERGE_PARTIAL and .git/NOTES_MERGE_REF, and call |
| 680 | * notes_merge_abort() to remove .git/NOTES_MERGE_WORKTREE. |
| 681 | */ |
| 682 | |
Kyle Meyer | 755b49a | 2017-02-20 20:10:32 -0500 | [diff] [blame] | 683 | if (delete_ref(NULL, "NOTES_MERGE_PARTIAL", NULL, 0)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 684 | ret += error(_("failed to delete ref NOTES_MERGE_PARTIAL")); |
Kyle Meyer | 755b49a | 2017-02-20 20:10:32 -0500 | [diff] [blame] | 685 | if (delete_ref(NULL, "NOTES_MERGE_REF", NULL, REF_NODEREF)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 686 | ret += error(_("failed to delete ref NOTES_MERGE_REF")); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 687 | if (notes_merge_abort(o)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 688 | ret += error(_("failed to remove 'git notes merge' worktree")); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 689 | return ret; |
| 690 | } |
| 691 | |
| 692 | static int merge_commit(struct notes_merge_options *o) |
| 693 | { |
| 694 | struct strbuf msg = STRBUF_INIT; |
brian m. carlson | 2928325 | 2017-02-21 23:47:29 +0000 | [diff] [blame] | 695 | struct object_id oid, parent_oid; |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 696 | struct notes_tree *t; |
| 697 | struct commit *partial; |
| 698 | struct pretty_print_context pretty_ctx; |
Nguyễn Thái Ngọc Duy | 96ec7b1 | 2011-12-13 21:17:48 +0700 | [diff] [blame] | 699 | void *local_ref_to_free; |
Nguyễn Thái Ngọc Duy | d5a35c1 | 2011-11-13 17:22:15 +0700 | [diff] [blame] | 700 | int ret; |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 701 | |
| 702 | /* |
| 703 | * Read partial merge result from .git/NOTES_MERGE_PARTIAL, |
| 704 | * and target notes ref from .git/NOTES_MERGE_REF. |
| 705 | */ |
| 706 | |
brian m. carlson | 2928325 | 2017-02-21 23:47:29 +0000 | [diff] [blame] | 707 | if (get_oid("NOTES_MERGE_PARTIAL", &oid)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 708 | die(_("failed to read ref NOTES_MERGE_PARTIAL")); |
brian m. carlson | 2928325 | 2017-02-21 23:47:29 +0000 | [diff] [blame] | 709 | else if (!(partial = lookup_commit_reference(oid.hash))) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 710 | die(_("could not find commit from NOTES_MERGE_PARTIAL.")); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 711 | else if (parse_commit(partial)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 712 | die(_("could not parse commit from NOTES_MERGE_PARTIAL.")); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 713 | |
Johan Herland | 6cfd6a9 | 2010-11-09 22:49:54 +0100 | [diff] [blame] | 714 | if (partial->parents) |
brian m. carlson | 2928325 | 2017-02-21 23:47:29 +0000 | [diff] [blame] | 715 | oidcpy(&parent_oid, &partial->parents->item->object.oid); |
Johan Herland | 6cfd6a9 | 2010-11-09 22:49:54 +0100 | [diff] [blame] | 716 | else |
brian m. carlson | 2928325 | 2017-02-21 23:47:29 +0000 | [diff] [blame] | 717 | oidclr(&parent_oid); |
Johan Herland | 6cfd6a9 | 2010-11-09 22:49:54 +0100 | [diff] [blame] | 718 | |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 719 | t = xcalloc(1, sizeof(struct notes_tree)); |
| 720 | init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0); |
| 721 | |
Nguyễn Thái Ngọc Duy | 96ec7b1 | 2011-12-13 21:17:48 +0700 | [diff] [blame] | 722 | o->local_ref = local_ref_to_free = |
brian m. carlson | 2928325 | 2017-02-21 23:47:29 +0000 | [diff] [blame] | 723 | resolve_refdup("NOTES_MERGE_REF", 0, oid.hash, NULL); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 724 | if (!o->local_ref) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 725 | die(_("failed to resolve NOTES_MERGE_REF")); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 726 | |
brian m. carlson | 2928325 | 2017-02-21 23:47:29 +0000 | [diff] [blame] | 727 | if (notes_merge_commit(o, t, partial, oid.hash)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 728 | die(_("failed to finalize notes merge")); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 729 | |
| 730 | /* Reuse existing commit message in reflog message */ |
| 731 | memset(&pretty_ctx, 0, sizeof(pretty_ctx)); |
| 732 | format_commit_message(partial, "%s", &msg, &pretty_ctx); |
| 733 | strbuf_trim(&msg); |
| 734 | strbuf_insert(&msg, 0, "notes: ", 7); |
brian m. carlson | 2928325 | 2017-02-21 23:47:29 +0000 | [diff] [blame] | 735 | update_ref(msg.buf, o->local_ref, oid.hash, |
| 736 | is_null_oid(&parent_oid) ? NULL : parent_oid.hash, |
Michael Haggerty | f412411 | 2014-04-07 15:47:56 +0200 | [diff] [blame] | 737 | 0, UPDATE_REFS_DIE_ON_ERR); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 738 | |
| 739 | free_notes(t); |
| 740 | strbuf_release(&msg); |
Nguyễn Thái Ngọc Duy | d5a35c1 | 2011-11-13 17:22:15 +0700 | [diff] [blame] | 741 | ret = merge_abort(o); |
Nguyễn Thái Ngọc Duy | 96ec7b1 | 2011-12-13 21:17:48 +0700 | [diff] [blame] | 742 | free(local_ref_to_free); |
Nguyễn Thái Ngọc Duy | d5a35c1 | 2011-11-13 17:22:15 +0700 | [diff] [blame] | 743 | return ret; |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 744 | } |
| 745 | |
Jacob Keller | d2d68d9 | 2015-08-17 14:33:33 -0700 | [diff] [blame] | 746 | static int git_config_get_notes_strategy(const char *key, |
| 747 | enum notes_merge_strategy *strategy) |
| 748 | { |
Stefan Beller | 344b548 | 2016-03-31 17:35:43 -0700 | [diff] [blame] | 749 | char *value; |
Jacob Keller | d2d68d9 | 2015-08-17 14:33:33 -0700 | [diff] [blame] | 750 | |
Stefan Beller | 344b548 | 2016-03-31 17:35:43 -0700 | [diff] [blame] | 751 | if (git_config_get_string(key, &value)) |
Jacob Keller | d2d68d9 | 2015-08-17 14:33:33 -0700 | [diff] [blame] | 752 | return 1; |
| 753 | if (parse_notes_merge_strategy(value, strategy)) |
Vasco Almeida | 5313827 | 2016-06-17 20:21:14 +0000 | [diff] [blame] | 754 | git_die_config(key, _("unknown notes merge strategy %s"), value); |
Jacob Keller | d2d68d9 | 2015-08-17 14:33:33 -0700 | [diff] [blame] | 755 | |
Stefan Beller | 344b548 | 2016-03-31 17:35:43 -0700 | [diff] [blame] | 756 | free(value); |
Jacob Keller | d2d68d9 | 2015-08-17 14:33:33 -0700 | [diff] [blame] | 757 | return 0; |
| 758 | } |
| 759 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 760 | static int merge(int argc, const char **argv, const char *prefix) |
| 761 | { |
| 762 | struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT; |
| 763 | unsigned char result_sha1[20]; |
Johan Herland | 2085b16 | 2010-11-15 00:54:11 +0100 | [diff] [blame] | 764 | struct notes_tree *t; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 765 | struct notes_merge_options o; |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 766 | int do_merge = 0, do_commit = 0, do_abort = 0; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 767 | int verbosity = 0, result; |
Johan Herland | 3228e67 | 2010-11-15 00:55:12 +0100 | [diff] [blame] | 768 | const char *strategy = NULL; |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 769 | struct option options[] = { |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 770 | OPT_GROUP(N_("General options")), |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 771 | OPT__VERBOSITY(&verbosity), |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 772 | OPT_GROUP(N_("Merge options")), |
| 773 | OPT_STRING('s', "strategy", &strategy, N_("strategy"), |
| 774 | N_("resolve notes conflicts using the given strategy " |
| 775 | "(manual/ours/theirs/union/cat_sort_uniq)")), |
| 776 | OPT_GROUP(N_("Committing unmerged notes")), |
Stefan Beller | 4741edd | 2013-08-03 13:51:18 +0200 | [diff] [blame] | 777 | { OPTION_SET_INT, 0, "commit", &do_commit, NULL, |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 778 | N_("finalize notes merge by committing unmerged notes"), |
Stefan Beller | 4741edd | 2013-08-03 13:51:18 +0200 | [diff] [blame] | 779 | PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1}, |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 780 | OPT_GROUP(N_("Aborting notes merge resolution")), |
Stefan Beller | 4741edd | 2013-08-03 13:51:18 +0200 | [diff] [blame] | 781 | { OPTION_SET_INT, 0, "abort", &do_abort, NULL, |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 782 | N_("abort notes merge"), |
Stefan Beller | 4741edd | 2013-08-03 13:51:18 +0200 | [diff] [blame] | 783 | PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1}, |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 784 | OPT_END() |
| 785 | }; |
| 786 | |
| 787 | argc = parse_options(argc, argv, prefix, options, |
| 788 | git_notes_merge_usage, 0); |
| 789 | |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 790 | if (strategy || do_commit + do_abort == 0) |
| 791 | do_merge = 1; |
| 792 | if (do_merge + do_commit + do_abort != 1) { |
Vasco Almeida | 5313827 | 2016-06-17 20:21:14 +0000 | [diff] [blame] | 793 | error(_("cannot mix --commit, --abort or -s/--strategy")); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 794 | usage_with_options(git_notes_merge_usage, options); |
| 795 | } |
| 796 | |
| 797 | if (do_merge && argc != 1) { |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 798 | error(_("must specify a notes ref to merge")); |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 799 | usage_with_options(git_notes_merge_usage, options); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 800 | } else if (!do_merge && argc) { |
Vasco Almeida | 5313827 | 2016-06-17 20:21:14 +0000 | [diff] [blame] | 801 | error(_("too many parameters")); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 802 | usage_with_options(git_notes_merge_usage, options); |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | init_notes_merge_options(&o); |
| 806 | o.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT; |
| 807 | |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 808 | if (do_abort) |
| 809 | return merge_abort(&o); |
| 810 | if (do_commit) |
| 811 | return merge_commit(&o); |
| 812 | |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 813 | o.local_ref = default_notes_ref(); |
| 814 | strbuf_addstr(&remote_ref, argv[0]); |
Jacob Keller | b3715b7 | 2015-12-29 14:40:28 -0800 | [diff] [blame] | 815 | expand_loose_notes_ref(&remote_ref); |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 816 | o.remote_ref = remote_ref.buf; |
| 817 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 818 | t = init_notes_check("merge", NOTES_INIT_WRITABLE); |
Jacob Keller | d2d68d9 | 2015-08-17 14:33:33 -0700 | [diff] [blame] | 819 | |
Johan Herland | 3228e67 | 2010-11-15 00:55:12 +0100 | [diff] [blame] | 820 | if (strategy) { |
Jacob Keller | 93efcad | 2015-08-17 14:33:31 -0700 | [diff] [blame] | 821 | if (parse_notes_merge_strategy(strategy, &o.strategy)) { |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 822 | error(_("unknown -s/--strategy: %s"), strategy); |
Johan Herland | 3228e67 | 2010-11-15 00:55:12 +0100 | [diff] [blame] | 823 | usage_with_options(git_notes_merge_usage, options); |
| 824 | } |
Jacob Keller | d2d68d9 | 2015-08-17 14:33:33 -0700 | [diff] [blame] | 825 | } else { |
Jacob Keller | 4f655e2 | 2015-08-17 14:33:34 -0700 | [diff] [blame] | 826 | struct strbuf merge_key = STRBUF_INIT; |
| 827 | const char *short_ref = NULL; |
Johan Herland | 3228e67 | 2010-11-15 00:55:12 +0100 | [diff] [blame] | 828 | |
Jacob Keller | 4f655e2 | 2015-08-17 14:33:34 -0700 | [diff] [blame] | 829 | if (!skip_prefix(o.local_ref, "refs/notes/", &short_ref)) |
| 830 | die("BUG: local ref %s is outside of refs/notes/", |
| 831 | o.local_ref); |
| 832 | |
| 833 | strbuf_addf(&merge_key, "notes.%s.mergeStrategy", short_ref); |
| 834 | |
| 835 | if (git_config_get_notes_strategy(merge_key.buf, &o.strategy)) |
| 836 | git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy); |
| 837 | |
| 838 | strbuf_release(&merge_key); |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 839 | } |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 840 | |
| 841 | strbuf_addf(&msg, "notes: Merged notes from %s into %s", |
| 842 | remote_ref.buf, default_notes_ref()); |
Johan Herland | 443259c | 2010-11-09 22:49:53 +0100 | [diff] [blame] | 843 | strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */ |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 844 | |
| 845 | result = notes_merge(&o, t, result_sha1); |
| 846 | |
| 847 | if (result >= 0) /* Merge resulted (trivially) in result_sha1 */ |
| 848 | /* Update default notes ref with new commit */ |
| 849 | update_ref(msg.buf, default_notes_ref(), result_sha1, NULL, |
Michael Haggerty | f412411 | 2014-04-07 15:47:56 +0200 | [diff] [blame] | 850 | 0, UPDATE_REFS_DIE_ON_ERR); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 851 | else { /* Merge has unresolved conflicts */ |
Nguyễn Thái Ngọc Duy | d3b9ac0 | 2016-04-22 20:01:27 +0700 | [diff] [blame] | 852 | const struct worktree *wt; |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 853 | /* Update .git/NOTES_MERGE_PARTIAL with partial merge result */ |
| 854 | update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL, |
Michael Haggerty | f412411 | 2014-04-07 15:47:56 +0200 | [diff] [blame] | 855 | 0, UPDATE_REFS_DIE_ON_ERR); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 856 | /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */ |
Nguyễn Thái Ngọc Duy | d3b9ac0 | 2016-04-22 20:01:27 +0700 | [diff] [blame] | 857 | wt = find_shared_symref("NOTES_MERGE_REF", default_notes_ref()); |
| 858 | if (wt) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 859 | die(_("a notes merge into %s is already in-progress at %s"), |
Nguyễn Thái Ngọc Duy | d3b9ac0 | 2016-04-22 20:01:27 +0700 | [diff] [blame] | 860 | default_notes_ref(), wt->path); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 861 | if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL)) |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 862 | die(_("failed to store link to current notes ref (%s)"), |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 863 | default_notes_ref()); |
Vasco Almeida | 5313827 | 2016-06-17 20:21:14 +0000 | [diff] [blame] | 864 | printf(_("Automatic notes merge failed. Fix conflicts in %s and " |
| 865 | "commit the result with 'git notes merge --commit', or " |
| 866 | "abort the merge with 'git notes merge --abort'.\n"), |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 867 | git_path(NOTES_MERGE_WORKTREE)); |
Johan Herland | 6abb365 | 2010-11-09 22:49:52 +0100 | [diff] [blame] | 868 | } |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 869 | |
| 870 | free_notes(t); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 871 | strbuf_release(&remote_ref); |
| 872 | strbuf_release(&msg); |
Johan Herland | 809f38c | 2010-11-09 22:49:51 +0100 | [diff] [blame] | 873 | return result < 0; /* return non-zero on conflicts */ |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 874 | } |
| 875 | |
Junio C Hamano | 4653801 | 2011-05-18 16:44:30 -0700 | [diff] [blame] | 876 | #define IGNORE_MISSING 1 |
Junio C Hamano | 2d370d2 | 2011-05-18 16:02:58 -0700 | [diff] [blame] | 877 | |
| 878 | static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag) |
Junio C Hamano | c3ab1a8 | 2011-05-18 15:44:37 -0700 | [diff] [blame] | 879 | { |
| 880 | int status; |
| 881 | unsigned char sha1[20]; |
| 882 | if (get_sha1(name, sha1)) |
| 883 | return error(_("Failed to resolve '%s' as a valid ref."), name); |
| 884 | status = remove_note(t, sha1); |
| 885 | if (status) |
| 886 | fprintf(stderr, _("Object %s has no note\n"), name); |
| 887 | else |
| 888 | fprintf(stderr, _("Removing note for object %s\n"), name); |
Junio C Hamano | 4653801 | 2011-05-18 16:44:30 -0700 | [diff] [blame] | 889 | return (flag & IGNORE_MISSING) ? 0 : status; |
Junio C Hamano | c3ab1a8 | 2011-05-18 15:44:37 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 892 | static int remove_cmd(int argc, const char **argv, const char *prefix) |
| 893 | { |
Junio C Hamano | 2d370d2 | 2011-05-18 16:02:58 -0700 | [diff] [blame] | 894 | unsigned flag = 0; |
Junio C Hamano | 4653801 | 2011-05-18 16:44:30 -0700 | [diff] [blame] | 895 | int from_stdin = 0; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 896 | struct option options[] = { |
Junio C Hamano | 2d370d2 | 2011-05-18 16:02:58 -0700 | [diff] [blame] | 897 | OPT_BIT(0, "ignore-missing", &flag, |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 898 | N_("attempt to remove non-existent note is not an error"), |
Junio C Hamano | 4653801 | 2011-05-18 16:44:30 -0700 | [diff] [blame] | 899 | IGNORE_MISSING), |
Stefan Beller | d5d09d4 | 2013-08-03 13:51:19 +0200 | [diff] [blame] | 900 | OPT_BOOL(0, "stdin", &from_stdin, |
Nguyễn Thái Ngọc Duy | e6b895e | 2012-08-20 19:32:28 +0700 | [diff] [blame] | 901 | N_("read object names from the standard input")), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 902 | OPT_END() |
| 903 | }; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 904 | struct notes_tree *t; |
Junio C Hamano | c3ab1a8 | 2011-05-18 15:44:37 -0700 | [diff] [blame] | 905 | int retval = 0; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 906 | |
| 907 | argc = parse_options(argc, argv, prefix, options, |
| 908 | git_notes_remove_usage, 0); |
| 909 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 910 | t = init_notes_check("remove", NOTES_INIT_WRITABLE); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 911 | |
Junio C Hamano | 4653801 | 2011-05-18 16:44:30 -0700 | [diff] [blame] | 912 | if (!argc && !from_stdin) { |
Junio C Hamano | 2d370d2 | 2011-05-18 16:02:58 -0700 | [diff] [blame] | 913 | retval = remove_one_note(t, "HEAD", flag); |
Junio C Hamano | c3ab1a8 | 2011-05-18 15:44:37 -0700 | [diff] [blame] | 914 | } else { |
| 915 | while (*argv) { |
Junio C Hamano | 2d370d2 | 2011-05-18 16:02:58 -0700 | [diff] [blame] | 916 | retval |= remove_one_note(t, *argv, flag); |
Junio C Hamano | c3ab1a8 | 2011-05-18 15:44:37 -0700 | [diff] [blame] | 917 | argv++; |
| 918 | } |
Johan Herland | 1ee1e43 | 2010-08-31 17:56:50 +0200 | [diff] [blame] | 919 | } |
Junio C Hamano | 4653801 | 2011-05-18 16:44:30 -0700 | [diff] [blame] | 920 | if (from_stdin) { |
| 921 | struct strbuf sb = STRBUF_INIT; |
| 922 | while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) { |
| 923 | strbuf_rtrim(&sb); |
| 924 | retval |= remove_one_note(t, sb.buf, flag); |
| 925 | } |
| 926 | strbuf_release(&sb); |
| 927 | } |
Junio C Hamano | c3ab1a8 | 2011-05-18 15:44:37 -0700 | [diff] [blame] | 928 | if (!retval) |
| 929 | commit_notes(t, "Notes removed by 'git notes remove'"); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 930 | free_notes(t); |
Johan Herland | 1ee1e43 | 2010-08-31 17:56:50 +0200 | [diff] [blame] | 931 | return retval; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | static int prune(int argc, const char **argv, const char *prefix) |
| 935 | { |
| 936 | struct notes_tree *t; |
Michael J Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 937 | int show_only = 0, verbose = 0; |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 938 | struct option options[] = { |
Vasco Almeida | b34c77e | 2016-06-17 20:21:15 +0000 | [diff] [blame] | 939 | OPT__DRY_RUN(&show_only, N_("do not remove, show only")), |
| 940 | OPT__VERBOSE(&verbose, N_("report pruned notes")), |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 941 | OPT_END() |
| 942 | }; |
| 943 | |
| 944 | argc = parse_options(argc, argv, prefix, options, git_notes_prune_usage, |
| 945 | 0); |
| 946 | |
| 947 | if (argc) { |
Ævar Arnfjörð Bjarmason | caeba0e | 2011-02-22 23:42:26 +0000 | [diff] [blame] | 948 | error(_("too many parameters")); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 949 | usage_with_options(git_notes_prune_usage, options); |
| 950 | } |
| 951 | |
Mike Hommey | ee76f92 | 2015-10-08 11:54:43 +0900 | [diff] [blame] | 952 | t = init_notes_check("prune", NOTES_INIT_WRITABLE); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 953 | |
Michael J Gruber | a9f2adf | 2010-05-14 23:42:07 +0200 | [diff] [blame] | 954 | prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) | |
| 955 | (show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) ); |
| 956 | if (!show_only) |
| 957 | commit_notes(t, "Notes removed by 'git notes prune'"); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 958 | free_notes(t); |
| 959 | return 0; |
| 960 | } |
| 961 | |
Johan Herland | 618cd75 | 2010-11-09 22:49:57 +0100 | [diff] [blame] | 962 | static int get_ref(int argc, const char **argv, const char *prefix) |
| 963 | { |
| 964 | struct option options[] = { OPT_END() }; |
| 965 | argc = parse_options(argc, argv, prefix, options, |
| 966 | git_notes_get_ref_usage, 0); |
| 967 | |
| 968 | if (argc) { |
Vasco Almeida | 5313827 | 2016-06-17 20:21:14 +0000 | [diff] [blame] | 969 | error(_("too many parameters")); |
Johan Herland | 618cd75 | 2010-11-09 22:49:57 +0100 | [diff] [blame] | 970 | usage_with_options(git_notes_get_ref_usage, options); |
| 971 | } |
| 972 | |
| 973 | puts(default_notes_ref()); |
| 974 | return 0; |
| 975 | } |
| 976 | |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 977 | int cmd_notes(int argc, const char **argv, const char *prefix) |
| 978 | { |
| 979 | int result; |
| 980 | const char *override_notes_ref = NULL; |
| 981 | struct option options[] = { |
Junio C Hamano | e703d71 | 2014-03-23 15:58:12 -0700 | [diff] [blame] | 982 | OPT_STRING(0, "ref", &override_notes_ref, N_("notes-ref"), |
Alex Henrie | 9c9b4f2 | 2015-01-13 00:44:47 -0700 | [diff] [blame] | 983 | N_("use notes from <notes-ref>")), |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 984 | OPT_END() |
| 985 | }; |
| 986 | |
| 987 | git_config(git_default_config, NULL); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 988 | argc = parse_options(argc, argv, prefix, options, git_notes_usage, |
| 989 | PARSE_OPT_STOP_AT_NON_OPTION); |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 990 | |
Thomas Rast | dcf783a | 2010-03-12 18:04:35 +0100 | [diff] [blame] | 991 | if (override_notes_ref) { |
| 992 | struct strbuf sb = STRBUF_INIT; |
Thomas Rast | dcf783a | 2010-03-12 18:04:35 +0100 | [diff] [blame] | 993 | strbuf_addstr(&sb, override_notes_ref); |
Johan Herland | 8ef313e | 2010-11-09 22:49:45 +0100 | [diff] [blame] | 994 | expand_notes_ref(&sb); |
Thomas Rast | dcf783a | 2010-03-12 18:04:35 +0100 | [diff] [blame] | 995 | setenv("GIT_NOTES_REF", sb.buf, 1); |
| 996 | strbuf_release(&sb); |
| 997 | } |
| 998 | |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 999 | if (argc < 1 || !strcmp(argv[0], "list")) |
| 1000 | result = list(argc, argv, prefix); |
| 1001 | else if (!strcmp(argv[0], "add")) |
| 1002 | result = add(argc, argv, prefix); |
| 1003 | else if (!strcmp(argv[0], "copy")) |
| 1004 | result = copy(argc, argv, prefix); |
| 1005 | else if (!strcmp(argv[0], "append") || !strcmp(argv[0], "edit")) |
| 1006 | result = append_edit(argc, argv, prefix); |
| 1007 | else if (!strcmp(argv[0], "show")) |
| 1008 | result = show(argc, argv, prefix); |
Johan Herland | 75ef3f4 | 2010-11-09 22:49:46 +0100 | [diff] [blame] | 1009 | else if (!strcmp(argv[0], "merge")) |
| 1010 | result = merge(argc, argv, prefix); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 1011 | else if (!strcmp(argv[0], "remove")) |
| 1012 | result = remove_cmd(argc, argv, prefix); |
| 1013 | else if (!strcmp(argv[0], "prune")) |
| 1014 | result = prune(argc, argv, prefix); |
Johan Herland | 618cd75 | 2010-11-09 22:49:57 +0100 | [diff] [blame] | 1015 | else if (!strcmp(argv[0], "get-ref")) |
| 1016 | result = get_ref(argc, argv, prefix); |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 1017 | else { |
Vasco Almeida | 8d79589 | 2016-09-15 14:59:04 +0000 | [diff] [blame] | 1018 | result = error(_("unknown subcommand: %s"), argv[0]); |
Johan Herland | 92b3385 | 2010-02-13 22:28:25 +0100 | [diff] [blame] | 1019 | usage_with_options(git_notes_usage, options); |
| 1020 | } |
| 1021 | |
Stephen Boyd | 74884b5 | 2010-02-27 00:59:22 -0800 | [diff] [blame] | 1022 | return result ? 1 : 0; |
Johan Herland | cd067d3 | 2010-02-13 22:28:20 +0100 | [diff] [blame] | 1023 | } |