Bug Summary

File:builtin/notes.c
Location:line 1019, column 3
Description:Value stored to 'result' is never read

Annotated Source Code

1/*
2 * Builtin "git notes"
3 *
4 * Copyright (c) 2010 Johan Herland <johan@herland.net>
5 *
6 * Based on git-notes.sh by Johannes Schindelin,
7 * and builtin/tag.c by Kristian Høgsberg and Carlos Rica.
8 */
9
10#include "cache.h"
11#include "builtin.h"
12#include "notes.h"
13#include "blob.h"
14#include "commit.h"
15#include "refs.h"
16#include "exec_cmd.h"
17#include "run-command.h"
18#include "parse-options.h"
19#include "string-list.h"
20#include "notes-merge.h"
21#include "notes-utils.h"
22#include "worktree.h"
23
24static const char * const git_notes_usage[] = {
25 N_("git notes [--ref <notes-ref>] [list [<object>]]")("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>]")("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>")("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>]")("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>]")("git notes [--ref <notes-ref>] edit [--allow-empty] [<object>]"
)
,
30 N_("git notes [--ref <notes-ref>] show [<object>]")("git notes [--ref <notes-ref>] show [<object>]"),
31 N_("git notes [--ref <notes-ref>] merge [-v | -q] [-s <strategy>] <notes-ref>")("git notes [--ref <notes-ref>] merge [-v | -q] [-s <strategy>] <notes-ref>"
)
,
32 N_("git notes merge --commit [-v | -q]")("git notes merge --commit [-v | -q]"),
33 N_("git notes merge --abort [-v | -q]")("git notes merge --abort [-v | -q]"),
34 N_("git notes [--ref <notes-ref>] remove [<object>...]")("git notes [--ref <notes-ref>] remove [<object>...]"
)
,
35 N_("git notes [--ref <notes-ref>] prune [-n | -v]")("git notes [--ref <notes-ref>] prune [-n | -v]"),
36 N_("git notes [--ref <notes-ref>] get-ref")("git notes [--ref <notes-ref>] get-ref"),
37 NULL((void*)0)
38};
39
40static const char * const git_notes_list_usage[] = {
41 N_("git notes [list [<object>]]")("git notes [list [<object>]]"),
42 NULL((void*)0)
43};
44
45static const char * const git_notes_add_usage[] = {
46 N_("git notes add [<options>] [<object>]")("git notes add [<options>] [<object>]"),
47 NULL((void*)0)
48};
49
50static const char * const git_notes_copy_usage[] = {
51 N_("git notes copy [<options>] <from-object> <to-object>")("git notes copy [<options>] <from-object> <to-object>"
)
,
52 N_("git notes copy --stdin [<from-object> <to-object>]...")("git notes copy --stdin [<from-object> <to-object>]..."
)
,
53 NULL((void*)0)
54};
55
56static const char * const git_notes_append_usage[] = {
57 N_("git notes append [<options>] [<object>]")("git notes append [<options>] [<object>]"),
58 NULL((void*)0)
59};
60
61static const char * const git_notes_edit_usage[] = {
62 N_("git notes edit [<object>]")("git notes edit [<object>]"),
63 NULL((void*)0)
64};
65
66static const char * const git_notes_show_usage[] = {
67 N_("git notes show [<object>]")("git notes show [<object>]"),
68 NULL((void*)0)
69};
70
71static const char * const git_notes_merge_usage[] = {
72 N_("git notes merge [<options>] <notes-ref>")("git notes merge [<options>] <notes-ref>"),
73 N_("git notes merge --commit [<options>]")("git notes merge --commit [<options>]"),
74 N_("git notes merge --abort [<options>]")("git notes merge --abort [<options>]"),
75 NULL((void*)0)
76};
77
78static const char * const git_notes_remove_usage[] = {
79 N_("git notes remove [<object>]")("git notes remove [<object>]"),
80 NULL((void*)0)
81};
82
83static const char * const git_notes_prune_usage[] = {
84 N_("git notes prune [<options>]")("git notes prune [<options>]"),
85 NULL((void*)0)
86};
87
88static const char * const git_notes_get_ref_usage[] = {
89 N_("git notes get-ref")("git notes get-ref"),
90 NULL((void*)0)
91};
92
93static const char note_template[] =
94 N_("Write/edit the notes for the following object:")("Write/edit the notes for the following object:");
95
96struct note_data {
97 int given;
98 int use_editor;
99 char *edit_path;
100 struct strbuf buf;
101};
102
103static 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
112static 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
120static void copy_obj_to_fd(int fd, const unsigned char *sha1)
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
132static 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((void*)0)};
136 struct child_process show = CHILD_PROCESS_INIT{ ((void*)0), { empty_argv, 0, 0 }, { empty_argv, 0, 0 } };
137 struct strbuf buf = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
138 struct strbuf cbuf = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
139
140 /* Invoke "git show --stat --no-notes $object" */
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))
147 die(_("unable to start 'show' for object '%s'"),
148 sha1_to_hex(object));
149
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);
154
155 strbuf_release(&cbuf);
156 strbuf_release(&buf);
157
158 if (finish_command(&show))
159 die(_("failed to finish 'show' for object '%s'"),
160 sha1_to_hex(object));
161}
162
163static void prepare_note_data(const unsigned char *object, struct note_data *d,
164 const unsigned char *old_note)
165{
166 if (d->use_editor || !d->given) {
167 int fd;
168 struct strbuf buf = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
169
170 /* write the template message before editing: */
171 d->edit_path = git_pathdup("NOTES_EDITMSG");
172 fd = open(d->edit_path, O_CREAT0x0200 | O_TRUNC0x0400 | O_WRONLY0x0001, 0600);
173 if (fd < 0)
174 die_errno(_("could not create file '%s'"), d->edit_path);
175
176 if (d->given)
177 write_or_die(fd, d->buf.buf, d->buf.len);
178 else if (old_note)
179 copy_obj_to_fd(fd, old_note);
180
181 strbuf_addch(&buf, '\n');
182 strbuf_add_commented_lines(&buf, "\n", strlen("\n"));
183 strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)));
184 strbuf_addch(&buf, '\n');
185 write_or_die(fd, buf.buf, buf.len);
186
187 write_commented_object(fd, object);
188
189 close(fd);
190 strbuf_release(&buf);
191 strbuf_reset(&d->buf)strbuf_setlen(&d->buf, 0);
192
193 if (launch_editor(d->edit_path, &d->buf, NULL((void*)0))) {
194 die(_("please supply the note contents using either -m or -F option"));
195 }
196 strbuf_stripspace(&d->buf, 1);
197 }
198}
199
200static 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"))(error(_("unable to write note object")), const_error());
204 if (d->edit_path)
205 error(_("the note contents have been left in %s"),(error(_("the note contents have been left in %s"), d->edit_path
), const_error())
206 d->edit_path)(error(_("the note contents have been left in %s"), d->edit_path
), const_error())
;
207 exit(128);
208 }
209}
210
211static int parse_msg_arg(const struct option *opt, const char *arg, int unset)
212{
213 struct note_data *d = opt->value;
214
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);
219 strbuf_stripspace(&d->buf, 0);
220
221 d->given = 1;
222 return 0;
223}
224
225static int parse_file_arg(const struct option *opt, const char *arg, int unset)
226{
227 struct note_data *d = opt->value;
228
229 if (d->buf.len)
230 strbuf_addch(&d->buf, '\n');
231 if (!strcmp(arg, "-")) {
232 if (strbuf_read(&d->buf, 0, 1024) < 0)
233 die_errno(_("cannot read '%s'"), arg);
234 } else if (strbuf_read_file(&d->buf, arg, 1024) < 0)
235 die_errno(_("could not open or read '%s'"), arg);
236 strbuf_stripspace(&d->buf, 0);
237
238 d->given = 1;
239 return 0;
240}
241
242static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
243{
244 struct note_data *d = opt->value;
245 char *buf;
246 unsigned char object[20];
247 enum object_type type;
248 unsigned long len;
249
250 if (d->buf.len)
251 strbuf_addch(&d->buf, '\n');
252
253 if (get_sha1(arg, object))
254 die(_("failed to resolve '%s' as a valid ref."), arg);
255 if (!(buf = read_sha1_file(object, &type, &len))) {
256 free(buf);
257 die(_("failed to read object '%s'."), arg);
258 }
259 if (type != OBJ_BLOB) {
260 free(buf);
261 die(_("cannot read note data from non-blob object '%s'."), arg);
262 }
263 strbuf_add(&d->buf, buf, len);
264 free(buf);
265
266 d->given = 1;
267 return 0;
268}
269
270static int parse_reedit_arg(const struct option *opt, const char *arg, int unset)
271{
272 struct note_data *d = opt->value;
273 d->use_editor = 1;
274 return parse_reuse_arg(opt, arg, unset);
275}
276
277static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
278{
279 struct strbuf buf = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
280 struct notes_rewrite_cfg *c = NULL((void*)0);
281 struct notes_tree *t = NULL((void*)0);
282 int ret = 0;
283 const char *msg = "Notes added by 'git notes copy'";
284
285 if (rewrite_cmd) {
286 c = init_copy_notes_for_rewrite(rewrite_cmd);
287 if (!c)
288 return 0;
289 } else {
290 init_notes(NULL((void*)0), NULL((void*)0), NULL((void*)0), NOTES_INIT_WRITABLE2);
291 t = &default_notes_tree;
292 }
293
294 while (strbuf_getline_lf(&buf, stdin__stdinp) != EOF(-1)) {
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])
301 die(_("malformed input line: '%s'."), buf.buf);
302 strbuf_rtrim(split[0]);
303 strbuf_rtrim(split[1]);
304 if (get_sha1(split[0]->buf, from_obj))
305 die(_("failed to resolve '%s' as a valid ref."), split[0]->buf);
306 if (get_sha1(split[1]->buf, to_obj))
307 die(_("failed to resolve '%s' as a valid ref."), split[1]->buf);
308
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);
314
315 if (err) {
316 error(_("failed to copy notes from '%s' to '%s'"),(error(_("failed to copy notes from '%s' to '%s'"), split[0]->
buf, split[1]->buf), const_error())
317 split[0]->buf, split[1]->buf)(error(_("failed to copy notes from '%s' to '%s'"), split[0]->
buf, split[1]->buf), const_error())
;
318 ret = 1;
319 }
320
321 strbuf_list_free(split);
322 }
323
324 if (!rewrite_cmd) {
325 commit_notes(t, msg);
326 free_notes(t);
327 } else {
328 finish_copy_notes_for_rewrite(c, msg);
329 }
330 return ret;
331}
332
333static struct notes_tree *init_notes_check(const char *subcommand,
334 int flags)
335{
336 struct notes_tree *t;
337 const char *ref;
338 init_notes(NULL((void*)0), NULL((void*)0), NULL((void*)0), flags);
339 t = &default_notes_tree;
340
341 ref = (flags & NOTES_INIT_WRITABLE2) ? t->update_ref : t->ref;
342 if (!starts_with(ref, "refs/notes/"))
343 /* TRANSLATORS: the first %s will be replaced by a
344 git notes command: 'add', 'merge', 'remove', etc.*/
345 die(_("refusing to %s notes in %s (outside of refs/notes/)"),
346 subcommand, ref);
347 return t;
348}
349
350static 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;
356 struct option options[] = {
357 OPT_END(){ OPTION_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) {
365 error(_("too many parameters"))(error(_("too many parameters")), const_error());
366 usage_with_options(git_notes_list_usage, options);
367 }
368
369 t = init_notes_check("list", 0);
370 if (argc) {
371 if (get_sha1(argv[0], object))
372 die(_("failed to resolve '%s' as a valid ref."), argv[0]);
373 note = get_note(t, object);
374 if (note) {
375 puts(sha1_to_hex(note));
376 retval = 0;
377 } else
378 retval = error(_("no note found for object %s."),(error(_("no note found for object %s."), sha1_to_hex(object)
), const_error())
379 sha1_to_hex(object))(error(_("no note found for object %s."), sha1_to_hex(object)
), const_error())
;
380 } else
381 retval = for_each_note(t, 0, list_each_note, NULL((void*)0));
382
383 free_notes(t);
384 return retval;
385}
386
387static int append_edit(int argc, const char **argv, const char *prefix);
388
389static int add(int argc, const char **argv, const char *prefix)
390{
391 int force = 0, allow_empty = 0;
392 const char *object_ref;
393 struct notes_tree *t;
394 unsigned char object[20], new_note[20];
395 const unsigned char *note;
396 struct note_data d = { 0, 0, NULL((void*)0), STRBUF_INIT{ 0, 0, strbuf_slopbuf } };
397 struct option options[] = {
398 { OPTION_CALLBACK, 'm', "message", &d, N_("message")("message"),
399 N_("note contents as a string")("note contents as a string"), PARSE_OPT_NONEG,
400 parse_msg_arg},
401 { OPTION_CALLBACK, 'F', "file", &d, N_("file")("file"),
402 N_("note contents in a file")("note contents in a file"), PARSE_OPT_NONEG,
403 parse_file_arg},
404 { OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object")("object"),
405 N_("reuse and edit specified note object")("reuse and edit specified note object"), PARSE_OPT_NONEG,
406 parse_reedit_arg},
407 { OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object")("object"),
408 N_("reuse specified note object")("reuse specified note object"), PARSE_OPT_NONEG,
409 parse_reuse_arg},
410 OPT_BOOL(0, "allow-empty", &allow_empty,{ OPTION_SET_INT, (0), ("allow-empty"), (&allow_empty), (
(void*)0), (("allow storing empty note")), PARSE_OPT_NOARG, (
(void*)0), (1) }
411 N_("allow storing empty note")){ OPTION_SET_INT, (0), ("allow-empty"), (&allow_empty), (
(void*)0), (("allow storing empty note")), PARSE_OPT_NOARG, (
(void*)0), (1) }
,
412 OPT__FORCE(&force, N_("replace existing notes")){ OPTION_COUNTUP, ('f'), ("force"), ((&force)), ((void*)0
), ((("replace existing notes"))), PARSE_OPT_NOARG }
,
413 OPT_END(){ OPTION_END }
414 };
415
416 argc = parse_options(argc, argv, prefix, options, git_notes_add_usage,
417 PARSE_OPT_KEEP_ARGV0);
418
419 if (2 < argc) {
420 error(_("too many parameters"))(error(_("too many parameters")), const_error());
421 usage_with_options(git_notes_add_usage, options);
422 }
423
424 object_ref = argc > 1 ? argv[1] : "HEAD";
425
426 if (get_sha1(object_ref, object))
427 die(_("failed to resolve '%s' as a valid ref."), object_ref);
428
429 t = init_notes_check("add", NOTES_INIT_WRITABLE2);
430 note = get_note(t, object);
431
432 if (note) {
433 if (!force) {
434 free_notes(t);
435 if (d.given) {
436 free_note_data(&d);
437 return error(_("Cannot add notes. "(error(_("Cannot add notes. " "Found existing notes for object %s. "
"Use '-f' to overwrite existing notes"), sha1_to_hex(object)
), const_error())
438 "Found existing notes for object %s. "(error(_("Cannot add notes. " "Found existing notes for object %s. "
"Use '-f' to overwrite existing notes"), sha1_to_hex(object)
), const_error())
439 "Use '-f' to overwrite existing notes"),(error(_("Cannot add notes. " "Found existing notes for object %s. "
"Use '-f' to overwrite existing notes"), sha1_to_hex(object)
), const_error())
440 sha1_to_hex(object))(error(_("Cannot add notes. " "Found existing notes for object %s. "
"Use '-f' to overwrite existing notes"), sha1_to_hex(object)
), const_error())
;
441 }
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);
451 }
452 fprintf(stderr__stderrp, _("Overwriting existing notes for object %s\n"),
453 sha1_to_hex(object));
454 }
455
456 prepare_note_data(object, &d, note);
457 if (d.buf.len || allow_empty) {
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__stderrp, _("Removing note for object %s\n"),
464 sha1_to_hex(object));
465 remove_note(t, object);
466 commit_notes(t, "Notes removed by 'git notes add'");
467 }
468
469 free_note_data(&d);
470 free_notes(t);
471 return 0;
472}
473
474static 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((void*)0);
482 struct option options[] = {
483 OPT__FORCE(&force, N_("replace existing notes")){ OPTION_COUNTUP, ('f'), ("force"), ((&force)), ((void*)0
), ((("replace existing notes"))), PARSE_OPT_NOARG }
,
484 OPT_BOOL(0, "stdin", &from_stdin, N_("read objects from stdin")){ OPTION_SET_INT, (0), ("stdin"), (&from_stdin), ((void*)
0), (("read objects from stdin")), PARSE_OPT_NOARG, ((void*)0
), (1) }
,
485 OPT_STRING(0, "for-rewrite", &rewrite_cmd, N_("command"),{ OPTION_STRING, (0), ("for-rewrite"), (&rewrite_cmd), ((
"command")), (("load rewriting config for <command> (implies "
"--stdin)")) }
486 N_("load rewriting config for <command> (implies "{ OPTION_STRING, (0), ("for-rewrite"), (&rewrite_cmd), ((
"command")), (("load rewriting config for <command> (implies "
"--stdin)")) }
487 "--stdin)")){ OPTION_STRING, (0), ("for-rewrite"), (&rewrite_cmd), ((
"command")), (("load rewriting config for <command> (implies "
"--stdin)")) }
,
488 OPT_END(){ OPTION_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) {
496 error(_("too many parameters"))(error(_("too many parameters")), const_error());
497 usage_with_options(git_notes_copy_usage, options);
498 } else {
499 return notes_copy_from_stdin(force, rewrite_cmd);
500 }
501 }
502
503 if (argc < 2) {
504 error(_("too few parameters"))(error(_("too few parameters")), const_error());
505 usage_with_options(git_notes_copy_usage, options);
506 }
507 if (2 < argc) {
508 error(_("too many parameters"))(error(_("too many parameters")), const_error());
509 usage_with_options(git_notes_copy_usage, options);
510 }
511
512 if (get_sha1(argv[0], from_obj))
513 die(_("failed to resolve '%s' as a valid ref."), argv[0]);
514
515 object_ref = 1 < argc ? argv[1] : "HEAD";
516
517 if (get_sha1(object_ref, object))
518 die(_("failed to resolve '%s' as a valid ref."), object_ref);
519
520 t = init_notes_check("copy", NOTES_INIT_WRITABLE2);
521 note = get_note(t, object);
522
523 if (note) {
524 if (!force) {
525 retval = error(_("Cannot copy notes. Found existing "(error(_("Cannot copy notes. Found existing " "notes for object %s. Use '-f' to "
"overwrite existing notes"), sha1_to_hex(object)), const_error
())
526 "notes for object %s. Use '-f' to "(error(_("Cannot copy notes. Found existing " "notes for object %s. Use '-f' to "
"overwrite existing notes"), sha1_to_hex(object)), const_error
())
527 "overwrite existing notes"),(error(_("Cannot copy notes. Found existing " "notes for object %s. Use '-f' to "
"overwrite existing notes"), sha1_to_hex(object)), const_error
())
528 sha1_to_hex(object))(error(_("Cannot copy notes. Found existing " "notes for object %s. Use '-f' to "
"overwrite existing notes"), sha1_to_hex(object)), const_error
())
;
529 goto out;
530 }
531 fprintf(stderr__stderrp, _("Overwriting existing notes for object %s\n"),
532 sha1_to_hex(object));
533 }
534
535 from_note = get_note(t, from_obj);
536 if (!from_note) {
537 retval = error(_("missing notes on source object %s. Cannot "(error(_("missing notes on source object %s. Cannot " "copy."
), sha1_to_hex(from_obj)), const_error())
538 "copy."), sha1_to_hex(from_obj))(error(_("missing notes on source object %s. Cannot " "copy."
), sha1_to_hex(from_obj)), const_error())
;
539 goto out;
540 }
541
542 if (add_note(t, object, from_note, combine_notes_overwrite))
543 die("BUG: combine_notes_overwrite failed");
544 commit_notes(t, "Notes added by 'git notes copy'");
545out:
546 free_notes(t);
547 return retval;
548}
549
550static int append_edit(int argc, const char **argv, const char *prefix)
551{
552 int allow_empty = 0;
553 const char *object_ref;
554 struct notes_tree *t;
555 unsigned char object[20], new_note[20];
556 const unsigned char *note;
557 char logmsg[100];
558 const char * const *usage;
559 struct note_data d = { 0, 0, NULL((void*)0), STRBUF_INIT{ 0, 0, strbuf_slopbuf } };
560 struct option options[] = {
561 { OPTION_CALLBACK, 'm', "message", &d, N_("message")("message"),
562 N_("note contents as a string")("note contents as a string"), PARSE_OPT_NONEG,
563 parse_msg_arg},
564 { OPTION_CALLBACK, 'F', "file", &d, N_("file")("file"),
565 N_("note contents in a file")("note contents in a file"), PARSE_OPT_NONEG,
566 parse_file_arg},
567 { OPTION_CALLBACK, 'c', "reedit-message", &d, N_("object")("object"),
568 N_("reuse and edit specified note object")("reuse and edit specified note object"), PARSE_OPT_NONEG,
569 parse_reedit_arg},
570 { OPTION_CALLBACK, 'C', "reuse-message", &d, N_("object")("object"),
571 N_("reuse specified note object")("reuse specified note object"), PARSE_OPT_NONEG,
572 parse_reuse_arg},
573 OPT_BOOL(0, "allow-empty", &allow_empty,{ OPTION_SET_INT, (0), ("allow-empty"), (&allow_empty), (
(void*)0), (("allow storing empty note")), PARSE_OPT_NOARG, (
(void*)0), (1) }
574 N_("allow storing empty note")){ OPTION_SET_INT, (0), ("allow-empty"), (&allow_empty), (
(void*)0), (("allow storing empty note")), PARSE_OPT_NOARG, (
(void*)0), (1) }
,
575 OPT_END(){ OPTION_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) {
584 error(_("too many parameters"))(error(_("too many parameters")), const_error());
585 usage_with_options(usage, options);
586 }
587
588 if (d.given && edit)
589 fprintf(stderr__stderrp, _("The -m/-F/-c/-C options have been deprecated "
590 "for the 'edit' subcommand.\n"
591 "Please use 'git notes add -f -m/-F/-c/-C' instead.\n"));
592
593 object_ref = 1 < argc ? argv[1] : "HEAD";
594
595 if (get_sha1(object_ref, object))
596 die(_("failed to resolve '%s' as a valid ref."), object_ref);
597
598 t = init_notes_check(argv[0], NOTES_INIT_WRITABLE2);
599 note = get_note(t, object);
600
601 prepare_note_data(object, &d, edit ? note : NULL((void*)0));
602
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
617 if (d.buf.len || allow_empty) {
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");
621 snprintf(logmsg, sizeof(logmsg), "Notes added by 'git notes %s'",__builtin___snprintf_chk (logmsg, sizeof(logmsg), 0, __builtin_object_size
(logmsg, 2 > 1 ? 1 : 0), "Notes added by 'git notes %s'",
argv[0])
622 argv[0])__builtin___snprintf_chk (logmsg, sizeof(logmsg), 0, __builtin_object_size
(logmsg, 2 > 1 ? 1 : 0), "Notes added by 'git notes %s'",
argv[0])
;
623 } else {
624 fprintf(stderr__stderrp, _("Removing note for object %s\n"),
625 sha1_to_hex(object));
626 remove_note(t, object);
627 snprintf(logmsg, sizeof(logmsg), "Notes removed by 'git notes %s'",__builtin___snprintf_chk (logmsg, sizeof(logmsg), 0, __builtin_object_size
(logmsg, 2 > 1 ? 1 : 0), "Notes removed by 'git notes %s'"
, argv[0])
628 argv[0])__builtin___snprintf_chk (logmsg, sizeof(logmsg), 0, __builtin_object_size
(logmsg, 2 > 1 ? 1 : 0), "Notes removed by 'git notes %s'"
, argv[0])
;
629 }
630 commit_notes(t, logmsg);
631
632 free_note_data(&d);
633 free_notes(t);
634 return 0;
635}
636
637static int show(int argc, const char **argv, const char *prefix)
638{
639 const char *object_ref;
640 struct notes_tree *t;
641 unsigned char object[20];
642 const unsigned char *note;
643 int retval;
644 struct option options[] = {
645 OPT_END(){ OPTION_END }
646 };
647
648 argc = parse_options(argc, argv, prefix, options, git_notes_show_usage,
649 0);
650
651 if (1 < argc) {
652 error(_("too many parameters"))(error(_("too many parameters")), const_error());
653 usage_with_options(git_notes_show_usage, options);
654 }
655
656 object_ref = argc ? argv[0] : "HEAD";
657
658 if (get_sha1(object_ref, object))
659 die(_("failed to resolve '%s' as a valid ref."), object_ref);
660
661 t = init_notes_check("show", 0);
662 note = get_note(t, object);
663
664 if (!note)
665 retval = error(_("no note found for object %s."),(error(_("no note found for object %s."), sha1_to_hex(object)
), const_error())
666 sha1_to_hex(object))(error(_("no note found for object %s."), sha1_to_hex(object)
), const_error())
;
667 else {
668 const char *show_args[3] = {"show", sha1_to_hex(note), NULL((void*)0)};
669 retval = execv_git_cmd(show_args);
670 }
671 free_notes(t);
672 return retval;
673}
674
675static int merge_abort(struct notes_merge_options *o)
676{
677 int ret = 0;
678
679 /*
680 * Remove .git/NOTES_MERGE_PARTIAL and .git/NOTES_MERGE_REF, and call
681 * notes_merge_abort() to remove .git/NOTES_MERGE_WORKTREE.
682 */
683
684 if (delete_ref("NOTES_MERGE_PARTIAL", NULL((void*)0), 0))
685 ret += error(_("failed to delete ref NOTES_MERGE_PARTIAL"))(error(_("failed to delete ref NOTES_MERGE_PARTIAL")), const_error
())
;
686 if (delete_ref("NOTES_MERGE_REF", NULL((void*)0), REF_NODEREF0x01))
687 ret += error(_("failed to delete ref NOTES_MERGE_REF"))(error(_("failed to delete ref NOTES_MERGE_REF")), const_error
())
;
688 if (notes_merge_abort(o))
689 ret += error(_("failed to remove 'git notes merge' worktree"))(error(_("failed to remove 'git notes merge' worktree")), const_error
())
;
690 return ret;
691}
692
693static int merge_commit(struct notes_merge_options *o)
694{
695 struct strbuf msg = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
696 unsigned char sha1[20], parent_sha1[20];
697 struct notes_tree *t;
698 struct commit *partial;
699 struct pretty_print_context pretty_ctx;
700 void *local_ref_to_free;
701 int ret;
702
703 /*
704 * Read partial merge result from .git/NOTES_MERGE_PARTIAL,
705 * and target notes ref from .git/NOTES_MERGE_REF.
706 */
707
708 if (get_sha1("NOTES_MERGE_PARTIAL", sha1))
709 die(_("failed to read ref NOTES_MERGE_PARTIAL"));
710 else if (!(partial = lookup_commit_reference(sha1)))
711 die(_("could not find commit from NOTES_MERGE_PARTIAL."));
712 else if (parse_commit(partial))
713 die(_("could not parse commit from NOTES_MERGE_PARTIAL."));
714
715 if (partial->parents)
716 hashcpy(parent_sha1, partial->parents->item->object.oid.hash);
717 else
718 hashclr(parent_sha1);
719
720 t = xcalloc(1, sizeof(struct notes_tree));
721 init_notes(t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
722
723 o->local_ref = local_ref_to_free =
724 resolve_refdup("NOTES_MERGE_REF", 0, sha1, NULL((void*)0));
725 if (!o->local_ref)
726 die(_("failed to resolve NOTES_MERGE_REF"));
727
728 if (notes_merge_commit(o, t, partial, sha1))
729 die(_("failed to finalize notes merge"));
730
731 /* Reuse existing commit message in reflog message */
732 memset(&pretty_ctx, 0, sizeof(pretty_ctx))__builtin___memset_chk (&pretty_ctx, 0, sizeof(pretty_ctx
), __builtin_object_size (&pretty_ctx, 0))
;
733 format_commit_message(partial, "%s", &msg, &pretty_ctx);
734 strbuf_trim(&msg);
735 strbuf_insert(&msg, 0, "notes: ", 7);
736 update_ref(msg.buf, o->local_ref, sha1,
737 is_null_sha1(parent_sha1) ? NULL((void*)0) : parent_sha1,
738 0, UPDATE_REFS_DIE_ON_ERR);
739
740 free_notes(t);
741 strbuf_release(&msg);
742 ret = merge_abort(o);
743 free(local_ref_to_free);
744 return ret;
745}
746
747static int git_config_get_notes_strategy(const char *key,
748 enum notes_merge_strategy *strategy)
749{
750 char *value;
751
752 if (git_config_get_string(key, &value))
753 return 1;
754 if (parse_notes_merge_strategy(value, strategy))
755 git_die_config(key, _("unknown notes merge strategy %s"), value);
756
757 free(value);
758 return 0;
759}
760
761static int merge(int argc, const char **argv, const char *prefix)
762{
763 struct strbuf remote_ref = STRBUF_INIT{ 0, 0, strbuf_slopbuf }, msg = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
764 unsigned char result_sha1[20];
765 struct notes_tree *t;
766 struct notes_merge_options o;
767 int do_merge = 0, do_commit = 0, do_abort = 0;
768 int verbosity = 0, result;
769 const char *strategy = NULL((void*)0);
770 struct option options[] = {
771 OPT_GROUP(N_("General options")){ OPTION_GROUP, 0, ((void*)0), ((void*)0), ((void*)0), (("General options"
)) }
,
772 OPT__VERBOSITY(&verbosity){ OPTION_CALLBACK, 'v', "verbose", (&verbosity), ((void*)
0), ("be more verbose"), PARSE_OPT_NOARG, &parse_opt_verbosity_cb
, 0 }, { OPTION_CALLBACK, 'q', "quiet", (&verbosity), ((void
*)0), ("be more quiet"), PARSE_OPT_NOARG, &parse_opt_verbosity_cb
, 0 }
,
773 OPT_GROUP(N_("Merge options")){ OPTION_GROUP, 0, ((void*)0), ((void*)0), ((void*)0), (("Merge options"
)) }
,
774 OPT_STRING('s', "strategy", &strategy, N_("strategy"),{ OPTION_STRING, ('s'), ("strategy"), (&strategy), (("strategy"
)), (("resolve notes conflicts using the given strategy " "(manual/ours/theirs/union/cat_sort_uniq)"
)) }
775 N_("resolve notes conflicts using the given strategy "{ OPTION_STRING, ('s'), ("strategy"), (&strategy), (("strategy"
)), (("resolve notes conflicts using the given strategy " "(manual/ours/theirs/union/cat_sort_uniq)"
)) }
776 "(manual/ours/theirs/union/cat_sort_uniq)")){ OPTION_STRING, ('s'), ("strategy"), (&strategy), (("strategy"
)), (("resolve notes conflicts using the given strategy " "(manual/ours/theirs/union/cat_sort_uniq)"
)) }
,
777 OPT_GROUP(N_("Committing unmerged notes")){ OPTION_GROUP, 0, ((void*)0), ((void*)0), ((void*)0), (("Committing unmerged notes"
)) }
,
778 { OPTION_SET_INT, 0, "commit", &do_commit, NULL((void*)0),
779 N_("finalize notes merge by committing unmerged notes")("finalize notes merge by committing unmerged notes"),
780 PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL((void*)0), 1},
781 OPT_GROUP(N_("Aborting notes merge resolution")){ OPTION_GROUP, 0, ((void*)0), ((void*)0), ((void*)0), (("Aborting notes merge resolution"
)) }
,
782 { OPTION_SET_INT, 0, "abort", &do_abort, NULL((void*)0),
783 N_("abort notes merge")("abort notes merge"),
784 PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL((void*)0), 1},
785 OPT_END(){ OPTION_END }
786 };
787
788 argc = parse_options(argc, argv, prefix, options,
789 git_notes_merge_usage, 0);
790
791 if (strategy || do_commit + do_abort == 0)
792 do_merge = 1;
793 if (do_merge + do_commit + do_abort != 1) {
794 error(_("cannot mix --commit, --abort or -s/--strategy"))(error(_("cannot mix --commit, --abort or -s/--strategy")), const_error
())
;
795 usage_with_options(git_notes_merge_usage, options);
796 }
797
798 if (do_merge && argc != 1) {
799 error(_("must specify a notes ref to merge"))(error(_("must specify a notes ref to merge")), const_error()
)
;
800 usage_with_options(git_notes_merge_usage, options);
801 } else if (!do_merge && argc) {
802 error(_("too many parameters"))(error(_("too many parameters")), const_error());
803 usage_with_options(git_notes_merge_usage, options);
804 }
805
806 init_notes_merge_options(&o);
807 o.verbosity = verbosity + NOTES_MERGE_VERBOSITY_DEFAULT;
808
809 if (do_abort)
810 return merge_abort(&o);
811 if (do_commit)
812 return merge_commit(&o);
813
814 o.local_ref = default_notes_ref();
815 strbuf_addstr(&remote_ref, argv[0]);
816 expand_loose_notes_ref(&remote_ref);
817 o.remote_ref = remote_ref.buf;
818
819 t = init_notes_check("merge", NOTES_INIT_WRITABLE2);
820
821 if (strategy) {
822 if (parse_notes_merge_strategy(strategy, &o.strategy)) {
823 error(_("unknown -s/--strategy: %s"), strategy)(error(_("unknown -s/--strategy: %s"), strategy), const_error
())
;
824 usage_with_options(git_notes_merge_usage, options);
825 }
826 } else {
827 struct strbuf merge_key = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
828 const char *short_ref = NULL((void*)0);
829
830 if (!skip_prefix(o.local_ref, "refs/notes/", &short_ref))
831 die("BUG: local ref %s is outside of refs/notes/",
832 o.local_ref);
833
834 strbuf_addf(&merge_key, "notes.%s.mergeStrategy", short_ref);
835
836 if (git_config_get_notes_strategy(merge_key.buf, &o.strategy))
837 git_config_get_notes_strategy("notes.mergeStrategy", &o.strategy);
838
839 strbuf_release(&merge_key);
840 }
841
842 strbuf_addf(&msg, "notes: Merged notes from %s into %s",
843 remote_ref.buf, default_notes_ref());
844 strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */
845
846 result = notes_merge(&o, t, result_sha1);
847
848 if (result >= 0) /* Merge resulted (trivially) in result_sha1 */
849 /* Update default notes ref with new commit */
850 update_ref(msg.buf, default_notes_ref(), result_sha1, NULL((void*)0),
851 0, UPDATE_REFS_DIE_ON_ERR);
852 else { /* Merge has unresolved conflicts */
853 const struct worktree *wt;
854 /* Update .git/NOTES_MERGE_PARTIAL with partial merge result */
855 update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL((void*)0),
856 0, UPDATE_REFS_DIE_ON_ERR);
857 /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */
858 wt = find_shared_symref("NOTES_MERGE_REF", default_notes_ref());
859 if (wt)
860 die(_("a notes merge into %s is already in-progress at %s"),
861 default_notes_ref(), wt->path);
862 if (create_symref("NOTES_MERGE_REF", default_notes_ref(), NULL((void*)0)))
863 die(_("failed to store link to current notes ref (%s)"),
864 default_notes_ref());
865 printf(_("Automatic notes merge failed. Fix conflicts in %s and "
866 "commit the result with 'git notes merge --commit', or "
867 "abort the merge with 'git notes merge --abort'.\n"),
868 git_path(NOTES_MERGE_WORKTREE"NOTES_MERGE_WORKTREE"));
869 }
870
871 free_notes(t);
872 strbuf_release(&remote_ref);
873 strbuf_release(&msg);
874 return result < 0; /* return non-zero on conflicts */
875}
876
877#define IGNORE_MISSING1 1
878
879static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag)
880{
881 int status;
882 unsigned char sha1[20];
883 if (get_sha1(name, sha1))
884 return error(_("Failed to resolve '%s' as a valid ref."), name)(error(_("Failed to resolve '%s' as a valid ref."), name), const_error
())
;
885 status = remove_note(t, sha1);
886 if (status)
887 fprintf(stderr__stderrp, _("Object %s has no note\n"), name);
888 else
889 fprintf(stderr__stderrp, _("Removing note for object %s\n"), name);
890 return (flag & IGNORE_MISSING1) ? 0 : status;
891}
892
893static int remove_cmd(int argc, const char **argv, const char *prefix)
894{
895 unsigned flag = 0;
896 int from_stdin = 0;
897 struct option options[] = {
898 OPT_BIT(0, "ignore-missing", &flag,{ OPTION_BIT, (0), ("ignore-missing"), (&flag), ((void*)0
), (("attempt to remove non-existent note is not an error")),
PARSE_OPT_NOARG, ((void*)0), (1) }
899 N_("attempt to remove non-existent note is not an error"),{ OPTION_BIT, (0), ("ignore-missing"), (&flag), ((void*)0
), (("attempt to remove non-existent note is not an error")),
PARSE_OPT_NOARG, ((void*)0), (1) }
900 IGNORE_MISSING){ OPTION_BIT, (0), ("ignore-missing"), (&flag), ((void*)0
), (("attempt to remove non-existent note is not an error")),
PARSE_OPT_NOARG, ((void*)0), (1) }
,
901 OPT_BOOL(0, "stdin", &from_stdin,{ OPTION_SET_INT, (0), ("stdin"), (&from_stdin), ((void*)
0), (("read object names from the standard input")), PARSE_OPT_NOARG
, ((void*)0), (1) }
902 N_("read object names from the standard input")){ OPTION_SET_INT, (0), ("stdin"), (&from_stdin), ((void*)
0), (("read object names from the standard input")), PARSE_OPT_NOARG
, ((void*)0), (1) }
,
903 OPT_END(){ OPTION_END }
904 };
905 struct notes_tree *t;
906 int retval = 0;
907
908 argc = parse_options(argc, argv, prefix, options,
909 git_notes_remove_usage, 0);
910
911 t = init_notes_check("remove", NOTES_INIT_WRITABLE2);
912
913 if (!argc && !from_stdin) {
914 retval = remove_one_note(t, "HEAD", flag);
915 } else {
916 while (*argv) {
917 retval |= remove_one_note(t, *argv, flag);
918 argv++;
919 }
920 }
921 if (from_stdin) {
922 struct strbuf sb = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
923 while (strbuf_getwholeline(&sb, stdin__stdinp, '\n') != EOF(-1)) {
924 strbuf_rtrim(&sb);
925 retval |= remove_one_note(t, sb.buf, flag);
926 }
927 strbuf_release(&sb);
928 }
929 if (!retval)
930 commit_notes(t, "Notes removed by 'git notes remove'");
931 free_notes(t);
932 return retval;
933}
934
935static int prune(int argc, const char **argv, const char *prefix)
936{
937 struct notes_tree *t;
938 int show_only = 0, verbose = 0;
939 struct option options[] = {
940 OPT__DRY_RUN(&show_only, N_("do not remove, show only")){ OPTION_SET_INT, ('n'), ("dry-run"), ((&show_only)), ((void
*)0), ((("do not remove, show only"))), PARSE_OPT_NOARG, ((void
*)0), (1) }
,
941 OPT__VERBOSE(&verbose, N_("report pruned notes")){ OPTION_COUNTUP, ('v'), ("verbose"), ((&verbose)), ((void
*)0), ((("report pruned notes"))), PARSE_OPT_NOARG }
,
942 OPT_END(){ OPTION_END }
943 };
944
945 argc = parse_options(argc, argv, prefix, options, git_notes_prune_usage,
946 0);
947
948 if (argc) {
949 error(_("too many parameters"))(error(_("too many parameters")), const_error());
950 usage_with_options(git_notes_prune_usage, options);
951 }
952
953 t = init_notes_check("prune", NOTES_INIT_WRITABLE2);
954
955 prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE1 : 0) |
956 (show_only ? NOTES_PRUNE_VERBOSE1|NOTES_PRUNE_DRYRUN2 : 0) );
957 if (!show_only)
958 commit_notes(t, "Notes removed by 'git notes prune'");
959 free_notes(t);
960 return 0;
961}
962
963static int get_ref(int argc, const char **argv, const char *prefix)
964{
965 struct option options[] = { OPT_END(){ OPTION_END } };
966 argc = parse_options(argc, argv, prefix, options,
967 git_notes_get_ref_usage, 0);
968
969 if (argc) {
970 error(_("too many parameters"))(error(_("too many parameters")), const_error());
971 usage_with_options(git_notes_get_ref_usage, options);
972 }
973
974 puts(default_notes_ref());
975 return 0;
976}
977
978int cmd_notes(int argc, const char **argv, const char *prefix)
979{
980 int result;
981 const char *override_notes_ref = NULL((void*)0);
982 struct option options[] = {
983 OPT_STRING(0, "ref", &override_notes_ref, N_("notes-ref"),{ OPTION_STRING, (0), ("ref"), (&override_notes_ref), (("notes-ref"
)), (("use notes from <notes-ref>")) }
984 N_("use notes from <notes-ref>")){ OPTION_STRING, (0), ("ref"), (&override_notes_ref), (("notes-ref"
)), (("use notes from <notes-ref>")) }
,
985 OPT_END(){ OPTION_END }
986 };
987
988 git_config(git_default_config, NULL((void*)0));
989 argc = parse_options(argc, argv, prefix, options, git_notes_usage,
990 PARSE_OPT_STOP_AT_NON_OPTION);
991
992 if (override_notes_ref) {
993 struct strbuf sb = STRBUF_INIT{ 0, 0, strbuf_slopbuf };
994 strbuf_addstr(&sb, override_notes_ref);
995 expand_notes_ref(&sb);
996 setenv("GIT_NOTES_REF", sb.buf, 1);
997 strbuf_release(&sb);
998 }
999
1000 if (argc < 1 || !strcmp(argv[0], "list"))
1001 result = list(argc, argv, prefix);
1002 else if (!strcmp(argv[0], "add"))
1003 result = add(argc, argv, prefix);
1004 else if (!strcmp(argv[0], "copy"))
1005 result = copy(argc, argv, prefix);
1006 else if (!strcmp(argv[0], "append") || !strcmp(argv[0], "edit"))
1007 result = append_edit(argc, argv, prefix);
1008 else if (!strcmp(argv[0], "show"))
1009 result = show(argc, argv, prefix);
1010 else if (!strcmp(argv[0], "merge"))
1011 result = merge(argc, argv, prefix);
1012 else if (!strcmp(argv[0], "remove"))
1013 result = remove_cmd(argc, argv, prefix);
1014 else if (!strcmp(argv[0], "prune"))
1015 result = prune(argc, argv, prefix);
1016 else if (!strcmp(argv[0], "get-ref"))
1017 result = get_ref(argc, argv, prefix);
1018 else {
1019 result = error(_("unknown subcommand: %s"), argv[0])(error(_("unknown subcommand: %s"), argv[0]), const_error());
Value stored to 'result' is never read
1020 usage_with_options(git_notes_usage, options);
1021 }
1022
1023 return result ? 1 : 0;
1024}