2009-06-30 72 views

回答

4

它在git-mergetool中編寫腳本。我在我的副本的第344行發現了這一點。

if test -z "$merge_tool"; then 
    merge_tool=`git config merge.tool` 
    if test -n "$merge_tool" && ! valid_tool "$merge_tool"; then 
     echo >&2 "git config option merge.tool set to unknown tool: $merge_tool" 
     echo >&2 "Resetting to default..." 
     unset merge_tool 
    fi 
fi 

if test -z "$merge_tool" ; then 
    if test -n "$DISPLAY"; then 
     merge_tool_candidates="kdiff3 tkdiff xxdiff meld gvimdiff" 
     if test -n "$GNOME_DESKTOP_SESSION_ID" ; then 
      merge_tool_candidates="meld $merge_tool_candidates" 
     fi 
     if test "$KDE_FULL_SESSION" = "true"; then 
      merge_tool_candidates="kdiff3 $merge_tool_candidates" 
     fi 
    fi 
    if echo "${VISUAL:-$EDITOR}" | grep 'emacs' > /dev/null 2>&1; then 
     merge_tool_candidates="$merge_tool_candidates emerge" 
    fi 
(snip) 
+0

我需要下載一個新的Git並查看它的源代碼。我的git採用編譯格式,因此無法讀取它。 @如何在不下載新的源代碼的情況下查看Git的源代碼? – 2009-07-04 00:12:24

+0

@Masi:當編譯git本身時,許多命令(如mergetool)實際上只是隱藏在某處的腳本。在我的系統上,這些主要存儲在/ usr/lib/git-core/ – kwatford 2009-07-04 01:58:50

2

正如git mergetool man page提到,

--tool=<tool> 

通過使用指定的合併決議的程序。
有效的合併工具是:kdiff3,tkdiff,meld,xxdiff,emerge,vimdiff,gvimdiff,ecmerge,diffuse,tortoisemerge,opendiff和araxis。

現在,該列表從哪裏來?

事實上,這些工具(和他們的自定義選項)在腳本中使用:

<Git>/libexec/git-core/git-mergetool--lib 

,並通過腳本混帳合併工具,它不基於git config merge.tool命令選擇使用。

但有一點基礎上,valid_tool的混帳合併工具()函數「自動選擇」的 - lib目錄下:

valid_tool() 

它採用get_merge_tool_cmd(),它是基於mergetool.<aMergeToolName>.cmd
如果該設置保留在其中一個git配置文件中,該工具將被選中。


右... Jakub Narębski只是指出了正確的部分在git-mergetool--lib腳本:

get_merge_tool() { 
    # Check if a merge tool has been configured 
    merge_tool=$(get_configured_merge_tool) 
    # Try to guess an appropriate merge tool if no tool has been set. 
    if test -z "$merge_tool"; then 
     merge_tool="$(guess_merge_tool)" || exit 
    fi 
    echo "$merge_tool" 
} 

該功能恰當地命名爲guess_merge_tool()(你覺得我應該能找到它! ..)除了其他的事情,以下,這可以解釋它檢測opendiff:

# Loop over each candidate and stop when a valid merge tool is found. 
for i in $tools 
do 
    merge_tool_path="$(translate_merge_tool_path "$i")" 
    if type "$merge_tool_path" > /dev/null 2>&1; then 
     echo "$i" 
     return 0 
    fi 
done