Как я устанавливаю DiffMerge с msysgit / gitk?

Вы не можете иметь списки в качестве ключей словаря, потому что они недоступны для чтения.

Поскольку вы запросили строковые ключи, вы можете сделать:

from collections import defaultdict

packed_items = {0: [0, 3],
                2: [1], 
                1: [2]}
trucks_dict = {0: [9.5, 5.5, 5.5],
               1: [13.0, 5.5, 7.0],
               2: [16.0, 6.0, 7.0]}
items_dict = {0: [4.6, 4.3, 4.3],
              1: [4.6, 4.3, 4.3],
              2: [6.0, 5.6, 9.0],
              3: [8.75, 5.6, 6.6]}

d = defaultdict(list)

for k1, v1 in trucks_dict.items():
    for k2, v2 in items_dict.items():
        if k1 == k2 % 3:
            d[str(v1)].append(v2)

print(d)
# {'[9.5, 5.5, 5.5]': [[4.6, 4.3, 4.3], [8.75, 5.6, 6.6]], '[16.0, 6.0, 7.0]': [[4.6, 4.3, 4.3]], '[13.0, 5.5, 7.0]': [[6.0, 5.6, 9.0]]}
21
задан Community 23 May 2017 в 11:45
поделиться

3 ответа

Я только что испытал несколько похожий опыт установки Notepad ++ в качестве моего внешнего редактора с msysgit1.6.2.2 .

Ключ был в том, чтобы понять, что оболочка не была Сценарий DOS, но сценарий / bin / sh.

Поэтому попробуйте вставить свой «.bat» (хотя это не совсем скрипт bat, расширение здесь не важно):

#!/bin/sh

# diff is called by git with 7 parameters:
# path old-file old-hex old-mode new-file new-hex new-mode

"C:/Programs/SourceGear/DiffMerge/DiffMerge.exe" /title1="Old Version" "$2" /title2="New Version" "$5" | cat

Не беспокойтесь о сделать все ' \ ' go ' / ': это делается скриптами Git, вызывающими внешний инструмент сравнения.

Я не тестировал его с помощью DiffMerge, но с WinMerge , он работает просто отлично, как из сеанса DOS, так и из Git Shell.

#!/bin/sh
"C:/Program Files/WinMerge/WinMergeU.exe" -e -ub "$2" "$5" | cat

(с опцией ' -e ', я просто набрал ot type для ' ESC ' to закройте и выйдите из инструмента сравнения: это прекрасно работает!)


alt text average_geek добавляет в комментариях:

добавил заголовок / bin / sh 'и попытался снова запустить git diff.
This time the error is:
Unexpected parameter 'C:/Docume~/avggeek/LOCALS~1/Temp/.diff_b08444
Is there a way to see what are the parameters getting passed when I call git diff ?

1/ There actually is a way to see what are the parameters getting passed!
Add the following line in the C:\Program Files\Git\libexec\git-core\git-sh-setup file:

git_editor() {
    : "${GIT_EDITOR:=$(git config core.editor)}"
    : "${GIT_EDITOR:=${VISUAL:-${EDITOR}}}"
    case "$GIT_EDITOR,$TERM" in
    ,dumb)
        echo >&2 "No editor specified in GIT_EDITOR, core.editor, VISUAL,"
        echo >&2 "or EDITOR. Tried to fall back to vi but terminal is dumb."
        echo >&2 "Please set one of these variables to an appropriate"
        echo >&2 "editor or run $0 with options that will not cause an"
        echo >&2 "editor to be invoked (e.g., -m or -F for git-commit)."
        exit 1
        ;;
    esac
#### ADD THIS LINE BELOW
    echo >&2 "editor is ${GIT_EDITOR:=vi} $@."
#### END ADDITION ABOVE
    eval "${GIT_EDITOR:=vi}" '"$@"'
}

You will see what editor is being called, with what parameter.

Now, regarding the "Unexpected parameter" part:
I did have the same kind of error when I called WinMergeU.exe with "/e /ub" instead of "-e -ub", so first question is:
Are you sure that the "/title1" bit could not be used as "-title1" or "-t1" or "--title1" or "--t1" ? That is what Is can see from the chapter 9 "Command Lines Arguments" of the pdf documentation of DiffMerge.
If not, I suspect some double quotes are in order for delimiting properly the different parameters. Something like:

"/title1="Old Version"" "$2" "/title2="New Version"" "$5"
or
"/title1=\"Old Version\"" "$2" "/title2=\"New Version\"" "$5"

But my money would rather be on the "-title1" or "-t1" form:

-t1="Old Version" "$2" -t2="New Version" "$5"

should work just fine.

9
ответ дан 29 November 2019 в 20:55
поделиться

VonC - switching to -t1 and -t2 fixed the errors. Diffmerge now works for git bash :)

After a little bit of poking at the gitk patch that added External Diff support, I realized that it's calling an External Diff program directly with the two files as arguments. So I modified gitk>Edit>Preferences and put the following command directly into the External Diff Tool option:

"C:/Programs/SourceGear/DiffMerge/DiffMerge.exe" -t1="Old Version" -t2="New Version"

Now I have DiffMerge working for gitk too :-)

4
ответ дан 29 November 2019 в 20:55
поделиться

У меня это работает следующим образом:

В ~ / .gitconfig :

[merge]
tool = diffmerge
[mergetool "diffmerge"]
cmd = \"C:/Program Files/git/cmd/git-diffmerge-merge.sh\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
trustExitCode = false

В C: \ Program Files \ Git \ cmd \ git-diffmerge-merge.sh :

#!/bin/sh

localPath="$2"
basePath="$1"
remotePath="$3"
resultPath="$4"

if [ ! -f $basePath ]
then
    basePath="~/diffmerge-empty"
fi

"C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe" --merge --result="$resultPath" "$localPath" "$basePath" "$remotePath" --title1="Mine" --title2="Merged: $4" --title3="Theirs"

Часть благодарности принадлежит http://therightstuff.de/2009/01/28/Setting-Up-SourceGear-DiffMerge-With-Git.aspx ;)

8
ответ дан 29 November 2019 в 20:55
поделиться
Другие вопросы по тегам:

Похожие вопросы: