builtin/notes: simplify early exit code in add()
Remove the need for 'retval' and the unnecessary goto. Also reorganize to only call free_note_data() is actually needed. Improved-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Nov 12, 2014 at 01:40 UTC
b0de56c6a5bb41da71babafefc9207b0fc211d66
1 file changed
+17
-18
builtin/notes.c
+17
-18
@@ -399,7 +399,7 @@ static int append_edit(int argc, const char **argv, const char *prefix);
399
400
static int add(int argc, const char **argv, const char *prefix)
401
{
402
- int retval = 0, force = 0;
402
+ int force = 0;
403
const char *object_ref;
404
struct notes_tree *t;
405
unsigned char object[20], new_note[20];
@@ -441,23 +441,23 @@ static int add(int argc, const char **argv, const char *prefix)
441
442
if (note) {
443
if (!force) {
444
- if (!d.given) {
445
- /*
446
- * Redirect to "edit" subcommand.
447
- *
448
- * We only end up here if none of -m/-F/-c/-C
449
- * or -f are given. The original args are
450
- * therefore still in argv[0-1].
451
- */
452
- argv[0] = "edit";
444
+ free_notes(t);
445
+ if (d.given) {
446
free_note_data(&d);
454
- free_notes(t);
455
- return append_edit(argc, argv, prefix);
447
+ return error(_("Cannot add notes. "
448
+ "Found existing notes for object %s. "
449
+ "Use '-f' to overwrite existing notes"),
450
+ sha1_to_hex(object));
451
}
457
- retval = error(_("Cannot add notes. Found existing notes "
458
- "for object %s. Use '-f' to overwrite "
459
- "existing notes"), sha1_to_hex(object));
460
- goto out;
452
+ /*
453
+ * Redirect to "edit" subcommand.
454
+ *
455
+ * We only end up here if none of -m/-F/-c/-C or -f are
456
+ * given. The original args are therefore still in
457
+ * argv[0-1].
458
+ */
459
+ argv[0] = "edit";
460
+ return append_edit(argc, argv, prefix);
461
}
462
fprintf(stderr, _("Overwriting existing notes for object %s\n"),
463
sha1_to_hex(object));
@@ -474,9 +474,8 @@ static int add(int argc, const char **argv, const char *prefix)
474
snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'",
475
is_null_sha1(new_note) ? "removed" : "added", "add");
476
commit_notes(t, logmsg);
477
-out:
477
free_notes(t);
479
- return retval;
478
+ return 0;
479
}
480
481
static int copy(int argc, const char **argv, const char *prefix)