2 # ====================================================================
3 # Copyright (c) 2007 CollabNet. All rights reserved.
5 # This software is licensed as described in the file COPYING, which
6 # you should have received as part of this distribution. The terms
7 # are also available at http://subversion.tigris.org/license-1.html.
8 # If newer versions of this license are posted there, you may use a
9 # newer version instead, at your option.
11 # This software consists of voluntary contributions made by many
12 # individuals. For exact contribution history, see the revision
13 # history and logs, available at http://subversion.tigris.org/.
14 # ====================================================================
15 HGMERGE_BINARY
='hgmerge'
17 '''This script allows using Mercurial's hgmerge script with Subversion.
25 def do_hgmerge(base
, repo
, local
, merged
):
26 '''Runs an interactive three-way merge using Mercurial's hgmerge script.
28 This function is designed to convert Subversion's four-file interactive merges
29 into Mercurial's three-file interactive merges so that hgmerge can be used for
30 interactive merging in subversion.
32 # We have to use a temporary directory because FileMerge on OS X fails to save
33 # the file if it has to write to a file in the CWD. As of now, there's no
34 # obvious reason for why that is, but this fixes it.
35 temp_dir
= tempfile
.mkdtemp(prefix
='svn_hgmerge')
36 local_name
= local
.split('/')[-1]
37 temp_file
= temp_dir
+'/'+local_name
38 shutil
.copyfile(local
, temp_file
)
39 args
= [HGMERGE_BINARY
, temp_file
, base
, repo
]
40 status
= os
.spawnvp(os
.P_WAIT
, HGMERGE_BINARY
, args
)
44 shutil
.copyfile(temp_file
, merged
)
49 if __name__
== '__main__':
50 status
= do_hgmerge(sys
.argv
[1], sys
.argv
[2], sys
.argv
[3], sys
.argv
[4])