| 916 | } |
| 917 | |
| 918 | int cmd_main(int argc, const char **argv) |
| 919 | { |
| 920 | struct strvec args = STRVEC_INIT; |
| 921 | const char *cmd; |
| 922 | int done_help = 0; |
| 923 | |
| 924 | cmd = argv[0]; |
| 925 | if (!cmd) |
| 926 | cmd = "git-help"; |
| 927 | else { |
| 928 | const char *slash = find_last_dir_sep(cmd); |
| 929 | if (slash) |
| 930 | cmd = slash + 1; |
| 931 | } |
| 932 | |
| 933 | trace_command_performance(argv); |
| 934 | |
| 935 | /* |
| 936 | * "git-xxxx" is the same as "git xxxx", but we obviously: |
| 937 | * |
| 938 | * - cannot take flags in between the "git" and the "xxxx". |
| 939 | * - cannot execute it externally (since it would just do |
| 940 | * the same thing over again) |
| 941 | * |
| 942 | * So we just directly call the builtin handler, and die if |
| 943 | * that one cannot handle it. |
| 944 | */ |
| 945 | if (skip_prefix(cmd, "git-", &cmd)) { |
| 946 | strvec_push(&args, cmd); |
| 947 | strvec_pushv(&args, argv + 1); |
| 948 | handle_builtin(&args); |
| 949 | strvec_clear(&args); |
| 950 | die(_("cannot handle %s as a builtin"), cmd); |
| 951 | } |
| 952 | |
| 953 | /* Look for flags.. */ |
| 954 | argv++; |
| 955 | argc--; |
| 956 | handle_options(&argv, &argc, NULL); |
| 957 | |
| 958 | if (!argc) { |
| 959 | /* The user didn't specify a command; give them help */ |
| 960 | commit_pager_choice(); |
| 961 | printf(_("usage: %s\n\n"), git_usage_string); |
| 962 | list_common_cmds_help(); |
| 963 | printf("\n%s\n", _(git_more_info_string)); |
| 964 | exit(1); |
| 965 | } |
| 966 | |
| 967 | if (!strcmp("--version", argv[0]) || !strcmp("-v", argv[0])) |
| 968 | argv[0] = "version"; |
| 969 | else if (!strcmp("--help", argv[0]) || !strcmp("-h", argv[0])) |
| 970 | argv[0] = "help"; |
| 971 | |
| 972 | cmd = argv[0]; |
| 973 | |
| 974 | /* |
| 975 | * We use PATH to find git commands, but we prepend some higher |
no test coverage detected