c - git的入口点是什么?

标签 c git

我正在浏览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/

相关文章:

c - 在字符串数组上使用指针的段错误

c++ - 静态编译共享库

c - C语言中如何获取int变量的后缀?

c - 如何解析不同类型的参数?

git - 当 merge 提交妨碍时如何避免 rebase hell ?

command-line - git中删除上一个分支的快捷方式

git - Android Studio - 在 git 远程上游 merge 后克隆的第 3 方模块

c - strcpy 产生重复的存储项

GitHub 从密码更改为个人访问 token ,无需重新克隆 repo

git filter-branch 重复提交