git的切入点是什么?

时间:2017-02-13 02:49:16

标签: c git

我正在浏览git源代码,我想知道入口点文件在哪里?我已经浏览了几个文件,我认为会是它,但找不到主要功能。

2 个答案:

答案 0 :(得分:4)

我可能错了,但我相信main()中的入口点为common-main.c

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中定义。

答案 1 :(得分:0)

也许最好解决这个误解。 Git是一种收集,记录和归档项目目录更改的方法。这是版本控制系统的目的,而git可能是更容易识别的一种。

有时它们也提供构建自动化,但通常最好的工具集中在最少的职责上。在git的情况下,它主要关注对存储库的提交,以便保留它初始化的目录的不同状态。它不构建程序,因此入口点不受影响。

对于C项目,入口点将始终与编译器定义的入口点相同。通常,这是一个名为main的函数,但有一些方法可以重新定义或隐藏此入口点。例如,Arduino使用setup作为切入点,然后调用loop

@larks留下的评论是一种在您不确定时找到入口点的简便方法。使用git repo根目录中的简单递归搜索可以在任何包含的文件中搜索单词main

grep main *.c

Windows等效项为FINDSTR,但最近对Windows 10的更新大大提高了与Bash命令的兼容性。 grep可用于我正在运行的版本中。 ls也是如此,但我不确定它是否一直存在。

一些git项目包含多种语言,与C(和前辈)相关的许多语言使用相同的入口点名称。仅查看.c的文件扩展名是查找C组件入口点的好方法,假设代码质量足够高,您首先要运行它。

肯定有办法干扰扩展程序过滤其他语言的程度,但它们的使用意味着非常随意的编码实践。

相关问题