{"thread":{"id":"18687","subject":"[PATCH v2 03/10] Add a mergetool-lib scriptlet for holding common merge tool functions","startedAt":"2009-04-02T04:20:38Z","lastAt":"2009-04-02T04:20:40Z","messageCount":3,"participants":["David Aguilar"],"isPatch":true,"patchVersion":2,"patchTotal":10},"messages":[{"id":"110185","messageId":"1238646040-46008-1-git-send-email-davvid@gmail.com","threadId":"18687","inReplyTo":null,"subject":"[PATCH v2 03/10] Add a mergetool-lib scriptlet for holding common merge tool functions","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-04-02T04:20:38Z","receivedAt":"2009-04-02T04:20:38Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"git-mergetool-lib provides common merge tool functions.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nIncludes fixups from Markus\n\n .gitignore                          |    1 +\n Documentation/git-mergetool-lib.txt |   42 +++++++++++++++++++++++++++++++++++\n Makefile                            |    1 +\n command-list.txt                    |    1 +\n git-mergetool-lib.sh                |   42 +++++++++++++++++++++++++++++++++++\n 5 files changed, 87 insertions(+), 0 deletions(-)\n create mode 100644 Documentation/git-mergetool-lib.txt\n create mode 100644 git-mergetool-lib.sh\n\ndiff --git a/.gitignore b/.gitignore\nindex 966c886..75c154a 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -80,6 +80,7 @@ git-merge-recursive\n git-merge-resolve\n git-merge-subtree\n git-mergetool\n+git-mergetool-lib\n git-mktag\n git-mktree\n git-name-rev\ndiff --git a/Documentation/git-mergetool-lib.txt b/Documentation/git-mergetool-lib.txt\nnew file mode 100644\nindex 0000000..a8d62f5\n--- /dev/null\n+++ b/Documentation/git-mergetool-lib.txt\n@@ -0,0 +1,42 @@\n+git-mergetool-lib(1)\n+====================\n+\n+NAME\n+----\n+git-mergetool-lib - Common git merge tool shell scriptlets\n+\n+SYNOPSIS\n+--------\n+'. \"$(git --exec-path)/git-mergetool-lib\"'\n+\n+DESCRIPTION\n+-----------\n+\n+This is not a command the end user would want to run.  Ever.\n+This documentation is meant for people who are studying the\n+Porcelain-ish scripts and/or are writing new ones.\n+\n+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+\n+FUNCTIONS\n+---------\n+get_merge_tool_path::\n+\treturns the `merge_tool_path` for a `merge_tool`.\n+\n+Author\n+------\n+Written by David Aguilar <davvid@gmail.com>\n+\n+Documentation\n+--------------\n+Documentation by David Aguilar and the git-list <git@vger.kernel.org>.\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\ndiff --git a/Makefile b/Makefile\nindex d77fd71..086f9e7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -284,6 +284,7 @@ SCRIPT_SH += git-merge-octopus.sh\n SCRIPT_SH += git-merge-one-file.sh\n SCRIPT_SH += git-merge-resolve.sh\n SCRIPT_SH += git-mergetool.sh\n+SCRIPT_SH += git-mergetool-lib.sh\n SCRIPT_SH += git-parse-remote.sh\n SCRIPT_SH += git-pull.sh\n SCRIPT_SH += git-quiltimport.sh\ndiff --git a/command-list.txt b/command-list.txt\nindex fb03a2e..922c815 100644\n--- a/command-list.txt\n+++ b/command-list.txt\n@@ -69,6 +69,7 @@ git-merge-file                          plumbingmanipulators\n git-merge-index                         plumbingmanipulators\n git-merge-one-file                      purehelpers\n git-mergetool                           ancillarymanipulators\n+git-mergetool-lib                       purehelpers\n git-merge-tree                          ancillaryinterrogators\n git-mktag                               plumbingmanipulators\n git-mktree                              plumbingmanipulators\ndiff --git a/git-mergetool-lib.sh b/git-mergetool-lib.sh\nnew file mode 100644\nindex 0000000..5f9ba97\n--- /dev/null\n+++ b/git-mergetool-lib.sh\n@@ -0,0 +1,42 @@\n+# git-mergetool-lib is a library for common merge tool functions\n+diff_mode() {\n+\ttest $TOOL_MODE = \"diff\"\n+}\n+\n+get_merge_tool_path () {\n+\tif test -z \"$2\"; then\n+\t\tcase \"$1\" in\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+\tfi\n+\techo \"$path\"\n+}\n+\n+valid_tool () {\n+\tcase \"$1\" in\n+\tkdiff3 | kompare | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | ecmerge)\n+\t\tif test \"$1\" = \"kompare\" && ! diff_mode; then\n+\t\t\treturn 1\n+\t\tfi\n+\t\t;; # happy\n+\t*)\n+\t\tif test -z \"$(get_custom_cmd \"$1\")\"; then\n+\t\t\treturn 1\n+\t\tfi\n+\t\t;;\n+\tesac\n+}\n+\n+get_custom_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+}\n-- \n1.6.1.3\n"},{"id":"110187","messageId":"1238646040-46008-2-git-send-email-davvid@gmail.com","threadId":"18687","inReplyTo":"1238646040-46008-1-git-send-email-davvid@gmail.com","subject":"[PATCH v2 08/10] mergetool-lib: introduce run_mergetool","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-04-02T04:20:39Z","receivedAt":"2009-04-02T04:20:39Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"run_mergetool contains the common functionality for launching\nmergetools.  There's some context-specific behavior but overall\nit's better to have all of this stuff in one place versus multiple\nplaces.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nInclude fixups from Markus\n\n Documentation/git-mergetool-lib.txt |   10 +++\n git-mergetool-lib.sh                |  141 +++++++++++++++++++++++++++++++++++\n 2 files changed, 151 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-mergetool-lib.txt b/Documentation/git-mergetool-lib.txt\nindex a8d62f5..7377774 100644\n--- a/Documentation/git-mergetool-lib.txt\n+++ b/Documentation/git-mergetool-lib.txt\n@@ -29,6 +29,16 @@ FUNCTIONS\n get_merge_tool_path::\n \treturns the `merge_tool_path` for a `merge_tool`.\n \n+run_mergetool::\n+\tlaunches a merge tool given the tool name and a true/false\n+\tflag to indicate whether a merge base is present\n+\n+valid_tool::\n+\ttests whether a merge tool is setup correctly.\n+\n+get_custom_cmd::\n+\tgiven a merge tool, returns the custom command for that tool.\n+\n Author\n ------\n Written by David Aguilar <davvid@gmail.com>\ndiff --git a/git-mergetool-lib.sh b/git-mergetool-lib.sh\nindex 5f9ba97..d28be68 100644\n--- a/git-mergetool-lib.sh\n+++ b/git-mergetool-lib.sh\n@@ -3,7 +3,12 @@ diff_mode() {\n \ttest $TOOL_MODE = \"diff\"\n }\n \n+merge_mode() {\n+\ttest $TOOL_MODE = \"merge\"\n+}\n+\n get_merge_tool_path () {\n+\tpath=\"$1\"\n \tif test -z \"$2\"; then\n \t\tcase \"$1\" in\n \t\temerge)\n@@ -17,6 +22,11 @@ get_merge_tool_path () {\n \techo \"$path\"\n }\n \n+# Overridden in git-mergetool\n+check_unchanged () {\n+\ttrue\n+}\n+\n valid_tool () {\n \tcase \"$1\" in\n \tkdiff3 | kompare | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | ecmerge)\n@@ -40,3 +50,134 @@ get_custom_cmd () {\n \ttest -n \"$custom_cmd\" &&\n \techo \"$custom_cmd\"\n }\n+\n+run_mergetool () {\n+\tbase_present=\"$2\"\n+\tif diff_mode; then\n+\t\tbase_present=\"false\"\n+\tfi\n+\tif test -z \"$base_present\"; then\n+\t\tbase_present=\"true\"\n+\tfi\n+\n+\tcase \"$1\" in\n+\tkdiff3)\n+\t\tif $base_present; then\n+\t\t\t(\"$merge_tool_path\" --auto \\\n+\t\t\t --L1 \"$MERGED (Base)\" --L2 \"$MERGED (Local)\" --L3 \"$MERGED (Remote)\" \\\n+\t\t\t -o \"$MERGED\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" > /dev/null 2>&1)\n+\t\telse\n+\t\t\t(\"$merge_tool_path\" --auto \\\n+\t\t\t --L1 \"$MERGED (Local)\" --L2 \"$MERGED (Remote)\" \\\n+\t\t\t -o \"$MERGED\" \"$LOCAL\" \"$REMOTE\" > /dev/null 2>&1)\n+\t\tfi\n+\t\tstatus=$?\n+\t\t;;\n+\tkompare)\n+\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n+\t\tstatus=$?\n+\t\t;;\n+\ttkdiff)\n+\t\tif $base_present; then\n+\t\t\t\"$merge_tool_path\" -a \"$BASE\" -o \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n+\t\telse\n+\t\t\tif merge_mode; then\n+\t\t\t\t\"$merge_tool_path\" -o \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n+\t\t\telse\n+\t\t\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n+\t\t\tfi\n+\t\tfi\n+\t\tstatus=$?\n+\t\t;;\n+\tmeld)\n+\t\tif merge_mode; then\n+\t\t\ttouch \"$BACKUP\"\n+\t\t\t\"$merge_tool_path\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\telse\n+\t\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n+\t\tfi\n+\t\tcheck_unchanged\n+\t\t;;\n+\tvimdiff)\n+\t\tif merge_mode; then\n+\t\t\ttouch \"$BACKUP\"\n+\t\t\t\"$merge_tool_path\" -c \"wincmd l\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\t\tcheck_unchanged\n+\t\telse\n+\t\t\t\"$merge_tool_path\" -c \"wincmd l\" \"$LOCAL\" \"$REMOTE\"\n+\t\tfi\n+\t\t;;\n+\tgvimdiff)\n+\t\tif merge_mode; then\n+\t\t\ttouch \"$BACKUP\"\n+\t\t\t\"$merge_tool_path\" -c \"wincmd l\" -f \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\t\tcheck_unchanged\n+\t\telse\n+\t\t\t\"$merge_tool_path\" -c \"wincmd l\" -f \"$LOCAL\" \"$REMOTE\"\n+\t\tfi\n+\t\t;;\n+\txxdiff)\n+\t\tmerge_mode && touch \"$BACKUP\"\n+\t\tif $base_present; then\n+\t\t\t\"$merge_tool_path\" -X --show-merged-pane \\\n+\t\t\t    -R 'Accel.SaveAsMerged: \"Ctrl-S\"' \\\n+\t\t\t    -R 'Accel.Search: \"Ctrl+F\"' \\\n+\t\t\t    -R 'Accel.SearchForward: \"Ctrl-G\"' \\\n+\t\t\t    --merged-file \"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"\n+\t\telse\n+\t\t\tmerge_mode && extra=--show-merged-pane\n+\t\t\t\"$merge_tool_path\" -X $extra \\\n+\t\t\t\t-R 'Accel.SaveAsMerged: \"Ctrl-S\"' \\\n+\t\t\t\t-R 'Accel.Search: \"Ctrl+F\"' \\\n+\t\t\t\t-R 'Accel.SearchForward: \"Ctrl-G\"' \\\n+\t\t\t\t--merged-file \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n+\t\tfi\n+\t\tcheck_unchanged\n+\t\t;;\n+\topendiff)\n+\t\tmerge_mode && touch \"$BACKUP\"\n+\t\tif $base_present; then\n+\t\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" \\\n+\t\t\t\t-ancestor \"$BASE\" -merge \"$MERGED\" | cat\n+\t\telse\n+\t\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" \\\n+\t\t\t\t-merge \"$MERGED\" | cat\n+\t\tfi\n+\t\tcheck_unchanged\n+\t\t;;\n+\tecmerge)\n+\t\tmerge_mode && touch \"$BACKUP\"\n+\t\tif $base_present; then\n+\t\t\t\"$merge_tool_path\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \\\n+\t\t\t\t--default --mode=merge3 --to=\"$MERGED\"\n+\t\telse\n+\t\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" \\\n+\t\t\t\t--default --mode=merge2 --to=\"$MERGED\"\n+\t\tfi\n+\t\tcheck_unchanged\n+\t\t;;\n+\temerge)\n+\t\tif $base_present; then\n+\t\t\t\"$merge_tool_path\" -f emerge-files-with-ancestor-command \\\n+\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$(basename \"$MERGED\")\"\n+\t\telse\n+\t\t\t\"$merge_tool_path\" -f emerge-files-command \\\n+\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$(basename \"$MERGED\")\"\n+\t\tfi\n+\t\tstatus=$?\n+\t\t;;\n+\t*)\n+\t\tif test -n \"$merge_tool_cmd\"; then\n+\t\t\tif merge_mode &&\n+\t\t\ttest \"$merge_tool_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+\t\t\telse\n+\t\t\t\t( eval $merge_tool_cmd )\n+\t\t\t\tstatus=$?\n+\t\t\tfi\n+\t\tfi\n+\t\t;;\n+\tesac\n+}\n-- \n1.6.1.3\n"},{"id":"110186","messageId":"1238646040-46008-3-git-send-email-davvid@gmail.com","threadId":"18687","inReplyTo":"1238646040-46008-2-git-send-email-davvid@gmail.com","subject":"[PATCH v2 10/10] mergetool: use run_mergetool from git-mergetool-lib","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-04-02T04:20:40Z","receivedAt":"2009-04-02T04:20:40Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"This refactors git-mergetool to use run_mergetool.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nIncludes fixups from Markus\n\n git-mergetool.sh |   96 +++--------------------------------------------------\n 1 files changed, 6 insertions(+), 90 deletions(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex 957993c..fd81ad7 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -190,96 +190,12 @@ merge_file () {\n \tread ans\n     fi\n \n-    case \"$merge_tool\" in\n-\tkdiff3)\n-\t    if base_present ; then\n-\t\t(\"$merge_tool_path\" --auto --L1 \"$MERGED (Base)\" --L2 \"$MERGED (Local)\" --L3 \"$MERGED (Remote)\" \\\n-\t\t    -o \"$MERGED\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" > /dev/null 2>&1)\n-\t    else\n-\t\t(\"$merge_tool_path\" --auto --L1 \"$MERGED (Local)\" --L2 \"$MERGED (Remote)\" \\\n-\t\t    -o \"$MERGED\" \"$LOCAL\" \"$REMOTE\" > /dev/null 2>&1)\n-\t    fi\n-\t    status=$?\n-\t    ;;\n-\ttkdiff)\n-\t    if base_present ; then\n-\t\t\"$merge_tool_path\" -a \"$BASE\" -o \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n-\t    else\n-\t\t\"$merge_tool_path\" -o \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n-\t    fi\n-\t    status=$?\n-\t    ;;\n-\tmeld)\n-\t    touch \"$BACKUP\"\n-\t    \"$merge_tool_path\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n-\t    check_unchanged\n-\t    ;;\n-\tvimdiff)\n-\t    touch \"$BACKUP\"\n-\t    \"$merge_tool_path\" -c \"wincmd l\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n-\t    check_unchanged\n-\t    ;;\n-\tgvimdiff)\n-\t    touch \"$BACKUP\"\n-\t    \"$merge_tool_path\" -c \"wincmd l\" -f \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n-\t    check_unchanged\n-\t    ;;\n-\txxdiff)\n-\t    touch \"$BACKUP\"\n-\t    if base_present ; then\n-\t\t\"$merge_tool_path\" -X --show-merged-pane \\\n-\t\t    -R 'Accel.SaveAsMerged: \"Ctrl-S\"' \\\n-\t\t    -R 'Accel.Search: \"Ctrl+F\"' \\\n-\t\t    -R 'Accel.SearchForward: \"Ctrl-G\"' \\\n-\t\t    --merged-file \"$MERGED\" \"$LOCAL\" \"$BASE\" \"$REMOTE\"\n-\t    else\n-\t\t\"$merge_tool_path\" -X --show-merged-pane \\\n-\t\t    -R 'Accel.SaveAsMerged: \"Ctrl-S\"' \\\n-\t\t    -R 'Accel.Search: \"Ctrl+F\"' \\\n-\t\t    -R 'Accel.SearchForward: \"Ctrl-G\"' \\\n-\t\t    --merged-file \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n-\t    fi\n-\t    check_unchanged\n-\t    ;;\n-\topendiff)\n-\t    touch \"$BACKUP\"\n-\t    if base_present; then\n-\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\" | cat\n-\t    else\n-\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" -merge \"$MERGED\" | cat\n-\t    fi\n-\t    check_unchanged\n-\t    ;;\n-\tecmerge)\n-\t    touch \"$BACKUP\"\n-\t    if base_present; then\n-\t\t\"$merge_tool_path\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" --default --mode=merge3 --to=\"$MERGED\"\n-\t    else\n-\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" --default --mode=merge2 --to=\"$MERGED\"\n-\t    fi\n-\t    check_unchanged\n-\t    ;;\n-\temerge)\n-\t    if base_present ; then\n-\t\t\"$merge_tool_path\" -f emerge-files-with-ancestor-command \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$(basename \"$MERGED\")\"\n-\t    else\n-\t\t\"$merge_tool_path\" -f emerge-files-command \"$LOCAL\" \"$REMOTE\" \"$(basename \"$MERGED\")\"\n-\t    fi\n-\t    status=$?\n-\t    ;;\n-\t*)\n-\t    if test -n \"$merge_tool_cmd\"; then\n-\t\tif test \"$merge_tool_trust_exit_code\" = \"false\"; then\n-\t\t    touch \"$BACKUP\"\n-\t\t    ( eval $merge_tool_cmd )\n-\t\t    check_unchanged\n-\t\telse\n-\t\t    ( eval $merge_tool_cmd )\n-\t\t    status=$?\n-\t\tfi\n-\t    fi\n-\t    ;;\n-    esac\n+    present=false\n+    base_present &&\n+    present=true\n+\n+    run_mergetool \"$merge_tool\" \"$present\"\n+\n     if test \"$status\" -ne 0; then\n \techo \"merge of $MERGED failed\" 1>&2\n \tmv -- \"$BACKUP\" \"$MERGED\"\n-- \n1.6.1.3\n"}]}