是Git';自动检测是脚本化的还是在某个Git可执行文件中?

是Git';自动检测是脚本化的还是在某个Git可执行文件中?,git,difftool,mergetool,Git,Difftool,Mergetool,这个问题是基于VonC在会议上的评论 Git对difftool或mergetool的自动检测是脚本化的还是在某个Git可执行文件中?它是在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

这个问题是基于VonC在会议上的评论


Git对difftool或mergetool的自动检测是脚本化的还是在某个Git可执行文件中?

它是在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)

它是在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)
如报告中所述

它使用基于
mergetool的get\u merge\u tool\u cmd()。刚才指出了
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\u merge\u 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
如报告中所述

它使用基于
mergetool的get\u merge\u tool\u cmd()。刚才指出了
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\u merge\u 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

实际上,它是git mergetool--lib中的“guess_merge_tool”函数实际上是git mergetool--lib中的“guess_merge_tool”函数Jakub Narębski在git脚本中找到正确的部分:查看我完整的答案。Jakub Narębski只需在git脚本中找到正确的部分:查看我完整的答案。我需要下载一个新的git并查看其内容来源。我的git采用编译格式,因此无法读取。@在不下载新的Git源代码的情况下,如何查看Git的源代码?@Masi:虽然Git本身是编译的,但许多命令(如mergetool)实际上只是隐藏在某处的脚本。在我的系统上,这些文件大部分存储在/usr/lib/git-core/中,我需要下载一个新的git并查看其源代码。我的git采用编译格式,因此无法读取。@在不下载新的Git源代码的情况下,如何查看Git的源代码?@Masi:虽然Git本身是编译的,但许多命令(如mergetool)实际上只是隐藏在某处的脚本。在我的系统上,它们大部分存储在/usr/lib/git-core中/