DEV Community

Max Pixel
Max Pixel

Posted on

How to use Plastic SCM's merge tool with P4V

Why I Prefer Plastic Merge

Back in 2013, when I was studying game development at USC, a classmate showed me how to install P4Merge, the free diff & merge program meant to supplement Perforce. I used it to resolve merge conflicts in a Unity project that was tracked through Git.

In the years since, I've looked into other merge tools at various times for various reasons, not least because I'm always eager to find better alternatives to whatever software I'm using. For a long time, P4Merge remained my top choice. Unlike most other merge tools which had only three panels (showing source, target, and result), P4V showed base in addition, providing greater clarity.

Then, I had the delight of using Plastic SCM for ElemenTerra, and dozens of other projects thereafter. Plastic comes with its own merge tool, and I decided to give that tool a chance, instead of replacing it with my favorite P4V right away. The first time I needed to merge a file in this new system, I was delighted to see that Plastic Merge, too, sported four panels.

There were a few downsides compared to P4Merge. Resolving conflicts require de-selecting two of three buttons at the top of the screen, while P4Merge requires selecting a single button in close proximity to the relevant output lines. In the rare case that I needed to merge a file that is several thousand lines long (e.g. UE4's 15MB+ Commit.gitdeps.xml), Plastic would simply refuse to open, while P4Merge managed well enough.

But Plastic's merge tool more than made up for these downsides by recognizing changes more intelligently than P4Merge. Where P4Merge chose to group big swaths of changes despite the presence of common lines, Plastic was able to recognize the smaller groups of differences. I've run a few merges through both tools for comparison, and found that Plastic was able to auto-resolve differences (correctly) that P4Merge saw as conflicts. Above all else, though, when it came to C# files, Plastic was capable of recognizing, highlighting, and merging moved code.

In recent years, I've worked for a few clients that use Perforce (now called Helix [good luck with that, Perforce]). Again, instead of customizing P4V right away, I gave its default diff configuration a chance. Recently, however, I felt compelled to switch back to Plastic Merge, after running into an intermittent P4Merge glitch one too many times. After resolving some conflicts, I was surprised to see my code fail to compile, and found it to be grossly mangled in ways that couldn't have resulted from user error alone (e.g. half of line 12 somehow ended up repeated in line 204). P4Merge was writing different content to the file than it was previewing in its GUI. Not good.

Refusing to Speak the Same Language

Unfortunately, configuring P4V to use Plastic Merge isn't intuitive. Thankfully, it's easy once you have some instructions.

P4V's configuration allows you to specify command-line arguments for the merge tool, in which you can put %1, %2, %b, and %r, which are substituted with the actual source, target, base, and result file-paths. The problem is, it only recognizes those “variables” when they’re surrounded by white-space. Meanwhile, Plastic's merge tool accepts arguments --source=<PathToSource>, --dest=<PathToDest>, etc., and does not recognize --source <PathToSource> etc. So, Plastic requires an = to be adjacent to the filename, while P4V only supplies filenames next to whitespace. If you configure it with --source=%1, then it will place exactly that into the command-line arguments, and Plastic Merge will complain that it can't find a file called %1. If you configure it with --source %1, Plastic will complain that that the arguments are invalid.

As with almost any format incompatibility problem, however, the two programs can be forced to work in tandem by using an intermediary adapter.

How To Do It

  1. Install Plastic SCM, of course. A license is not required for the merge tool to work.
  2. Place the following text into %UserProfile%/Scripts/plasticmerge.cmd

    mergetool --source=%1 --destination=%2 --base=%3 --result=%4
  3. Configure P4V to use that file as the merge tool:

    In P4V settings, "Merge" section, choose Other Application, specify your plasticmerge.cmd path, and set Arguments to "%1 %2 %b %r"

But Wait, There's More!

Plastic's merge tool is great, but the company that makes it, Códice, has an even better version, called SemanticMerge, that's even smarter (unless you're using C++, in which case it usually fails to parse the syntax correctly). Unlike Plastic Merge, SemanticMerge is not available for free. The subscription plan, at the time of writing, is shockingly expensive at almost $7/month, but the one-time-payment forever license is very reasonable. Unlike Plastic Merge, SemanticMerge can be integrated with P4V without CMD file hacks, but only for the filetypes that it supports (you'll still want to use the "vanilla" merge tool for other files, which will still require the hack). Official SemanticMerge usage instructions are found here.

Top comments (0)