Mercurial > dotfiles
comparison unixSoft/bin/svn-hgmerge.py @ 0:c30d68fbd368
Initial import from svn.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Wed, 26 Nov 2008 10:56:09 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c30d68fbd368 |
---|---|
1 #!/usr/bin/env python | |
2 # ==================================================================== | |
3 # Copyright (c) 2007 CollabNet. All rights reserved. | |
4 # | |
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. | |
10 # | |
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' | |
16 | |
17 '''This script allows using Mercurial's hgmerge script with Subversion. | |
18 ''' | |
19 | |
20 import os | |
21 import sys | |
22 import shutil | |
23 import tempfile | |
24 | |
25 def do_hgmerge(base, repo, local, merged): | |
26 '''Runs an interactive three-way merge using Mercurial's hgmerge script. | |
27 | |
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. | |
31 ''' | |
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) | |
41 print status | |
42 if status == 0: | |
43 os.unlink(merged) | |
44 shutil.copyfile(temp_file, merged) | |
45 os.unlink(temp_file) | |
46 os.rmdir(temp_dir) | |
47 return status | |
48 | |
49 if __name__ == '__main__': | |
50 status = do_hgmerge(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) | |
51 sys.exit(status) | |
52 |