MCPcopy Index your code
hub / github.com/git/git / cmd_main

Function cmd_main

git.c:918–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

916}
917
918int 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

Callers 1

mainFunction · 0.70

Calls 13

strvec_pushFunction · 0.85
strvec_pushvFunction · 0.85
handle_builtinFunction · 0.85
strvec_clearFunction · 0.85
handle_optionsFunction · 0.85
commit_pager_choiceFunction · 0.85
list_common_cmds_helpFunction · 0.85
setup_pathFunction · 0.85
run_argvFunction · 0.85
help_unknown_cmdFunction · 0.85
strvec_replaceFunction · 0.85

Tested by

no test coverage detected