{"thread":{"id":"18633","subject":"[PATCH 6/8 v2] sh-tools: add a run_merge_tool function","startedAt":"2009-03-30T08:11:24Z","lastAt":"2009-04-02T05:33:46Z","messageCount":5,"participants":["David Aguilar","James Pickens","Markus Heidelberg"],"isPatch":true,"patchVersion":2,"patchTotal":8},"messages":[{"id":"109853","messageId":"1238400684-14881-1-git-send-email-davvid@gmail.com","threadId":"18633","inReplyTo":null,"subject":"[PATCH 6/8 v2] sh-tools: add a run_merge_tool function","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-03-30T08:11:24Z","receivedAt":"2009-03-30T08:11:24Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"This function launches merge tools and will be used to refactor\ngit-(diff|merge)tool.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\n\nThis fixes the problems spotted by Markus.\n\n Documentation/git-sh-tools.txt |    3 +\n git-sh-tools.sh                |  160 +++++++++++++++++++++++++++++++++++++--\n 2 files changed, 154 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/git-sh-tools.txt b/Documentation/git-sh-tools.txt\nindex 055a10c..68d1b37 100644\n--- a/Documentation/git-sh-tools.txt\n+++ b/Documentation/git-sh-tools.txt\n@@ -36,6 +36,9 @@ init_merge_tool_path::\n \tsets up `$merge_tool_path` according to '(diff|merge)tool.<tool>.path'\n \tconfigurations.\n \n+run_merge_tool::\n+\truns the specified merge tool.\n+\n Author\n ------\n Written by David Aguilar <davvid@gmail.com>\ndiff --git a/git-sh-tools.sh b/git-sh-tools.sh\nindex 234bac7..e8593fc 100644\n--- a/git-sh-tools.sh\n+++ b/git-sh-tools.sh\n@@ -2,7 +2,12 @@\n # Built-in merge tools are always valid.\n valid_tool() {\n \tcase \"$1\" in\n-\tkdiff3 | kompare | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | ecmerge)\n+\tkompare)\n+\t\tif mergetool_mode; then\n+\t\t\treturn 1\n+\t\tfi\n+\t\t;; # happy\n+\tkdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | ecmerge)\n \t\t;; # happy\n \t*)\n \t\tif ! valid_custom_tool \"$1\"; then\n@@ -12,29 +17,34 @@ valid_tool() {\n \tesac\n }\n \n+# Test whether we're in merge mode\n+mergetool_mode()\n+{\n+\ttest \"$TOOL_MODE\" = \"merge\"\n+}\n+\n # Verifies that (difftool|mergetool).<tool>.cmd exists\n # Requires $TOOL_MODE to be set.\n valid_custom_tool() {\n-\tif test \"$TOOL_MODE\" = \"diff\"; then\n-\t\tmerge_tool_cmd=\"$(git config difftool.$1.cmd)\"\n-\t\ttest -z \"$merge_tool_cmd\" &&\n+\tif mergetool_mode; then\n \t\tmerge_tool_cmd=\"$(git config mergetool.$1.cmd)\"\n \t\ttest -n \"$merge_tool_cmd\"\n-\telif test \"$TOOL_MODE\" = \"merge\"; then\n+\telse\n+\t\tmerge_tool_cmd=\"$(git config difftool.$1.cmd)\"\n+\t\ttest -z \"$merge_tool_cmd\" &&\n \t\tmerge_tool_cmd=\"$(git config mergetool.$1.cmd)\"\n \t\ttest -n \"$merge_tool_cmd\"\n \tfi\n }\n \n-\n # Set up $merge_tool_path for (diff|merge)tool.<tool>.path configurations\n init_merge_tool_path() {\n-\tif test \"$TOOL_MODE\" = \"diff\"; then\n+\tif mergetool_mode; then\n+\t\tmerge_tool_path=$(git config mergetool.\"$1\".path)\n+\telse\n \t\tmerge_tool_path=$(git config difftool.\"$1\".path)\n \t\ttest -z \"$merge_tool_path\" &&\n \t\tmerge_tool_path=$(git config mergetool.\"$1\".path)\n-\telif test \"$TOOL_MODE\" = \"merge\"; then\n-\t\tmerge_tool_path=$(git config mergetool.\"$1\".path)\n \tfi\n \n \tif test -z \"$merge_tool_path\" ; then\n@@ -48,3 +58,135 @@ init_merge_tool_path() {\n \t\tesac\n \tfi\n }\n+\n+# Runs a side-by-side merge tool\n+run_merge_tool()\n+{\n+\tmerge_tool=\"$1\"\n+\n+\t# base_present is always false when !mergetool_mode\n+\tcase \"$merge_tool\" in\n+\tkdiff3)\n+\t\tif mergetool_mode; then\n+\t\t\tbase=Base\n+\t\t\tlocal=Local\n+\t\t\tremote=Remote\n+\t\telse\n+\t\t\tbase=A\n+\t\t\tlocal=A\n+\t\t\tremote=B\n+\t\tfi\n+\t\tif base_present; then\n+\t\t\t(\"$merge_tool_path\" --auto \\\n+\t\t\t\t--L1 \"$MERGED ($base)\" \\\n+\t\t\t\t--L2 \"$MERGED ($local)\" \\\n+\t\t\t\t--L3 \"$MERGED ($remote)\" \\\n+\t\t\t\t-o \"$MERGED\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \\\n+\t\t\t > /dev/null 2>&1)\n+\t\telse\n+\t\t\t(\"$merge_tool_path\" --auto \\\n+\t\t\t\t--L1 \"$MERGED ($local)\" \\\n+\t\t\t\t--L2 \"$MERGED ($remote)\" \\\n+\t\t\t\t-o \"$MERGED\" \"$LOCAL\" \"$REMOTE\" \\\n+\t\t\t > /dev/null 2>&1)\n+\t\tfi\n+\t\tstatus=$?\n+\t\t;;\n+\n+\tkompare)\n+\t\t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n+\t\tstatus=$?\n+\t\t;;\n+\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\t\"$merge_tool_path\" -o \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n+\t\tfi\n+\t\tstatus=$?\n+\t\t;;\n+\tmeld)\n+\t\tmergetool_mode && touch \"$BACKUP\"\n+\t\t\"$merge_tool_path\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\tmergetool_mode && check_unchanged\n+\t\t;;\n+\tvimdiff)\n+\t\tmergetool_mode && touch \"$BACKUP\"\n+\t\t\"$merge_tool_path\" -c \"wincmd l\" \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\tmergetool_mode && check_unchanged\n+\t\t;;\n+\tgvimdiff)\n+\t\tmergetool_mode && touch \"$BACKUP\"\n+\t\t\"$merge_tool_path\" -c \"wincmd l\" -f \"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\tmergetool_mode && check_unchanged\n+\t\t;;\n+\txxdiff)\n+\t\tif mergetool_mode; then\n+\t\t\ttouch \"$BACKUP\"\n+\t\t\txtra_args='--show-merged-pane'\n+\t\telse\n+\t\t\txtra_args=\n+\t\tfi\n+\t\tif base_present; then\n+\t\t\t\"$merge_tool_path\" -X $xtra_args \\\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\" \"$BASE\" \"$REMOTE\"\n+\t\telse\n+\t\t\t\"$merge_tool_path\" -X $xtra_args \\\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\tmergetool_mode && check_unchanged\n+\t\t;;\n+\topendiff)\n+\t\tmergetool_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\tmergetool_mode && check_unchanged\n+\t\t;;\n+\tecmerge)\n+\t\tmergetool_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\tmergetool_mode && check_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 test \"$merge_tool_trust_exit_code\" = \"false\"; then\n+\t\t\t\tmergetool_mode && touch \"$BACKUP\"\n+\t\t\t\t( eval $merge_tool_cmd )\n+\t\t\t\tmergetool_mode && check_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+\treturn $status\n+}\n-- \n1.6.2.1.303.g63699\n"},{"id":"110046","messageId":"885649360903311115o6131988emdcba6ef215ec0ab0@mail.gmail.com","threadId":"18633","inReplyTo":"1238400684-14881-1-git-send-email-davvid@gmail.com","subject":"Re: [PATCH 6/8 v2] sh-tools: add a run_merge_tool function","fromName":"James Pickens","fromEmail":"jepicken@gmail.com","sentAt":"2009-03-31T18:15:52Z","receivedAt":"2009-03-31T18:15:52Z","isPatch":true,"sender":{"key":"jepicken@gmail.com","avatar":null},"body":"On Mon, Mar 30, 2009 at 1:11 AM, David Aguilar <davvid@gmail.com> wrote:\n> This function launches merge tools and will be used to refactor\n> git-(diff|merge)tool.\n\nThanks for writing difftool; I find it quite useful.  I tried it with\ntkdiff, and noticed that it shows the 'merge preview' window even though it\nisn't doing a merge.  If a user with unstaged changes were to carelessly\nclick the 'save and exit' button, his changes could be lost.  So I think\nit's a good idea to stop the merge preview window from showing up under\ndifftool.  To do that I think you just have to remove the '-o \"$MERGED\"'\noption to tkdiff.\n\nJames\n"},{"id":"110072","messageId":"200904010011.10296.markus.heidelberg@web.de","threadId":"18633","inReplyTo":"885649360903311115o6131988emdcba6ef215ec0ab0@mail.gmail.com","subject":"Re: [PATCH 6/8 v2] sh-tools: add a run_merge_tool function","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2009-03-31T22:11:09Z","receivedAt":"2009-03-31T22:11:09Z","isPatch":true,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"James Pickens, 31.03.2009:\n> On Mon, Mar 30, 2009 at 1:11 AM, David Aguilar <davvid@gmail.com> wrote:\n> > This function launches merge tools and will be used to refactor\n> > git-(diff|merge)tool.\n> \n> Thanks for writing difftool; I find it quite useful.  I tried it with\n> tkdiff, and noticed that it shows the 'merge preview' window even though it\n> isn't doing a merge.  If a user with unstaged changes were to carelessly\n> click the 'save and exit' button, his changes could be lost.  So I think\n> it's a good idea to stop the merge preview window from showing up under\n> difftool.  To do that I think you just have to remove the '-o \"$MERGED\"'\n> option to tkdiff.\n\nThis mail made me see an issue with your patch series. Sorry, I haven't\nseen this earlier, my review was just scratching the surface, I merely\napplied it and looked through it, but didn't actually test it. Lack of\ntime.\n\nThe invocations seem to be appropriate only for mergetool, it is just\nthe invocations from the old git-mergetool.sh, not from the old\ngit-difftool-helper.sh. This means, git-difftool opens 3 files instead\nof 2.\n\nI think there are preset diff tools, which opened 3 files instead of 2\nbefore this series (I just tested kdiff3, it opened 3 files). Seems to\nbe originated from the fact, that they were initially copied from\ngit-mergetool.sh.\n\nMarkus\n"},{"id":"110105","messageId":"20090401083649.GA30594@gmail.com","threadId":"18633","inReplyTo":"200904010011.10296.markus.heidelberg@web.de","subject":"Re: [PATCH 6/8 v2] sh-tools: add a run_merge_tool function","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-04-01T08:36:49Z","receivedAt":"2009-04-01T08:36:49Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"\nOn  0, Markus Heidelberg <markus.heidelberg@web.de> wrote:\n> James Pickens, 31.03.2009:\n> > On Mon, Mar 30, 2009 at 1:11 AM, David Aguilar <davvid@gmail.com> wrote:\n> > > This function launches merge tools and will be used to refactor\n> > > git-(diff|merge)tool.\n\nsorry this whole series is being rewriten...\n\n\n> > \n> > Thanks for writing difftool; I find it quite useful.  I tried it with\n> > tkdiff, and noticed that it shows the 'merge preview' window even though it\n> > isn't doing a merge.  If a user with unstaged changes were to carelessly\n> > click the 'save and exit' button, his changes could be lost.  So I think\n> > it's a good idea to stop the merge preview window from showing up under\n> > difftool.  To do that I think you just have to remove the '-o \"$MERGED\"'\n> > option to tkdiff.\n> \n> This mail made me see an issue with your patch series. Sorry, I haven't\n> seen this earlier, my review was just scratching the surface, I merely\n> applied it and looked through it, but didn't actually test it. Lack of\n> time.\n> \n> The invocations seem to be appropriate only for mergetool, it is just\n> the invocations from the old git-mergetool.sh, not from the old\n> git-difftool-helper.sh. This means, git-difftool opens 3 files instead\n> of 2.\n> \n> I think there are preset diff tools, which opened 3 files instead of 2\n> before this series (I just tested kdiff3, it opened 3 files). Seems to\n> be originated from the fact, that they were initially copied from\n> git-mergetool.sh.\n> \n> Markus\n> \n\n-- \n\t\tDavid\n"},{"id":"110194","messageId":"20090402053345.GA4185@gmail.com","threadId":"18633","inReplyTo":"885649360903311115o6131988emdcba6ef215ec0ab0@mail.gmail.com","subject":"Re: [PATCH 6/8 v2] sh-tools: add a run_merge_tool function","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-04-02T05:33:46Z","receivedAt":"2009-04-02T05:33:46Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On  0, James Pickens <jepicken@gmail.com> wrote:\n> On Mon, Mar 30, 2009 at 1:11 AM, David Aguilar <davvid@gmail.com> wrote:\n> > This function launches merge tools and will be used to refactor\n> > git-(diff|merge)tool.\n> \n> Thanks for writing difftool; I find it quite useful.  I tried it with\n> tkdiff, and noticed that it shows the 'merge preview' window even though it\n> isn't doing a merge.  If a user with unstaged changes were to carelessly\n> click the 'save and exit' button, his changes could be lost.  So I think\n> it's a good idea to stop the merge preview window from showing up under\n> difftool.  To do that I think you just have to remove the '-o \"$MERGED\"'\n> option to tkdiff.\n> \n> James\n\nHi James\n\nI included your suggestion in my latest patch series.\nOnce things settle down with the current series I'll\nadd diffuse to {diff,merge}tool and friends.\n\nSo, yup, this shouldn't be an issue in future versions of\ndifftool.\n\nThanks\n\n-- \n\n\tDavid\n"}]}