我正在浏览git源代码,我想知道入口点文件在哪里?我浏览了几个文件,我认为可以,但找不到主要功能。
最佳答案
我可能是错的,但我相信入口点是 common-main.c
中的 main()
。
int main(int argc, const char **argv)
{
/*
* Always open file descriptors 0/1/2 to avoid clobbering files
* in die(). It also avoids messing up when the pipes are dup'ed
* onto stdin/stdout/stderr in the child processes we spawn.
*/
sanitize_stdfds();
git_setup_gettext();
git_extract_argv0_path(argv[0]);
restore_sigpipe_to_default();
return cmd_main(argc, argv);
}
最后你可以看到它返回 cmd_main(argc, argv)
。 cmd_main()
有很多定义,但我相信这里返回的是 git.c
中定义的那个,在这里贴出来有点长其全部内容,但摘录如下:
int cmd_main(int argc, const char **argv)
{
const char *cmd;
cmd = argv[0];
if (!cmd)
cmd = "git-help";
else {
const char *slash = find_last_dir_sep(cmd);
if (slash)
cmd = slash + 1;
}
/*
* "git-xxxx" is the same as "git xxxx", but we obviously:
*
* - cannot take flags in between the "git" and the "xxxx".
* - cannot execute it externally (since it would just do
* the same thing over again)
*
* So we just directly call the builtin handler, and die if
* that one cannot handle it.
*/
if (skip_prefix(cmd, "git-", &cmd)) {
argv[0] = cmd;
handle_builtin(argc, argv);
die("cannot handle %s as a builtin", cmd);
}
handle_builtin()
也在 git.c
中定义。
关于c - git的入口点是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42195929/