changeset 9006:419329d436fd stable

scripts: update i18n dev script to modern hg Support for old hg versions is not a concern for dev scripts like this.
author Mads Kiilerich <mads@kiilerich.com>
date Sat, 20 Jul 2024 17:10:24 +0200
parents edcd5eafc890
children 92653a85a87e
files scripts/i18n
diffstat 1 files changed, 8 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/i18n	Fri Jul 19 21:03:19 2024 +0200
+++ b/scripts/i18n	Sat Jul 20 17:10:24 2024 +0200
@@ -20,6 +20,7 @@
 
 import click
 import i18n_utils
+from mercurial import util
 
 
 """
@@ -90,28 +91,25 @@
     and then invoke merge/rebase/graft with the additional argument '--tool i18n'.
     """
     from mercurial import context, simplemerge
-    from mercurial import ui as uimod
 
     print('i18n normalized-merge: normalizing and merging %s' % output)
 
     i18n_utils._normalize_po_file(local, merge_pot_file=merge_pot_file, strip=strip)
     i18n_utils._normalize_po_file(base, merge_pot_file=merge_pot_file, strip=strip)
     i18n_utils._normalize_po_file(other, merge_pot_file=merge_pot_file, strip=strip)
-    i18n_utils._normalize_po_file(output, merge_pot_file=merge_pot_file, strip=strip)
 
     # simplemerge will write markers to 'local' if it fails, keep a copy without markers
     localkeep = local + '.keep'
     shutil.copyfile(local, localkeep)
 
-    ret = simplemerge.simplemerge(uimod.ui.load(),
-         context.arbitraryfilectx(local.encode('utf-8')),
-         context.arbitraryfilectx(base.encode('utf-8')),
-         context.arbitraryfilectx(other.encode('utf-8')),
-         label=[b'local', b'other', b'base'],
+    merged_text, conflicts = simplemerge.simplemerge(
+         simplemerge.MergeInput(context.arbitraryfilectx(local.encode('utf-8'), b'local')),
+         simplemerge.MergeInput(context.arbitraryfilectx(base.encode('utf-8'), b'base')),
+         simplemerge.MergeInput(context.arbitraryfilectx(other.encode('utf-8'), b'other')),
          mode='merge',
     )
-    shutil.copyfile(local, output)  # simplemerge wrote to local - either resolved or with conflict markers
-    if ret:
+    util.writefile(output, merged_text)  # either resolved or with conflict markers
+    if conflicts:
         shutil.copyfile(localkeep, local)
         basekeep = base + '.keep'
         otherkeep = other + '.keep'
@@ -119,7 +117,7 @@
         shutil.copyfile(other, otherkeep)
         sys.stderr.write("Error: simple merge failed and %s is left with conflict markers. Resolve the conflicts, then use 'hg resolve -m'.\n" % output)
         sys.stderr.write('Resolve with e.g.: kdiff3 %s %s %s -o %s\n' % (basekeep, localkeep, otherkeep, output))
-        sys.exit(ret)
+        sys.exit(1)
 
     os.remove(localkeep)