Skip to content

Commit b0de56c

Browse files
jherlandgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johan Herland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4282af0 commit b0de56c

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

builtin/notes.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ static int append_edit(int argc, const char **argv, const char *prefix);
399399

400400
static int add(int argc, const char **argv, const char *prefix)
401401
{
402-
int retval = 0, force = 0;
402+
int force = 0;
403403
const char *object_ref;
404404
struct notes_tree *t;
405405
unsigned char object[20], new_note[20];
@@ -441,23 +441,23 @@ static int add(int argc, const char **argv, const char *prefix)
441441

442442
if (note) {
443443
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) {
453446
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));
456451
}
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);
461461
}
462462
fprintf(stderr, _("Overwriting existing notes for object %s\n"),
463463
sha1_to_hex(object));
@@ -474,9 +474,8 @@ static int add(int argc, const char **argv, const char *prefix)
474474
snprintf(logmsg, sizeof(logmsg), "Notes %s by 'git notes %s'",
475475
is_null_sha1(new_note) ? "removed" : "added", "add");
476476
commit_notes(t, logmsg);
477-
out:
478477
free_notes(t);
479-
return retval;
478+
return 0;
480479
}
481480

482481
static int copy(int argc, const char **argv, const char *prefix)

0 commit comments

Comments
 (0)