{"thread":{"id":"37716","subject":"[PATCH] mergetool: add an option for writing to a temporary directory","startedAt":"2014-10-11T17:04:45Z","lastAt":"2014-10-15T20:45:42Z","messageCount":6,"participants":["David Aguilar","Junio C Hamano","Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"250513","messageId":"1413047085-12398-1-git-send-email-davvid@gmail.com","threadId":"37716","inReplyTo":null,"subject":"[PATCH] mergetool: add an option for writing to a temporary directory","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2014-10-11T17:04:45Z","receivedAt":"2014-10-11T17:04:45Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"Teach mergetool to write files in a temporary directory when\n'mergetool.writeToTemp' is true.\n\nThis is helpful for tools such as Eclipse which cannot cope with\nmultiple copies of the same file in the worktree.\n\nSuggested-by: Charles Bailey <charles@hashpling.org>\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\nThis patch is dependent on my previous mergetool patches:\n\"use more conservative temporary...\" and the subsequent --tool-help\nseries.\n\n Documentation/config.txt |  6 ++++++\n git-mergetool.sh         | 35 +++++++++++++++++++++++++++++++----\n 2 files changed, 37 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 04a1e2f..be6cf35 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1768,6 +1768,12 @@ mergetool.keepTemporaries::\n \tpreserved, otherwise they will be removed after the tool has\n \texited. Defaults to `false`.\n \n+mergetool.writeToTemp::\n+\tGit writes temporary 'BASE', 'LOCAL', and 'REMOTE' versions of\n+\tconflicting files in the worktree by default.  Git will attempt\n+\tto use a temporary directory for these files when set `true`.\n+\tDefaults to `false`.\n+\n mergetool.prompt::\n \tPrompt before each invocation of the merge resolution program.\n \ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex 10782b8..2b788c5 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -37,6 +37,19 @@ base_present () {\n \ttest -n \"$base_mode\"\n }\n \n+mergetool_tmpdir_init () {\n+\tif test \"$(git config --bool mergetool.writeToTemp)\" != true\n+\tthen\n+\t\tMERGETOOL_TMPDIR=.\n+\t\treturn 0\n+\tfi\n+\tif MERGETOOL_TMPDIR=$(mktemp -d -t \"git-mergetool-XXXXXX\" 2>/dev/null)\n+\tthen\n+\t\treturn 0\n+\tfi\n+\tdie \"error: mktemp is needed when 'mergetool.writeToTemp' is true\"\n+}\n+\n cleanup_temp_files () {\n \tif test \"$1\" = --save-backup\n \tthen\n@@ -46,6 +59,10 @@ cleanup_temp_files () {\n \telse\n \t\trm -f -- \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$BACKUP\"\n \tfi\n+\tif test \"$MERGETOOL_TMPDIR\" != \".\"\n+\tthen\n+\t\trmdir \"$MERGETOOL_TMPDIR\"\n+\tfi\n }\n \n describe_file () {\n@@ -235,10 +252,20 @@ merge_file () {\n \t\tBASE=$MERGED\n \t\text=\n \tfi\n-\tBACKUP=\"./${BASE}_BACKUP_$$$ext\"\n-\tLOCAL=\"./${BASE}_LOCAL_$$$ext\"\n-\tREMOTE=\"./${BASE}_REMOTE_$$$ext\"\n-\tBASE=\"./${BASE}_BASE_$$$ext\"\n+\n+\tmergetool_tmpdir_init\n+\n+\tif test \"$MERGETOOL_TMPDIR\" != \".\"\n+\tthen\n+\t\t# If we're using a temporary directory then write to the\n+\t\t# top-level of that directory.\n+\t\tBASE=${BASE##*/}\n+\tfi\n+\n+\tBACKUP=\"$MERGETOOL_TMPDIR/${BASE}_BACKUP_$$$ext\"\n+\tLOCAL=\"$MERGETOOL_TMPDIR/${BASE}_LOCAL_$$$ext\"\n+\tREMOTE=\"$MERGETOOL_TMPDIR/${BASE}_REMOTE_$$$ext\"\n+\tBASE=\"$MERGETOOL_TMPDIR/${BASE}_BASE_$$$ext\"\n \n \tbase_mode=$(git ls-files -u -- \"$MERGED\" | awk '{if ($3==1) print $1;}')\n \tlocal_mode=$(git ls-files -u -- \"$MERGED\" | awk '{if ($3==2) print $1;}')\n-- \n2.1.2.379.gc4e1e0c\n"},{"id":"250568","messageId":"xmqqoatf3hir.fsf@gitster.dls.corp.google.com","threadId":"37716","inReplyTo":"1413047085-12398-1-git-send-email-davvid@gmail.com","subject":"Re: [PATCH] mergetool: add an option for writing to a temporary directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-10-13T19:18:36Z","receivedAt":"2014-10-13T19:18:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Aguilar <davvid@gmail.com> writes:\n\n> Teach mergetool to write files in a temporary directory when\n> 'mergetool.writeToTemp' is true.\n>\n> This is helpful for tools such as Eclipse which cannot cope with\n> multiple copies of the same file in the worktree.\n>\n> Suggested-by: Charles Bailey <charles@hashpling.org>\n> Signed-off-by: David Aguilar <davvid@gmail.com>\n> ---\n> This patch is dependent on my previous mergetool patches:\n> \"use more conservative temporary...\" and the subsequent --tool-help\n> series.\n\nI can understand why it depends on the \"foo_BACKUP_1234.c\" change,\nbut why does it need to depend on the other one?\n\n>\n>  Documentation/config.txt |  6 ++++++\n>  git-mergetool.sh         | 35 +++++++++++++++++++++++++++++++----\n>  2 files changed, 37 insertions(+), 4 deletions(-)\n>\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index 04a1e2f..be6cf35 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -1768,6 +1768,12 @@ mergetool.keepTemporaries::\n>  \tpreserved, otherwise they will be removed after the tool has\n>  \texited. Defaults to `false`.\n>  \n> +mergetool.writeToTemp::\n> +\tGit writes temporary 'BASE', 'LOCAL', and 'REMOTE' versions of\n> +\tconflicting files in the worktree by default.  Git will attempt\n> +\tto use a temporary directory for these files when set `true`.\n> +\tDefaults to `false`.\n> +\n>  mergetool.prompt::\n>  \tPrompt before each invocation of the merge resolution program.\n>  \n> diff --git a/git-mergetool.sh b/git-mergetool.sh\n> index 10782b8..2b788c5 100755\n> --- a/git-mergetool.sh\n> +++ b/git-mergetool.sh\n> @@ -37,6 +37,19 @@ base_present () {\n>  \ttest -n \"$base_mode\"\n>  }\n>  \n> +mergetool_tmpdir_init () {\n> +\tif test \"$(git config --bool mergetool.writeToTemp)\" != true\n> +\tthen\n> +\t\tMERGETOOL_TMPDIR=.\n> +\t\treturn 0\n> +\tfi\n> +\tif MERGETOOL_TMPDIR=$(mktemp -d -t \"git-mergetool-XXXXXX\" 2>/dev/null)\n> +\tthen\n> +\t\treturn 0\n> +\tfi\n> +\tdie \"error: mktemp is needed when 'mergetool.writeToTemp' is true\"\n> +}\n> +\n>  cleanup_temp_files () {\n>  \tif test \"$1\" = --save-backup\n>  \tthen\n> @@ -46,6 +59,10 @@ cleanup_temp_files () {\n>  \telse\n>  \t\trm -f -- \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$BACKUP\"\n>  \tfi\n> +\tif test \"$MERGETOOL_TMPDIR\" != \".\"\n> +\tthen\n> +\t\trmdir \"$MERGETOOL_TMPDIR\"\n> +\tfi\n>  }\n>  \n>  describe_file () {\n> @@ -235,10 +252,20 @@ merge_file () {\n>  \t\tBASE=$MERGED\n>  \t\text=\n>  \tfi\n> -\tBACKUP=\"./${BASE}_BACKUP_$$$ext\"\n> -\tLOCAL=\"./${BASE}_LOCAL_$$$ext\"\n> -\tREMOTE=\"./${BASE}_REMOTE_$$$ext\"\n> -\tBASE=\"./${BASE}_BASE_$$$ext\"\n> +\n> +\tmergetool_tmpdir_init\n> +\n> +\tif test \"$MERGETOOL_TMPDIR\" != \".\"\n> +\tthen\n> +\t\t# If we're using a temporary directory then write to the\n> +\t\t# top-level of that directory.\n> +\t\tBASE=${BASE##*/}\n> +\tfi\n> +\n> +\tBACKUP=\"$MERGETOOL_TMPDIR/${BASE}_BACKUP_$$$ext\"\n> +\tLOCAL=\"$MERGETOOL_TMPDIR/${BASE}_LOCAL_$$$ext\"\n> +\tREMOTE=\"$MERGETOOL_TMPDIR/${BASE}_REMOTE_$$$ext\"\n> +\tBASE=\"$MERGETOOL_TMPDIR/${BASE}_BASE_$$$ext\"\n>  \n>  \tbase_mode=$(git ls-files -u -- \"$MERGED\" | awk '{if ($3==1) print $1;}')\n>  \tlocal_mode=$(git ls-files -u -- \"$MERGED\" | awk '{if ($3==2) print $1;}')\n"},{"id":"250569","messageId":"xmqqk3433h8m.fsf@gitster.dls.corp.google.com","threadId":"37716","inReplyTo":"1413047085-12398-1-git-send-email-davvid@gmail.com","subject":"Re: [PATCH] mergetool: add an option for writing to a temporary directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-10-13T19:24:41Z","receivedAt":"2014-10-13T19:24:41Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Aguilar <davvid@gmail.com> writes:\n\n> Teach mergetool to write files in a temporary directory when\n> 'mergetool.writeToTemp' is true.\n>\n> This is helpful for tools such as Eclipse which cannot cope with\n> multiple copies of the same file in the worktree.\n\nWith this can we drop the \"change the temporary file name\" patch by\nRobin Rosenberg?\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/255457/focus=255599\n\nMessage-Id: <1408607240-11369-1-git-send-email-robin.rosenberg@dewire.com>\n"},{"id":"250665","messageId":"20141015063848.GC14751@gmail.com","threadId":"37716","inReplyTo":"xmqqk3433h8m.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] mergetool: add an option for writing to a temporary directory","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2014-10-15T06:38:49Z","receivedAt":"2014-10-15T06:38:49Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On Mon, Oct 13, 2014 at 12:24:41PM -0700, Junio C Hamano wrote:\n> David Aguilar <davvid@gmail.com> writes:\n> \n> > Teach mergetool to write files in a temporary directory when\n> > 'mergetool.writeToTemp' is true.\n> >\n> > This is helpful for tools such as Eclipse which cannot cope with\n> > multiple copies of the same file in the worktree.\n> \n> With this can we drop the \"change the temporary file name\" patch by\n> Robin Rosenberg?\n> \n> http://thread.gmane.org/gmane.comp.version-control.git/255457/focus=255599\n> \n> Message-Id: <1408607240-11369-1-git-send-email-robin.rosenberg@dewire.com>\n\nI would think so but I'm biased ;-)\n-- \nDavid\n"},{"id":"250699","messageId":"293924028.621540.1413401411270.JavaMail.zimbra@dewire.com","threadId":"37716","inReplyTo":"20141015063848.GC14751@gmail.com","subject":"Re: [PATCH] mergetool: add an option for writing to a temporary directory","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2014-10-15T19:30:11Z","receivedAt":"2014-10-15T19:30:11Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"\n\n----- Ursprungligt meddelande -----\n> Från: \"David Aguilar\" <davvid@gmail.com>\n> Till: \"Junio C Hamano\" <gitster@pobox.com>\n> Kopia: \"Robin Rosenberg\" <robin.rosenberg@dewire.com>, git@vger.kernel.org, \"Charles Bailey\" <charles@hashpling.org>\n> Skickat: onsdag, 15 okt 2014 8:38:49\n> Ämne: Re: [PATCH] mergetool: add an option for writing to a temporary directory\n> \n> On Mon, Oct 13, 2014 at 12:24:41PM -0700, Junio C Hamano wrote:\n> > David Aguilar <davvid@gmail.com> writes:\n> > \n> > > Teach mergetool to write files in a temporary directory when\n> > > 'mergetool.writeToTemp' is true.\n> > >\n> > > This is helpful for tools such as Eclipse which cannot cope with\n> > > multiple copies of the same file in the worktree.\n> > \n> > With this can we drop the \"change the temporary file name\" patch by\n> > Robin Rosenberg?\n> > \n> > http://thread.gmane.org/gmane.comp.version-control.git/255457/focus=255599\n> > \n> > Message-Id: <1408607240-11369-1-git-send-email-robin.rosenberg@dewire.com>\n> \n> I would think so but I'm biased ;-)\n\nThe new patch solves my problem.\n\n-- robin\n"},{"id":"250704","messageId":"xmqq1tq9vz7t.fsf@gitster.dls.corp.google.com","threadId":"37716","inReplyTo":"293924028.621540.1413401411270.JavaMail.zimbra@dewire.com","subject":"Re: [PATCH] mergetool: add an option for writing to a temporary directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-10-15T20:45:42Z","receivedAt":"2014-10-15T20:45:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Robin Rosenberg <robin.rosenberg.lists@dewire.com> writes:\n\n> ----- Ursprungligt meddelande -----\n>> Från: \"David Aguilar\" <davvid@gmail.com>\n>> Till: \"Junio C Hamano\" <gitster@pobox.com>\n>> Kopia: \"Robin Rosenberg\" <robin.rosenberg@dewire.com>,\n>> git@vger.kernel.org, \"Charles Bailey\" <charles@hashpling.org>\n>> Skickat: onsdag, 15 okt 2014 8:38:49\n>> Ämne: Re: [PATCH] mergetool: add an option for writing to a temporary directory\n>> \n>> On Mon, Oct 13, 2014 at 12:24:41PM -0700, Junio C Hamano wrote:\n>> > David Aguilar <davvid@gmail.com> writes:\n>> > \n>> > > Teach mergetool to write files in a temporary directory when\n>> > > 'mergetool.writeToTemp' is true.\n>> > >\n>> > > This is helpful for tools such as Eclipse which cannot cope with\n>> > > multiple copies of the same file in the worktree.\n>> > \n>> > With this can we drop the \"change the temporary file name\" patch by\n>> > Robin Rosenberg?\n>> > \n>> > http://thread.gmane.org/gmane.comp.version-control.git/255457/focus=255599\n>> > \n>> > Message-Id: <1408607240-11369-1-git-send-email-robin.rosenberg@dewire.com>\n>> \n>> I would think so but I'm biased ;-)\n>\n> The new patch solves my problem.\n\nThanks.  Let's move David's series forward then.\n"}]}