{"thread":{"id":"18836","subject":"[PATCH 1/2] mergetool--lib: Fix misspelled mergetool.keepBackup","startedAt":"2009-04-12T03:41:55Z","lastAt":"2009-04-12T03:41:56Z","messageCount":2,"participants":["David Aguilar"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"111116","messageId":"1239507716-6766-1-git-send-email-davvid@gmail.com","threadId":"18836","inReplyTo":null,"subject":"[PATCH 1/2] mergetool--lib: Fix misspelled mergetool.keepBackup","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-04-12T03:41:55Z","receivedAt":"2009-04-12T03:41:55Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"From: Ferry Huberts <ferry.huberts@pelagic.nl>\n\nIn several places mergetool.keepBackup was misspelled as merge.keepBackup.\n\nSigned-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>\n---\n\nThis is Ferry's patch with Junio's suggested commit message.\nBased on pu.\n\n git-mergetool.sh |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex efa31a2..2e3e02b 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -257,7 +257,7 @@ prompt_after_failed_merge() {\n merge_tool=$(get_merge_tool \"$merge_tool\") || exit\n merge_tool_cmd=\"$(get_merge_tool_cmd \"$merge_tool\")\"\n merge_tool_path=\"$(get_merge_tool_path \"$merge_tool\")\" || exit\n-merge_keep_backup=\"$(git config --bool merge.keepBackup || echo true)\"\n+merge_keep_backup=\"$(git config --bool mergetool.keepBackup || echo true)\"\n merge_keep_temporaries=\"$(git config --bool mergetool.keepTemporaries || echo false)\"\n merge_tool_trust_exit_code=\"$(git config --bool mergetool.\"$merge_tool\".trustExitCode || echo false)\"\n \n-- \n1.6.2.2.471.g6da14\n"},{"id":"111117","messageId":"1239507716-6766-2-git-send-email-davvid@gmail.com","threadId":"18836","inReplyTo":"1239507716-6766-1-git-send-email-davvid@gmail.com","subject":"[PATCH 2/2] mergetool--lib: simplify API usage by removing more global variables","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-04-12T03:41:56Z","receivedAt":"2009-04-12T03:41:56Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"The mergetool--lib scriplet was tricky to use because it relied upon\nthe existance of several global shell variables.  This removes more\nglobal variables so that things are simpler for callers.\n\nA side effect is that some variables are recomputed each time\nrun_merge_tool() is called, but the overhead for recomputing\nthem is justified by the simpler implementation.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nThis addresses Charles' notes by making the mergetool--lib\nsimpler to use.\n\nWe can now simply use:\n\tget_merge_tool\n\tget_merge_tool_path\n\tget_merge_tool_cmd\nand things will work consistently.\n\nPrevious versions used global variables that would give\nunexpected results if they had been set previously.\n\n Documentation/git-mergetool--lib.txt |   16 ++---\n git-difftool--helper.sh              |    6 +-\n git-mergetool--lib.sh                |  109 ++++++++++++++++++----------------\n git-mergetool.sh                     |   15 +++--\n 4 files changed, 76 insertions(+), 70 deletions(-)\n\ndiff --git a/Documentation/git-mergetool--lib.txt b/Documentation/git-mergetool--lib.txt\nindex 3d57031..78eb03f 100644\n--- a/Documentation/git-mergetool--lib.txt\n+++ b/Documentation/git-mergetool--lib.txt\n@@ -7,7 +7,7 @@ git-mergetool--lib - Common git merge tool shell scriptlets\n \n SYNOPSIS\n --------\n-'. \"$(git --exec-path)/git-mergetool--lib\"'\n+'TOOL_MODE=(diff|merge) . \"$(git --exec-path)/git-mergetool--lib\"'\n \n DESCRIPTION\n -----------\n@@ -20,14 +20,14 @@ The 'git-mergetool--lib' scriptlet is designed to be sourced (using\n `.`) by other shell scripts to set up functions for working\n with git merge tools.\n \n-Before sourcing it, your script should set up a few variables;\n-`TOOL_MODE` is used to define the operation mode for various\n-functions.  'diff' and 'merge' are valid values.\n+Before sourcing 'git-mergetool--lib', your script must set `TOOL_MODE`\n+to define the operation mode for the functions listed below.\n+'diff' and 'merge' are valid values.\n \n FUNCTIONS\n ---------\n get_merge_tool::\n-\treturns a merge tool\n+\treturns a merge tool.\n \n get_merge_tool_cmd::\n \treturns the custom command for a merge tool.\n@@ -38,10 +38,8 @@ get_merge_tool_path::\n run_merge_tool::\n \tlaunches a merge tool given the tool name and a true/false\n \tflag to indicate whether a merge base is present.\n-\t'$merge_tool', '$merge_tool_path', and for custom commands,\n-\t'$merge_tool_cmd', must be defined prior to calling\n-\trun_merge_tool.  Additionally, '$MERGED', '$LOCAL', '$REMOTE',\n-\tand '$BASE' must be defined for use by the merge tool.\n+\t'$MERGED', '$LOCAL', '$REMOTE', and '$BASE' must be defined\n+\tfor use by the merge tool.\n \n Author\n ------\ndiff --git a/git-difftool--helper.sh b/git-difftool--helper.sh\nindex b450036..57e8e32 100755\n--- a/git-difftool--helper.sh\n+++ b/git-difftool--helper.sh\n@@ -47,9 +47,9 @@ launch_merge_tool () {\n test -n \"$GIT_MERGE_TOOL\" && merge_tool=\"$GIT_MERGE_TOOL\"\n test -n \"$GIT_DIFF_TOOL\" && merge_tool=\"$GIT_DIFF_TOOL\"\n \n-merge_tool=$(get_merge_tool \"$merge_tool\") || exit\n-merge_tool_cmd=\"$(get_merge_tool_cmd \"$merge_tool\")\"\n-merge_tool_path=\"$(get_merge_tool_path \"$merge_tool\")\" || exit\n+if test -z \"$merge_tool\"; then\n+\tmerge_tool=\"$(get_merge_tool)\" || exit\n+fi\n \n # Launch the merge tool on each path provided by 'git diff'\n while test $# -gt 6\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex c5db24e..a16a279 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -8,25 +8,20 @@ merge_mode() {\n }\n \n translate_merge_tool_path () {\n-\tif test -n \"$2\"; then\n-\t\techo \"$2\"\n-\telse\n-\t\tcase \"$1\" in\n-\t\tvimdiff)\n-\t\t\tpath=vim\n-\t\t\t;;\n-\t\tgvimdiff)\n-\t\t\tpath=gvim\n-\t\t\t;;\n-\t\temerge)\n-\t\t\tpath=emacs\n-\t\t\t;;\n-\t\t*)\n-\t\t\tpath=\"$1\"\n-\t\t\t;;\n-\t\tesac\n-\t\techo \"$path\"\n-\tfi\n+\tcase \"$1\" in\n+\tvimdiff)\n+\t\techo vim\n+\t\t;;\n+\tgvimdiff)\n+\t\techo gvim\n+\t\t;;\n+\temerge)\n+\t\techo emacs\n+\t\t;;\n+\t*)\n+\t\techo \"$1\"\n+\t\t;;\n+\tesac\n }\n \n check_unchanged () {\n@@ -69,15 +64,22 @@ valid_tool () {\n }\n \n get_merge_tool_cmd () {\n-\tdiff_mode &&\n-\tcustom_cmd=\"$(git config difftool.$1.cmd)\"\n-\ttest -z \"$custom_cmd\" &&\n-\tcustom_cmd=\"$(git config mergetool.$1.cmd)\"\n-\ttest -n \"$custom_cmd\" &&\n-\techo \"$custom_cmd\"\n+\t# Prints the custom command for a merge tool\n+\tif test -n \"$1\"; then\n+\t\tmerge_tool=\"$1\"\n+\telse\n+\t\tmerge_tool=\"$(get_merge_tool)\"\n+\tfi\n+\tif diff_mode; then\n+\t\techo \"$(git config difftool.$merge_tool.cmd ||\n+\t\t        git config mergetool.$merge_tool.cmd)\"\n+\telse\n+\t\techo \"$(git config mergetool.$merge_tool.cmd)\"\n+\tfi\n }\n \n run_merge_tool () {\n+\tmerge_tool_path=\"$(get_merge_tool_path \"$1\")\" || exit\n \tbase_present=\"$2\"\n \tstatus=0\n \n@@ -103,9 +105,9 @@ run_merge_tool () {\n \t\t\tstatus=$?\n \t\telse\n \t\t\t(\"$merge_tool_path\" --auto \\\n-\t\t\t --L1 \"$MERGED (A)\" \\\n-\t\t\t --L2 \"$MERGED (B)\" \"$LOCAL\" \"$REMOTE\" \\\n-\t\t\t > /dev/null 2>&1)\n+\t\t\t\t--L1 \"$MERGED (A)\" \\\n+\t\t\t\t--L2 \"$MERGED (B)\" \"$LOCAL\" \"$REMOTE\" \\\n+\t\t\t> /dev/null 2>&1)\n \t\tfi\n \t\t;;\n \tkompare)\n@@ -262,6 +264,7 @@ run_merge_tool () {\n \t\tfi\n \t\t;;\n \t*)\n+\t\tmerge_tool_cmd=\"$(get_merge_tool_cmd \"$1\")\"\n \t\tif test -z \"$merge_tool_cmd\"; then\n \t\t\tif merge_mode; then\n \t\t\t\tstatus=1\n@@ -269,7 +272,9 @@ run_merge_tool () {\n \t\t\tbreak\n \t\tfi\n \t\tif merge_mode; then\n-\t\t\tif test \"$merge_tool_trust_exit_code\" = \"false\"; then\n+\t\t\ttrust_exit_code=\"$(git config --bool \\\n+\t\t\t\tmergetool.\"$1\".trustExitCode || echo false)\"\n+\t\t\tif test \"$trust_exit_code\" = \"false\"; then\n \t\t\t\ttouch \"$BACKUP\"\n \t\t\t\t( eval $merge_tool_cmd )\n \t\t\t\tcheck_unchanged\n@@ -315,64 +320,66 @@ guess_merge_tool () {\n \tdo\n \t\tmerge_tool_path=\"$(translate_merge_tool_path \"$i\")\"\n \t\tif type \"$merge_tool_path\" > /dev/null 2>&1; then\n-\t\t\tmerge_tool=\"$i\"\n-\t\t\tbreak\n+\t\t\techo \"$i\"\n+\t\t\treturn 0\n \t\tfi\n \tdone\n \n-\tif test -z \"$merge_tool\" ; then\n-\t\techo >&2 \"No known merge resolution program available.\"\n-\t\treturn 1\n-\tfi\n-\techo \"$merge_tool\"\n+\techo >&2 \"No known merge resolution program available.\"\n+\treturn 1\n }\n \n get_configured_merge_tool () {\n \t# Diff mode first tries diff.tool and falls back to merge.tool.\n \t# Merge mode only checks merge.tool\n \tif diff_mode; then\n-\t\ttool=$(git config diff.tool)\n-\tfi\n-\tif test -z \"$tool\"; then\n-\t\ttool=$(git config merge.tool)\n+\t\tmerge_tool=$(git config diff.tool || git config merge.tool)\n+\telse\n+\t\tmerge_tool=$(git config merge.tool)\n \tfi\n \tif test -n \"$merge_tool\" && ! valid_tool \"$merge_tool\"; then\n \t\techo >&2 \"git config option $TOOL_MODE.tool set to unknown tool: $merge_tool\"\n \t\techo >&2 \"Resetting to default...\"\n \t\treturn 1\n \tfi\n-\techo \"$tool\"\n+\techo \"$merge_tool\"\n }\n \n get_merge_tool_path () {\n \t# A merge tool has been set, so verify that it's valid.\n+\tif test -n \"$1\"; then\n+\t\tmerge_tool=\"$1\"\n+\telse\n+\t\tmerge_tool=\"$(get_merge_tool)\"\n+\tfi\n \tif ! valid_tool \"$merge_tool\"; then\n \t\techo >&2 \"Unknown merge tool $merge_tool\"\n \t\texit 1\n \tfi\n \tif diff_mode; then\n-\t\tmerge_tool_path=$(git config difftool.\"$merge_tool\".path)\n+\t\tmerge_tool_path=$(git config difftool.\"$merge_tool\".path ||\n+\t\t                  git config mergetool.\"$merge_tool\".path)\n+\telse\n+\t\tmerge_tool_path=$(git config mergetool.\"$merge_tool\".path)\n \tfi\n \tif test -z \"$merge_tool_path\"; then\n-\t\tmerge_tool_path=$(git config mergetool.\"$merge_tool\".path)\n+\t\tmerge_tool_path=\"$(translate_merge_tool_path \"$merge_tool\")\"\n \tfi\n-\tmerge_tool_path=\"$(translate_merge_tool_path \"$merge_tool\" \"$merge_tool_path\")\"\n-\tif test -z \"$merge_tool_cmd\" && ! type \"$merge_tool_path\" > /dev/null 2>&1; then\n-\t\techo >&2 \"The $TOOL_MODE tool $merge_tool is not available as '$merge_tool_path'\"\n+\tif test -z \"$(get_merge_tool_cmd \"$merge_tool\")\" &&\n+\t! type \"$merge_tool_path\" > /dev/null 2>&1; then\n+\t\techo >&2 \"The $TOOL_MODE tool $merge_tool is not available as\"\\\n+\t\t         \"'$merge_tool_path'\"\n \t\texit 1\n \tfi\n \techo \"$merge_tool_path\"\n }\n \n get_merge_tool () {\n-\tmerge_tool=\"$1\"\n \t# Check if a merge tool has been configured\n-\tif test -z \"$merge_tool\"; then\n-\t\tmerge_tool=$(get_configured_merge_tool)\n-\tfi\n+\tmerge_tool=$(get_configured_merge_tool)\n \t# Try to guess an appropriate merge tool if no tool has been set.\n \tif test -z \"$merge_tool\"; then\n-\t\tmerge_tool=$(guess_merge_tool) || exit\n+\t\tmerge_tool=\"$(guess_merge_tool)\" || exit\n \tfi\n \techo \"$merge_tool\"\n }\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex 2e3e02b..b52a741 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -174,9 +174,11 @@ merge_file () {\n \tread ans\n     fi\n \n-    present=false\n-    base_present &&\n-    present=true\n+    if base_present; then\n+\t    present=true\n+    else\n+\t    present=false\n+    fi\n \n     if ! run_merge_tool \"$merge_tool\" \"$present\"; then\n \techo \"merge of $MERGED failed\" 1>&2\n@@ -254,12 +256,11 @@ prompt_after_failed_merge() {\n     done\n }\n \n-merge_tool=$(get_merge_tool \"$merge_tool\") || exit\n-merge_tool_cmd=\"$(get_merge_tool_cmd \"$merge_tool\")\"\n-merge_tool_path=\"$(get_merge_tool_path \"$merge_tool\")\" || exit\n+if test -z \"$merge_tool\"; then\n+    merge_tool=$(get_merge_tool \"$merge_tool\") || exit\n+fi\n merge_keep_backup=\"$(git config --bool mergetool.keepBackup || echo true)\"\n merge_keep_temporaries=\"$(git config --bool mergetool.keepTemporaries || echo false)\"\n-merge_tool_trust_exit_code=\"$(git config --bool mergetool.\"$merge_tool\".trustExitCode || echo false)\"\n \n last_status=0\n rollup_status=0\n-- \n1.6.2.2.471.g6da14\n"}]}