Skip to content

Commit 413bc6d

Browse files
dsal3389gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0feb86 commit 413bc6d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

git.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -893,19 +893,21 @@ int cmd_main(int argc, const char **argv)
893893
argv++;
894894
argc--;
895895
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) {
902898
/* The user didn't specify a command; give them help */
903899
commit_pager_choice();
904900
printf(_("usage: %s\n\n"), git_usage_string);
905901
list_common_cmds_help();
906902
printf("\n%s\n", _(git_more_info_string));
907903
exit(1);
908904
}
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+
909911
cmd = argv[0];
910912

911913
/*

0 commit comments

Comments
 (0)