How to set up svn conflict resolution with meld?

2019-01-22 12:43发布

问题:

I've specified merge-tool-cmd = meld in my Subversion config. When I go to resolve a merge conflict using option l from the presented conflict resolution options, I receive the message:

meld: error: too many arguments (wanted 0-4, got 5)
The external merge tool exited with exit code 2

Can anyone diagnose the problem/provide a solution? Thanks.

回答1:

First a warning! It is very easy to end up losing your local edits if you get this wrong! Test test test!

I'm afraid the script from pmod's link does not work with svn 1.6 (current in Ubuntu 11.04). Putting together code from pmod's link and here and advice here, I made this script that seems to work ok:

#!/usr/bin/env python
# svn merge-tool python wrapper for meld
import sys
import subprocess

try:
   # path to meld
   meld = "/usr/bin/meld"

   # file paths
   base   = sys.argv[1]
   theirs = sys.argv[2]
   mine   = sys.argv[3]
   merged = sys.argv[4]

   # the call to meld
   # For older meld versions:
   # cmd = [meld, mine, base, theirs, merged]
   # New meld versions: >= 1.8.4
   cmd = [meld, mine, base, theirs, '-o', merged]

   # Call meld, making sure it exits correctly
   subprocess.check_call(cmd)
except:
   print "Oh noes, an error!"
   sys.exit(-1)

Save this somewhere sensible (eg /usr/local/bin/svn-merge-meld.py) and make it executable:

sudo chmod +x /usr/local/bin/svn-merge-meld.py

Then edit ~/.subversion/config and uncomment the line merge-tool-cmd =, and set the path to your command.

Note that when a conflict occurs, you will be prompted what to do with it. You need to type a single 'l' and for svn to run this script. When you've finished your merge, you need to type an 'r' to resolve the conflict and copy the merged version to the working copy.



回答2:

The drevicko's answer is correct for recent meld versions. But older meld versions are also used:

  • old   Meld-1.6.1 in Ubuntu 13.04 (Raring) and Debian Wheezy (7.0)
  • new Meld-1.8.2 in Ubuntu 13.10 (Saucy)  and Debian Jessie

The below bash script svn-merge-meld.sh supports both old and recent meld versions (three of four arguments).

#!/bin/bash

base=${1?1st argument is 'base' file}
theirs=${2?2nd argument is 'theirs' file}
mine=${3?3rd argument is 'mine' file}
merged=${4?4th argument is 'merged' file}
version=$(meld --version | perl -pe '($_)=/([0-9]+([.][0-9]+)+)/' )    

if [[ "$version" < 1.7 ]]
then
  #old meld version 1.6.* = three input files
  cat "$mine" > "$merged"
  meld --label="Base=${base##*/}"           "$base"   \
       --label="Mine->Merged=${merged##*/}" "$merged" \
       --label="Theirs=${theirs##*/}"       "$theirs"
else
  # recent meld versions 1.7.* and above = four input files
  meld --label="Base=${base##*/}"           "$base"   \
       --label="Mine=${mine##*/}"           "$mine"   \
       --label="Merged=${merged##*/}"       "$merged" \
       --label="Theirs=${theirs##*/}"       "$theirs"
fi

Do not forget to chmod +x svn-merge-meld.sh.

You can also download svn-merge-meld.sh or fork it:

git clone github.com/olibre/svn-useful-scripts.git

Finally, update your svn configuration:

vi ~/.subversion/config

and enable merge-tool-cmd:

[helpers]
merge-tool-cmd = /home/....../svn-useful-scripts/svn-merge-meld.sh


回答3:

You need to use wrapper script to grab and put things subversion is out to the order needed for your diff tool (check this):

The key to using external two- and three-way differencing tools (other than GNU diff and diff3, of course) with Subversion is to use wrapper scripts, which convert the input from Subversion into something that your differencing tool can understand, and then to convert the output of your tool back into a format that Subversion expects—the format that the GNU tools would have used. ...

Subversion calls external diff programs with parameters suitable for the GNU diff utility, and expects only that the external program will return with a successful error code. For most alternative diff programs, only the sixth and seventh arguments—the paths of the files that represent the left and right sides of the diff, respectively—are of interest.

This is very well described here



标签: svn meld