##// END OF EJS Templates
scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option...
Thomas De Schampheleire -
r8185:46e78e58 default
parent child Browse files
Show More
@@ -14,6 +14,8 b''
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17 import os
18 import shutil
17 import sys
19 import sys
18
20
19 import click
21 import click
@@ -51,6 +53,61 b' def normalize_po_files(po_files):'
51 i18n_utils._normalize_po_file(po_file, strip=True)
53 i18n_utils._normalize_po_file(po_file, strip=True)
52
54
53 @cli.command()
55 @cli.command()
56 @click.argument('local')
57 @click.argument('base')
58 @click.argument('other')
59 @click.argument('output')
60 def normalized_merge(local, base, other, output):
61 """Merge tool for use with 'hg merge/rebase/graft --tool'
62
63 Merging i18n files with a standard merge tool could yield merge conflicts
64 when one side is normalized and the other is not. In such cases, it may be
65 better to first normalize all sides, then proceed with a standard merge.
66 This command does exactly that, and can be used as 'merge-tool' in
67 Mercurial commands like merge, rebase and graft.
68
69 Add the following to your user or repository-specific .hgrc file to use it:
70 [merge-tools]
71 i18n.executable = /path/to/scripts/i18n
72 i18n.args = normalized-merge $local $base $other $output
73
74 and then invoke merge/rebase/graft with the additional argument '--tool i18n'.
75 """
76 from mercurial import (
77 context,
78 simplemerge,
79 ui as uimod,
80 )
81
82 print('i18n normalized-merge: merging file %s' % output)
83
84 i18n_utils._normalize_po_file(local, strip=True)
85 i18n_utils._normalize_po_file(base, strip=True)
86 i18n_utils._normalize_po_file(other, strip=True)
87 i18n_utils._normalize_po_file(output, strip=True)
88
89 # simplemerge will write markers to 'local' if it fails, keep a copy without markers
90 localkeep = local + '.keep'
91 shutil.copyfile(local, localkeep)
92
93 ret = simplemerge.simplemerge(uimod.ui.load(),
94 context.arbitraryfilectx(local.encode('utf-8')),
95 context.arbitraryfilectx(base.encode('utf-8')),
96 context.arbitraryfilectx(other.encode('utf-8'))
97 )
98 shutil.copyfile(local, output) # simplemerge wrote to local
99 if ret:
100 basekeep = base + '.keep'
101 otherkeep = other + '.keep'
102 shutil.copyfile(base, basekeep)
103 shutil.copyfile(other, otherkeep)
104 sys.stderr.write("Error: simple merge failed. Run a merge tool manually to resolve conflicts, then use 'hg resolve -m'.\n")
105 sys.stderr.write('Resolve with e.g.: kdiff3 %s %s %s -o %s\n' % (basekeep, localkeep, otherkeep, output))
106 sys.exit(ret)
107
108 os.remove(localkeep)
109
110 @cli.command()
54 @click.argument('file1')
111 @click.argument('file1')
55 @click.argument('file2')
112 @click.argument('file2')
56 def normalized_diff(file1, file2):
113 def normalized_diff(file1, file2):
General Comments 0
You need to be logged in to leave comments. Login now