开发者

How to let mercurial external diff tool deal with file rename?

If I commit a file rename and use extdiff to see the diff in Beyond Compare or kdiff3, they show two differ开发者_开发问答ent files on each side.

With Beyond Compare I can manually pick arbitrary files from each side to compare, but it's a huge pain if I have many renames (i.e. changing a java package name for refactoring).

I understand why it's so: extdiff simply makes two temp snapshot directories for the diff tool.

So my question is: is there any way to convey the rename to the diff tool, such that it will compare the old file name with the new file name?

This is probably specific for each diff tool. So if you know a tool that supports it, please, please let me know.


Note This only works for diffs with TortoiseHg.

The way I've configured my Mercurial installation, with Beyond Compare 3, is as follows:

(note, these are only the options relevant to diff and merging, you still need other options in some of the same sections, so only add or change, don't clear out your old sections and replace with the ones below)

[ui]
merge = bc3m

[extensions]
extdiff=

[extdiff]
cmd.bc3d = C:\Program Files (x86)\Beyond Compare 3\bcomp.exe
opts.bc3d = /lro

[merge-tools]
bc3m.executable = C:\Program Files (x86)\Beyond Compare 3\bcomp.exe
bc3m.args = $local $other $base $output /automerge /reviewconflicts /closescript /lro /rro /title1="Left parent" /title2="Right parent" /title3="Common base" /title4="Merged output"
bc3m.priority = 1
bc3m.premerge = True
bc3m.gui = True

[tortoisehg]
vdiff=bc3d

This now:

  • Auto-merges if possible, not showing a merge-GUI unless there's a merge conflict
  • Diff for a renamed file shows the old filename on the left side and the new one on the right side (funky temporary directory names though)

Important note: Do not use the same name for the merge tool and the diff tool (like bc3 for both). It confuses the tools involved and diffs just punt to the startup screen of BC. That's why the merge tool is named bc3m and the diff tool is named bc3d.

Also note that I've dropped using the built-in beyondcompare tools, as they seem incorrectly configured. In particular, the auto-merge part did not happen when using the built-in tool, but now works nicely. Also, with the built-in tool, visualizing diffs with renames showed the directory comparison or just punted to the startup screen of BC which makes you pick the type of comparison you want.

So in the end I just experimented until I found the right options and set everything up myself.


Handling renames requires a digging into history which a typical scm has. Specially dvcs like Mercurial. That is how, they can handle renames.

Some thing of interest could be the fact that Git doesn't track renames, operates on content and renames don't matter.

Diff tool can handle examining changes but it can tell nothing about the files within it. It will also be erroneous with a preceding history to tell if the file has been renamed or not. Any external diff tool usually examines contents and hence the task of supplying the files will remain with the user.

How ever, Mercurial does track renames. See this extentsion that can be used to track renamed files. You can use that to supply any external diff tool the right filenames to compare.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜