notes: simplify default operation mode arguments check

'git notes' has a default operation mode, but when invoked without a subcommand it doesn't accept any arguments (although the 'list' subcommand implementing the default operation mode does accept arguments). The condition checking this ended up a bit awkward, so let's make it clearer. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Sep 5, 2022 at 20:50 UTC 1c7c25aef12918b9305df19142ab5755297274a6
1 file changed +7 -4
builtin/notes.c
+7 -4
@@ -995,7 +995,7 @@ static int get_ref(int argc, const char **argv, const char *prefix)
995 int cmd_notes(int argc, const char **argv, const char *prefix)
996 {
997 const char *override_notes_ref = NULL;
998 - parse_opt_subcommand_fn *fn = list;
998 + parse_opt_subcommand_fn *fn = NULL;
999 struct option options[] = {
1000 OPT_STRING(0, "ref", &override_notes_ref, N_("notes-ref"),
1001 N_("use notes from <notes-ref>")),
@@ -1015,9 +1015,12 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
1015 git_config(git_default_config, NULL);
1016 argc = parse_options(argc, argv, prefix, options, git_notes_usage,
1017 PARSE_OPT_SUBCOMMAND_OPTIONAL);
1018 - if (fn == list && argc && strcmp(argv[0], "list")) {
1019 - error(_("unknown subcommand: %s"), argv[0]);
1020 - usage_with_options(git_notes_usage, options);
1018 + if (!fn) {
1019 + if (argc) {
1020 + error(_("unknown subcommand: %s"), argv[0]);
1021 + usage_with_options(git_notes_usage, options);
1022 + }
1023 + fn = list;
1024 }
1025
1026 if (override_notes_ref) {