{"thread":{"id":"19123","subject":"Diftool problems","startedAt":"2009-04-29T16:15:49Z","lastAt":"2009-05-02T09:05:33Z","messageCount":6,"participants":["Marcin Zalewski","Markus Heidelberg","David Aguilar"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"112648","messageId":"7c0fdf4f0904290915i56f58981i70e7093e9bf87d8b@mail.gmail.com","threadId":"19123","inReplyTo":null,"subject":"Diftool problems","fromName":"Marcin Zalewski","fromEmail":"marcin.zalewski@gmail.com","sentAt":"2009-04-29T16:15:49Z","receivedAt":"2009-04-29T16:15:49Z","isPatch":false,"sender":{"key":"marcin.zalewski@gmail.com","avatar":"https://gravatar.com/avatar/df5a1c06f2fd2fc729fd0e540c4802b598695ef40d9fb0ed11bfb4d3e17a2c04?d=mp&s=160"},"body":"Hi,\n\nWhen git-difftool calls a diff tool, it uses file names given to it by\ngit-diff. This is a problem because often one of the files to be\ncompared is the same as the file to be merged into. What I mean is\nthat, in the following fragment of the git-difftool--helper file, $1\nand $2 (I think) may end up being the same:\n\nlaunch_merge_tool () {\n\t# Merged is the filename as it appears in the work tree\n\t# Local is the contents of a/filename\n\t# Remote is the contents of b/filename\n\t# Custom merge tool commands might use $BASE so we provide it\n\tMERGED=\"$1\"\n\tLOCAL=\"$2\"\n\tREMOTE=\"$3\"\n\tBASE=\"$1\"\n\nGit-mergetool creates a temporary file for merging, but git-difftool\ndoes not. Since git-diff tools is not meant for merging anything, it\nmay seem that there is no problem. However, some merge tools (such as\nediff) do not like when the merge target is the same as one of the\nfiles to be compared. I use the following emacs snippet by Theodore\nTso:\n\nhttp://kerneltrap.org/mailarchive/git/2007/7/2/250505\n\nWith that emacs code, ediff refuses to do a diff with the way that\ndifftool is done now. I do not have a patch, but it seems that a\nsimple fix would be to copy the code that creates temporary files from\nmergetool.\n\nCheers,\nMarcin Zalewski\n"},{"id":"112675","messageId":"200904292142.59471.markus.heidelberg@web.de","threadId":"19123","inReplyTo":"7c0fdf4f0904290915i56f58981i70e7093e9bf87d8b@mail.gmail.com","subject":"Re: Diftool problems","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2009-04-29T19:42:59Z","receivedAt":"2009-04-29T19:42:59Z","isPatch":false,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"Marcin Zalewski, 29.04.2009:\n> Hi,\n> \n> When git-difftool calls a diff tool, it uses file names given to it by\n> git-diff. This is a problem because often one of the files to be\n> compared is the same as the file to be merged into. What I mean is\n> that, in the following fragment of the git-difftool--helper file, $1\n> and $2 (I think) may end up being the same:\n> \n> launch_merge_tool () {\n> \t# Merged is the filename as it appears in the work tree\n> \t# Local is the contents of a/filename\n> \t# Remote is the contents of b/filename\n> \t# Custom merge tool commands might use $BASE so we provide it\n> \tMERGED=\"$1\"\n> \tLOCAL=\"$2\"\n> \tREMOTE=\"$3\"\n> \tBASE=\"$1\"\n> \n> Git-mergetool creates a temporary file for merging, but git-difftool\n> does not. Since git-diff tools is not meant for merging anything, it\n> may seem that there is no problem. However, some merge tools (such as\n> ediff) do not like when the merge target is the same as one of the\n> files to be compared. I use the following emacs snippet by Theodore\n> Tso:\n> \n> http://kerneltrap.org/mailarchive/git/2007/7/2/250505\n> \n> With that emacs code, ediff refuses to do a diff with the way that\n> difftool is done now. I do not have a patch, but it seems that a\n> simple fix would be to copy the code that creates temporary files from\n> mergetool.\n\nThe real fix would be to adjust the ediff snippet for difftool support.\n\nAs you said yourself, git-difftool is not meant for merging files, so\nthere is no reason to open more than 2 files at all.\n\nThe built-in difftools 'emerge' and 'ecmerge' still seem to open LOCAL,\nREMOTE and MERGED. This should be fixed, so that they don't open MERGED\nany more, but I don't have emacs installed, so I shouldn't try it\nmyself.\n\nOh, and LOCAL shouldn't be copied to a temporary file in the first\nplace, because people don't use git-difftool in read-only mode only.\n\nMarkus\n"},{"id":"112677","messageId":"7c0fdf4f0904291255i4076df8cubb26fdb2d51826d4@mail.gmail.com","threadId":"19123","inReplyTo":"200904292142.59471.markus.heidelberg@web.de","subject":"Re: Diftool problems","fromName":"Marcin Zalewski","fromEmail":"marcin.zalewski@gmail.com","sentAt":"2009-04-29T19:55:42Z","receivedAt":"2009-04-29T19:55:42Z","isPatch":false,"sender":{"key":"marcin.zalewski@gmail.com","avatar":"https://gravatar.com/avatar/df5a1c06f2fd2fc729fd0e540c4802b598695ef40d9fb0ed11bfb4d3e17a2c04?d=mp&s=160"},"body":"> The real fix would be to adjust the ediff snippet for difftool support.\n\nThe emas snippet was meant to work with mergetool and it does (I\nthink). Changing the emacs code could indeed help with difftool but it\nwould break mergetool.\n\n> As you said yourself, git-difftool is not meant for merging files, so\n> there is no reason to open more than 2 files at all.\n\nI agree, but the current implementation of difftool uses mergetool\nlibrary. That may be the reason why difftool is trying to come up with\nthe third file. Here is the snippet of code from mergetool library\nthat executes emerge in case of non-merge-mode:\n\n\"$merge_tool_path\" -f emerge-files-command \\\n\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$(basename \"$MERGED\")\"\n\n> The built-in difftools 'emerge' and 'ecmerge' still seem to open LOCAL,\n> REMOTE and MERGED. This should be fixed, so that they don't open MERGED\n> any more, but I don't have emacs installed, so I shouldn't try it\n> myself.\n\nAgain, I agree. This could be one of the possible solutions, but it\nwould require that mergetool library is changed or rewriting pieces of\nmergetool in difftool. Correct me if I am wrong.\n\n> Oh, and LOCAL shouldn't be copied to a temporary file in the first\n> place, because people don't use git-difftool in read-only mode only.\n\nI think that merge result could be a temporary file, like in\nmergetool. In a situation where I use git to track an SVN repository,\ndifftool can be actually used to merge my uncommitted changes with a\ncommit from someone else after doing svn rebase. On the other hand, I\nam no git expert so there may be a better way to handle this case.\n\n-m\n"},{"id":"112690","messageId":"200904292248.06107.markus.heidelberg@web.de","threadId":"19123","inReplyTo":"7c0fdf4f0904291255i4076df8cubb26fdb2d51826d4@mail.gmail.com","subject":"Re: Diftool problems","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2009-04-29T20:48:05Z","receivedAt":"2009-04-29T20:48:05Z","isPatch":false,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"Marcin Zalewski, 29.04.2009:\n> > The real fix would be to adjust the ediff snippet for difftool support.\n> \n> The emas snippet was meant to work with mergetool and it does (I\n> think). Changing the emacs code could indeed help with difftool but it\n> would break mergetool.\n\nI'm sure the emacs snippet can be adjusted to work with both. If it is\ncalled with 2 files, then it's for difftool, else for mergetool.\n\n> > As you said yourself, git-difftool is not meant for merging files, so\n> > there is no reason to open more than 2 files at all.\n> \n> I agree, but the current implementation of difftool uses mergetool\n> library.\n\nThe file is called git-mergetool--lib, but more exactly it should be\ncalled git-mergetool-difftool--lib, but who wants this? Difftool was\noriginally based on mergetool, but the recent refactoring introduced the\nlib, which is shared by both, without belonging to one of them more than\nto the other.\n\n> That may be the reason why difftool is trying to come up with\n> the third file.\n\nDifftool isn't forcing a third file on you.\n\n> Here is the snippet of code from mergetool library\n> that executes emerge in case of non-merge-mode:\n> \n> \"$merge_tool_path\" -f emerge-files-command \\\n> \t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$(basename \"$MERGED\")\"\n\nAs said, this command shouldn't open the 3rd MERGED file, this should be\nfixed. This part of the lib is not responsible for difftool.\n\n> > The built-in difftools 'emerge' and 'ecmerge' still seem to open LOCAL,\n> > REMOTE and MERGED. This should be fixed, so that they don't open MERGED\n> > any more, but I don't have emacs installed, so I shouldn't try it\n> > myself.\n> \n> Again, I agree. This could be one of the possible solutions,\n\nNo, that doesn't solve your problem with ediff.\nOr do you set merge.tool=emerge and ediff is called due to the snippet\nin your ~/.emacs? If yes, then I got it now... Sure, I just read the\npost from Ted Tso again, use-ediff-instead.el, aha.\n\nI guess it would be cleaner to do this in ~/.gitconfig:\n\n[diff]\n\ttool = ediff\n[difftool \"ediff\"]\n\tcmd = emacs --options \"$LOCAL\" \"$REMOTE\"\n\nWhich is annoying, of course.\n\nBut now that I got it (see above) I think you should leave\nmerge.tool=emerge, since the snippet somehow seems to rely on it.\n\n> but it\n> would require that mergetool library is changed\n\nWhat's wrong with that?\nIf this solves the 'ediff' problem and also makes 'emerge' to work right\nas difftool, then everyone would benefit from.\n\n> or rewriting pieces of\n> mergetool in difftool. Correct me if I am wrong.\n> \n> > Oh, and LOCAL shouldn't be copied to a temporary file in the first\n> > place, because people don't use git-difftool in read-only mode only.\n> \n> I think that merge result could be a temporary file, like in\n> mergetool. In a situation where I use git to track an SVN repository,\n> difftool can be actually used to merge my uncommitted changes with a\n> commit from someone else after doing svn rebase.\n\nAbove you want your ediff mergetool snippet to work with difftool. And\nhere you want to use difftool as a mergetool. I'm confused :)\n\nBTW, difftool doesn't work with files in unmerged state.\n\nMarkus\n"},{"id":"112698","messageId":"7c0fdf4f0904291437w58b2a325t5e56888aadd3780f@mail.gmail.com","threadId":"19123","inReplyTo":"200904292248.06107.markus.heidelberg@web.de","subject":"Re: Diftool problems","fromName":"Marcin Zalewski","fromEmail":"marcin.zalewski@gmail.com","sentAt":"2009-04-29T21:37:37Z","receivedAt":"2009-04-29T21:37:37Z","isPatch":false,"sender":{"key":"marcin.zalewski@gmail.com","avatar":"https://gravatar.com/avatar/df5a1c06f2fd2fc729fd0e540c4802b598695ef40d9fb0ed11bfb4d3e17a2c04?d=mp&s=160"},"body":"Markus,\n\nI think I mostly agree with everything that you have written. I hope\nthat someone will fix something now. :)\n\nCheers,\n-m\n"},{"id":"112869","messageId":"20090502090531.GC34467@gmail.com","threadId":"19123","inReplyTo":"7c0fdf4f0904291255i4076df8cubb26fdb2d51826d4@mail.gmail.com","subject":"Re: Diftool problems","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2009-05-02T09:05:33Z","receivedAt":"2009-05-02T09:05:33Z","isPatch":false,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"On  0, Marcin Zalewski <marcin.zalewski@gmail.com> wrote:\n> > The real fix would be to adjust the ediff snippet for difftool support.\n> \n> \"$merge_tool_path\" -f emerge-files-command \\\n> \t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$(basename \"$MERGED\")\"\n\nHi\n\nWould the right command be:\n\t\"$merge_tool_path\" -f emerge-files-command \\\n\t\t\"$LOCAL\" \"$REMOTE\"\n\n(without $MERGED) ?\n\n\n> I think that merge result could be a temporary file, like in\n> mergetool. In a situation where I use git to track an SVN repository,\n> difftool can be actually used to merge my uncommitted changes with a\n> commit from someone else after doing svn rebase. On the other hand, I\n> am no git expert so there may be a better way to handle this case.\n> \n> -m\n\nAre you able to save the result to a file with the above\nsnippet?  I'd prefer to not touch the way difftool deals\nwith files this late in the RC cycle, and if just\nsaving within emacs works without changing difftool\nto use temporary files then that's even better.\n\nI tried it and didn't notice any difference w/ or w/out\nthe patch, but if not specifying $MERGED is more\ncorrect then we should do that.\n\nYou should have just seen a patch from me.\nLet me know if you have any other suggestions.\n\n-- \n\t\tDavid\n"}]}