2017-02-13 23 views
0

我正在瀏覽git源代碼,我想知道入口點文件在哪裏?我已經經歷了一些文件,我認爲它會是它,但找不到主要功能。git的入口點是什麼?

+1

* any * C程序的入口點是什麼? –

+3

'grep main * .c'? – larsks

+0

@JonathonReinhart雖然我對c很新,但我會認爲它可能是任何具有主函數的文件。讓我知道,如果不是這樣。 –

回答

2

我可能是錯的,但我相信入口點是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中定義。

0

也許最好是解決誤會。 Git是一種收集,記錄和歸檔項目目錄變化的方式。這就是版本控制系統的目的,而git也許是其中一個比較容易識別的版本。

有時他們也提供構建自動化,但通常最好的工具集中於最少的責任。在git的情況下,它主要關注提交到一個存儲庫,以便保存它初始化到的目錄的不同狀態。它不會構建程序,因此入口點不受影響。


對於C項目,入口點將始終與編譯器定義的入口點相同。通常這是一個名爲main的函數,但有些方法可以重新定義或隱藏此入口點。例如,Arduino使用setup作爲入口點,然後調用loop

@larks留下的評論是一種在不確定的情況下找到入口點的簡單方法。使用從git倉庫的根目錄下一個簡單的遞歸搜索可以在任何包含文件追捕字main

grep main *.c 

在Windows相當於是FINDSTR,但在bash命令最近更新到Windows 10有很大的提高兼容性。 grep在我正在運行的版本中可用。所以ls,雖然我不確定它是否一直存在。


一些git的項目包括多國語言,以及許多語言與C(及其前身)使用相同的入口點的名稱。只要在.c的文件擴展名中查找,就可以找到C組件的入口點,假設代碼的質量足夠高,以至於您希望首先運行它。

確實有辦法干擾擴展程序如何過濾掉其他語言,但它們的使用意味着非常隨意的編碼實踐。

+0

到目前爲止最好的回答! – d3L

+0

這似乎沒有回答這個問題(國際海事組織)。我認爲OP正在尋找_git本身的切入點_... –

+0

@DanLowe也許你是對的,儘管答案與這個問題以及更一般的問題高度相關。唯一的區別是識別構建系統,調用哪個目錄以及是否使用入口點混淆非常重要。在大多數情況下,發現主要是足夠的 – Aaron3468