threads / discuss / 19123

Diftool problems

Subject: Diftool problems

## tl;dr

6 messages between Apr 29, 2009 and May 2, 2009.

replies: 5people: 3as markdown or json

Marcin Zalewski· Apr 29, 2009, 16:15 UTC · lore
Hi,

When git-difftool calls a diff tool, it uses file names given to it by git-diff. This is a problem because often one of the files to be compared is the same as the file to be merged into. What I mean is that, in the following fragment of the git-difftool--helper file, $1 and $2 (I think) may end up being the same:

launch_merge_tool () {
	# Merged is the filename as it appears in the work tree
	# Local is the contents of a/filename
	# Remote is the contents of b/filename
	# Custom merge tool commands might use $BASE so we provide it
	MERGED="$1"
	LOCAL="$2"
	REMOTE="$3"
	BASE="$1"

Git-mergetool creates a temporary file for merging, but git-difftool does not. Since git-diff tools is not meant for merging anything, it may seem that there is no problem. However, some merge tools (such as ediff) do not like when the merge target is the same as one of the files to be compared. I use the following emacs snippet by Theodore Tso:

http://kerneltrap.org/mailarchive/git/2007/7/2/250505

With that emacs code, ediff refuses to do a diff with the way that difftool is done now. I do not have a patch, but it seems that a simple fix would be to copy the code that creates temporary files from mergetool.

Cheers, Marcin Zalewski

Markus Heidelberg· Apr 29, 2009, 19:42 UTC · re: Marcin Zalewski · lore

Re: Diftool problems

Marcin Zalewski, 29.04.2009:
Show 31 quoted lines
> Hi,
> 
> When git-difftool calls a diff tool, it uses file names given to it by
> git-diff. This is a problem because often one of the files to be
> compared is the same as the file to be merged into. What I mean is
> that, in the following fragment of the git-difftool--helper file, $1
> and $2 (I think) may end up being the same:
> 
> launch_merge_tool () {
> 	# Merged is the filename as it appears in the work tree
> 	# Local is the contents of a/filename
> 	# Remote is the contents of b/filename
> 	# Custom merge tool commands might use $BASE so we provide it
> 	MERGED="$1"
> 	LOCAL="$2"
> 	REMOTE="$3"
> 	BASE="$1"
> 
> Git-mergetool creates a temporary file for merging, but git-difftool
> does not. Since git-diff tools is not meant for merging anything, it
> may seem that there is no problem. However, some merge tools (such as
> ediff) do not like when the merge target is the same as one of the
> files to be compared. I use the following emacs snippet by Theodore
> Tso:
> 
> http://kerneltrap.org/mailarchive/git/2007/7/2/250505
> 
> With that emacs code, ediff refuses to do a diff with the way that
> difftool is done now. I do not have a patch, but it seems that a
> simple fix would be to copy the code that creates temporary files from
> mergetool.
The real fix would be to adjust the ediff snippet for difftool support.

As you said yourself, git-difftool is not meant for merging files, so there is no reason to open more than 2 files at all.

The built-in difftools 'emerge' and 'ecmerge' still seem to open LOCAL, REMOTE and MERGED. This should be fixed, so that they don't open MERGED any more, but I don't have emacs installed, so I shouldn't try it myself.

Oh, and LOCAL shouldn't be copied to a temporary file in the first place, because people don't use git-difftool in read-only mode only.

Markus
Marcin Zalewski· Apr 29, 2009, 19:55 UTC · re: Markus Heidelberg · lore

Re: Diftool problems

> The real fix would be to adjust the ediff snippet for difftool support.

The emas snippet was meant to work with mergetool and it does (I think). Changing the emacs code could indeed help with difftool but it would break mergetool.

> As you said yourself, git-difftool is not meant for merging files, so
> there is no reason to open more than 2 files at all.

I agree, but the current implementation of difftool uses mergetool library. That may be the reason why difftool is trying to come up with the third file. Here is the snippet of code from mergetool library that executes emerge in case of non-merge-mode:

"$merge_tool_path" -f emerge-files-command \
				"$LOCAL" "$REMOTE" "$(basename "$MERGED")"
> The built-in difftools 'emerge' and 'ecmerge' still seem to open LOCAL,
> REMOTE and MERGED. This should be fixed, so that they don't open MERGED
> any more, but I don't have emacs installed, so I shouldn't try it
> myself.

Again, I agree. This could be one of the possible solutions, but it would require that mergetool library is changed or rewriting pieces of mergetool in difftool. Correct me if I am wrong.

> Oh, and LOCAL shouldn't be copied to a temporary file in the first
> place, because people don't use git-difftool in read-only mode only.

I think that merge result could be a temporary file, like in mergetool. In a situation where I use git to track an SVN repository, difftool can be actually used to merge my uncommitted changes with a commit from someone else after doing svn rebase. On the other hand, I am no git expert so there may be a better way to handle this case.

-m
Markus Heidelberg· Apr 29, 2009, 20:48 UTC · re: Marcin Zalewski · lore

Re: Diftool problems

Marcin Zalewski, 29.04.2009:
Show 5 quoted lines
> > The real fix would be to adjust the ediff snippet for difftool support.
> 
> The emas snippet was meant to work with mergetool and it does (I
> think). Changing the emacs code could indeed help with difftool but it
> would break mergetool.

I'm sure the emacs snippet can be adjusted to work with both. If it is called with 2 files, then it's for difftool, else for mergetool.

Show 5 quoted lines
> > As you said yourself, git-difftool is not meant for merging files, so
> > there is no reason to open more than 2 files at all.
> 
> I agree, but the current implementation of difftool uses mergetool
> library.

The file is called git-mergetool--lib, but more exactly it should be called git-mergetool-difftool--lib, but who wants this? Difftool was originally based on mergetool, but the recent refactoring introduced the lib, which is shared by both, without belonging to one of them more than to the other.

> That may be the reason why difftool is trying to come up with
> the third file.
Difftool isn't forcing a third file on you.
Show 5 quoted lines
> Here is the snippet of code from mergetool library
> that executes emerge in case of non-merge-mode:
> 
> "$merge_tool_path" -f emerge-files-command \
> 				"$LOCAL" "$REMOTE" "$(basename "$MERGED")"

As said, this command shouldn't open the 3rd MERGED file, this should be fixed. This part of the lib is not responsible for difftool.

Show 6 quoted lines
> > The built-in difftools 'emerge' and 'ecmerge' still seem to open LOCAL,
> > REMOTE and MERGED. This should be fixed, so that they don't open MERGED
> > any more, but I don't have emacs installed, so I shouldn't try it
> > myself.
> 
> Again, I agree. This could be one of the possible solutions,

No, that doesn't solve your problem with ediff. Or do you set merge.tool=emerge and ediff is called due to the snippet in your ~/.emacs? If yes, then I got it now... Sure, I just read the post from Ted Tso again, use-ediff-instead.el, aha.

I guess it would be cleaner to do this in ~/.gitconfig:
[diff]
	tool = ediff
[difftool "ediff"]
	cmd = emacs --options "$LOCAL" "$REMOTE"
Which is annoying, of course.

But now that I got it (see above) I think you should leave merge.tool=emerge, since the snippet somehow seems to rely on it.

> but it
> would require that mergetool library is changed

What's wrong with that? If this solves the 'ediff' problem and also makes 'emerge' to work right as difftool, then everyone would benefit from.

Show 10 quoted lines
> or rewriting pieces of
> mergetool in difftool. Correct me if I am wrong.
> 
> > Oh, and LOCAL shouldn't be copied to a temporary file in the first
> > place, because people don't use git-difftool in read-only mode only.
> 
> I think that merge result could be a temporary file, like in
> mergetool. In a situation where I use git to track an SVN repository,
> difftool can be actually used to merge my uncommitted changes with a
> commit from someone else after doing svn rebase.

Above you want your ediff mergetool snippet to work with difftool. And here you want to use difftool as a mergetool. I'm confused :)

BTW, difftool doesn't work with files in unmerged state.
Markus
David Aguilar· May 2, 2009, 09:05 UTC · re: Marcin Zalewski · lore

Re: Diftool problems

On  0, Marcin Zalewski <marcin.zalewski@gmail.com> wrote:
> > The real fix would be to adjust the ediff snippet for difftool support.
> 
> "$merge_tool_path" -f emerge-files-command \
> 				"$LOCAL" "$REMOTE" "$(basename "$MERGED")"
Hi
Would the right command be:
	"$merge_tool_path" -f emerge-files-command \
		"$LOCAL" "$REMOTE"
(without $MERGED) ?
Show 7 quoted lines
> I think that merge result could be a temporary file, like in
> mergetool. In a situation where I use git to track an SVN repository,
> difftool can be actually used to merge my uncommitted changes with a
> commit from someone else after doing svn rebase. On the other hand, I
> am no git expert so there may be a better way to handle this case.
> 
> -m

Are you able to save the result to a file with the above snippet? I'd prefer to not touch the way difftool deals with files this late in the RC cycle, and if just saving within emacs works without changing difftool to use temporary files then that's even better.

I tried it and didn't notice any difference w/ or w/out the patch, but if not specifying $MERGED is more correct then we should do that.

You should have just seen a patch from me. Let me know if you have any other suggestions.

-- 
		David

← back to recent threads