Eddy Petrișor: Integrating Beyond Compare with Semanticmerge
Note: This post will probably not be on the liking of those who think free software is always preferable to closed source software, so if you are such a person, please take this article as an invitation to implement better open source alternatives that can realistically compete with the closed source applications I am mentioning here. I am not going to mention here where the open source alternatives are not up to the same level as the commercial tools, I'll leave that for the readers or for another article.Semanticmerge is a merge tool that attempts to do the right thing when it comes to merging source code. It is language aware and it currently supports Java and C#. Just today the creators of the software have started working on the support for C.
Recently they added Debian packages, so I installed it on my system. For open source development Codice Software, the creators of Semanticmerge, offers free licenses, so I decided to ask for one today, and, although is Sunday, I received an answer and I will get my license on Monday.
When a method is moved from one place to another and changed in a conflicting way in two parallel development lines, Semanticmerge can isolate the offending method and can pass all its incarnations (base, source and destination or, if you prefer, base, mine and theirs) to a text based merge tool to allow the developer to decide how to resolve the merge. On Linux, the Semanticmerge samples are using kdiff3 as the text-based merge tool, which is nice, but I don't use kdiff3, I use Meld, another open source visual tool for merges and comparisons.
OTOH, Beyond Compare is a merge and compare tool made by Scooter Software which provides a very good text based 3-way merge with a 3 sources + 1 result pane, and can compare both files and directories. Two of its killer features is having the ability split differences into important and non-important ones according to the syntax of the compared/merged files, and the ability to easily change or add to the syntax rules in a very user-friendly way. This allows to easily ignore changes in comments, but also basic refactoring such as variable renaming, or other trivial code-wide changes, which allows the developer to focus on the important changes/differences during merges or code reviews.
Syntax support for usual file formats like C, Java, shell, Perl etc. is built in (but can be modified, which is a good thing) and new file types with their syntaxes can be added via the GUI from scratch or based on existing rules.
I evaluated Beyond Compare at my workplace and we decided it would be a good investment to purchases licenses for it for the people in our department.
Having these two software separate is good, but having them integrated with each other would be even better. So I decided I would try to see how it can be done. I installed Beyond compare on my system, too and looked through the examples
The first thing I discovered is that the main assumption of Semanticmerge developers was that the application would be called via the SCM when merges are to be done, so passing lots of parameters would not be problem. I realised that when I saw how one of the samples' starting script invoked semantic merge:
semanticmergetool -s=$sm_dir/src.java -b=$sm_dir/base.java -d=$sm_dir/dst.java -r=/tmp/semanticmergetoolresult.java -edt="kdiff3 \"#sourcefile\" \"#destinationfile\"" -emt="kdiff3 \"#basefile\" \"#sourcefile\" \"#destinationfile\" --L1 \"#basesymbolic\" --L2 \"#sourcesymbolic\" --L3 \"#destinationsymbolic\" -o \"#output\"" -e2mt="kdiff3 \"#sourcefile\" \"#destinationfile\" -o \"#output\""Can you see the problem? It seems Semanticmerge has no persistent knowledge of the user preferences with regards to the text-based merge tool and exports the issue to the SCM, at the price of overcomplicating the command line. I already mentioned this issue in my license request mail and added the issue and my fix suggestion in their voting system of features to be implemented.
The upside was that by comparing the command line for kdiff3 invocations, the kdiff3 documentation and, by comparison, the Beyond Compare SCM integration information, I could deduce what is the command line necessary for Semanticmerge to use Beyond Compare as an external merge and diff tool.
The -edt, -emt and -e2mt options are the ones which specify how the external diff tool, external 3-way merge tool and external 2-way merge tool is to be called. Once I understood that, I split the problem in its obvious parts, each invocation had to be mapped, from kdiff3 options to beyond compare options, adding the occasional bell and whistle, if possible.
The parts to figure out, ordered by compexity, were:
- -edt="kdiff3 \"#sourcefile\" \"#destinationfile\"
- -e2mt="kdiff3 \"#sourcefile\" \"#destinationfile\" -o \"#output\""
- -emt="kdiff3 \"#basefile\" \"#sourcefile\" \"#destinationfile\" --L1 \"#basesymbolic\" --L2 \"#sourcesymbolic\" --L3 \"#destinationsymbolic\" -o \"#output\""
Semantic merge integrates with kdiff3 in diff mode via the -edt option. This was easy to map to Beyond Compare, I just replaced kdiff3 with bcompare:
-edt="bcompare \"#sourcefile\" \"#destinationfile\""Integration for 2-way merges was also quite easy, the mapping to Beyond Compare was:
-e2mt="bcompare \"#sourcefile\" \"#destinationfile\" -savetarget=\"#output\""For the 3-way merge I was a little confused because the Beyond Compare documentation and options were inconsistent between Windows and Linux. On Windows, for some of the SCMs, the options that set the titles for the panes are '/title1', '/title2', '/title3' and '/title4' (way too descriptive for my taste /sarcasm), but for some others are '/lefttitle', '/centertitle', '/righttitle', '/outputtitle', while on Linux the options are the more explicit kind, but with a '-' instead of a '/'.
The basic things were easy, ordering the parameters in the 'source, destination, base, output' instead of kdiff3's 'base, source, destination, -o ouptut', so I wanted to add the bells and whistles, since it really makes more sense for the developer to see something like 'Destination: [method] readOptions' instead of '/tmp/tmp4327687242.tmp', and because that's exactly what is necessary for Semanticmerge when merging methods, since on conflicts the various versions of the functions are placed in temporary files which don't mean anything.
So, after some digging into the examples from Beyond Compare and kdiff3 documentation, I ended up with:
-emt="bcompare \"#sourcefile\" \"#destinationfile\" \"#basefile\" \"#output\" -lefttitle='#sourcesymbolic' -righttitle='#destinationsymbolic' -centertitle='#basesymbolic' -outputtitle='merge result'"
Sadly, I wasn't able to identify the symbolic name for the output, so I added the hard coded 'merge result'. If Codice people would like to help with with this information (or if it exists), I would be more than willing to do update the information and do the necessary changes.
Then I added the bells and whistles for the -edt and -e2mt options, so I ended up with an even more complicated command line. The end result was this monstrosity:
semanticmergetool -s=$sm_dir/src.java -b=$sm_dir/base.java -d=$sm_dir/dst.java -r=/tmp/semanticmergetoolresult.java -edt="bcompare \"#sourcefile\" \"#destinationfile\" -lefttitle='#sourcesymbolic' -righttitle='#destinationsymbolic'" -emt="bcompare \"#sourcefile\" \"#destinationfile\" \"#basefile\" \"#output\" -lefttitle='#sourcesymbolic' -righttitle='#destinationsymbolic' -centertitle='#basesymbolic' -outputtitle='merge result'" -e2mt="bcompare \"#sourcefile\" \"#destinationfile\" -savetarget=\"#output\" -lefttitle='#sourcesymbolic' -righttitle='#destinationsymbolic'"So when I 3-way merge a function I get something like this (sorry for high resolution, lower resolutions don't do justice to the tools):
I don't expect this post to remain relevant for too much time, because after sending my feedback to Codice, they were open to my suggestion to have persistent settings for the external tool integration, so, in the future, the command line could probably be as simple as:
semanticmergetool -s=$sm_dir/src.java -b=$sm_dir/base.java -d=$sm_dir/dst.java -r=/tmp/semanticmergetoolresult.javaAnd the integration could be done via the GUI, while the command line can become a way to override the defaults.

This is my monthly summary of my free software related activities. If you re among the people who
The GUI is written using the PyQT Toolkit and the options in the GUI are generated at runtime, based on the list of available power saving modules.
Apart from the GUI configuration tool, this release also includes some bug fixes:
One of the
I *did* some hacking at DebConf, as usual. For once, I had no TODO
list: after all, I never complete these, so why make one?
Still, I participated to discussions around samba packaging, mostly
animated by Ivo De Decker and I think we're making good progress
towards samba 4.x packages. The road is long, quite complicated, but
we now have a stronger team, with a very active Ivo, Jeroen Dekkers
who officially joined, Steve Langasek who still cherishes one of his
pet packages (and even branched in our git with the Ubuntu packages).
Great work and thanks to Ivo for pushing this forward.
I also worked quite actively on the migration of fonts packages to git
(I now reached the point where I'm more comfortable with git than SVN,
yes, everything can happen). These packages were modernized at the
same time and checked for new upstream versions (I have to say that
few of these fonts had new upstream versions, indeed). We
unfortunately found no time to have a good font BoF in Vaumarcus,
indeed...but I'm not sure we would have many things to say. The work
is done and done well, in this team.
Some progress was made, also, for restoring a working "monolithic"
build of D-I. This build gathers together all udebs from unstable,
which means it offers a D-I image that uses ALL udebs from
nustable.....which is not the default of other images. This would be
very helpful for translators who want to check their work as soon as
possible. In the future, with a Jenkins task that would build each
package at each commit and then build a monolithic image, we could
have a way to provide a tes snapshot of D-I git repos.....which could
help catching more bugs (or more of my stupid mistakes).
So, in general, I consider this a quite successful DebConf when it
comes at "real" production.
For me, DebConf13 in Switzerland was a perfect DebConf, and generally an
great developer meeting and conference. I've attended several past DebConfs
in Canada, Norway, Brazil, Finland, Mexico, Scotland, Spain, NYC, Bosnia,
and Nicaragua. I have special memories of each. DebConf13 was ideal in every
way.










Github is a nice site, and I routinely monitor a couple of projects there.
I've also been using it to host
So, last year I've switched to an OpenPGP smartcard setup for my
whole personal/Debian PGP usage. When doing so, I've also switched
to subkeys, since it's pretty natural when using a smartcard. I
initially set up an expiration of one year for the subkeys, and
everything seems to be running just fine for now.
The expiration date was set to october 27th, and I though it'd
be a good idea to renew them quite in advance, considering there's
my signing key in there, which is (for example) used to sign
packages. If the Debian archive considers my signature subkey
expired, that means I can't upload packages anymore, which is a bit
of a problem (although I think I could still upload packages signed
by the main key). dak (Debian Archive Kit, the software managing
the Debian archive) uses keys from the keyring provided by Debian
admins, which is usually updated every month or so from the
When starting a new


