git.c: improve code readability in cmd_main()

Check for an error condition whose body unconditionally exists first, and then perform the special casing of "version" and "help" as part of the preparation for the "normal codepath". This makes the code simpler to read. Signed-off-by: Daniel Sonbolian <dsal3389@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Daniel Sonbolian committed Oct 8, 2022 at 16:21 UTC 413bc6d20ad4d686f68afcf3c012b77840c1243b
1 file changed +8 -6
git.c
+8 -6
@@ -893,12 +893,8 @@ int cmd_main(int argc, const char **argv)
893 argv++;
894 argc--;
895 handle_options(&argv, &argc, NULL);
896 - if (argc > 0) {
897 - if (!strcmp("--version", argv[0]) || !strcmp("-v", argv[0]))
898 - argv[0] = "version";
899 - else if (!strcmp("--help", argv[0]) || !strcmp("-h", argv[0]))
900 - argv[0] = "help";
901 - } else {
896 +
897 + if (!argc) {
898 /* The user didn't specify a command; give them help */
899 commit_pager_choice();
900 printf(_("usage: %s\n\n"), git_usage_string);
@@ -906,6 +902,12 @@ int cmd_main(int argc, const char **argv)
902 printf("\n%s\n", _(git_more_info_string));
903 exit(1);
904 }
905 +
906 + if (!strcmp("--version", argv[0]) || !strcmp("-v", argv[0]))
907 + argv[0] = "version";
908 + else if (!strcmp("--help", argv[0]) || !strcmp("-h", argv[0]))
909 + argv[0] = "help";
910 +
911 cmd = argv[0];
912
913 /*