contrib/simplemerge
author Raphaël Gomès <rgomes@octobus.net>
Wed, 04 May 2022 18:00:01 +0200
branchstable
changeset 49161 0ddd5e1f5f67
parent 48758 7dad4665d223
child 48875 6000f5b25c9b
permissions -rw-r--r--
ci: remove py2-rust support Nobody cares about this very narrow usecase, and py2 support is over by July 1st. This helps with the CI load, and removes some flakiness.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45830
c102b704edb5 global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 45055
diff changeset
     1
#!/usr/bin/env python3
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     2
from __future__ import absolute_import
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
     3
30576
541949a10a68 fancyopts: switch from fancyopts.getopt.* to getopt.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30559
diff changeset
     4
import getopt
19378
9de689d20230 cleanup: drop unused variables and an unused import
Simon Heimberg <simohe@besonet.ch>
parents: 19022
diff changeset
     5
import sys
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     6
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     7
import hgdemandimport
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
     8
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
     9
hgdemandimport.enable()
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    10
4363
2e3c54fb79a3 actually port simplemerge to hg
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4362
diff changeset
    11
from mercurial.i18n import _
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    12
from mercurial import (
34051
d2fc88426d21 context: add arbitraryfilectx, which can represent files outside the workdir
Phil Cohen <phillco@fb.com>
parents: 34050
diff changeset
    13
    context,
33895
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    14
    error,
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    15
    fancyopts,
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    16
    simplemerge,
aed91971d88c simplemerge: update to conform with modern import conventions
Augie Fackler <raf@durin42.com>
parents: 30576
diff changeset
    17
    ui as uimod,
48755
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
    18
    util,
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 34051
diff changeset
    19
)
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    20
from mercurial.utils import procutil, stringutil
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    21
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    22
options = [
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    23
    (b'L', b'label', [], _(b'labels to use on conflict markers')),
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    24
    (b'a', b'text', None, _(b'treat all files as text')),
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    25
    (b'p', b'print', None, _(b'print results instead of overwriting LOCAL')),
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    26
    (b'', b'no-minimal', None, _(b'no effect (DEPRECATED)')),
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    27
    (b'h', b'help', None, _(b'display help and exit')),
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    28
    (b'q', b'quiet', None, _(b'suppress output')),
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    29
]
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    30
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    31
usage = _(
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    32
    b'''simplemerge [OPTS] LOCAL BASE OTHER
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    33
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    34
    Simple three-way file merge utility with a minimal feature set.
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
    35
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    36
    Apply to LOCAL the changes necessary to go from BASE to OTHER.
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4408
diff changeset
    37
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    38
    By default, LOCAL is overwritten with the results of this operation.
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    39
'''
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    40
)
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    41
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    42
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    43
class ParseError(Exception):
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    44
    """Exception raised on errors in parsing the command line."""
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    45
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    46
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    47
def showhelp():
45055
4c1b4805db57 pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents: 43659
diff changeset
    48
    procutil.stdout.write(usage)
4c1b4805db57 pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents: 43659
diff changeset
    49
    procutil.stdout.write(b'\noptions:\n')
4362
465b9ea02868 Import 3-way merge code from bzr
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
diff changeset
    50
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    51
    out_opts = []
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    52
    for shortopt, longopt, default, desc in options:
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    53
        out_opts.append(
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    54
            (
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    55
                b'%2s%s'
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    56
                % (
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    57
                    shortopt and b'-%s' % shortopt,
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    58
                    longopt and b' --%s' % longopt,
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    59
                ),
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    60
                b'%s' % desc,
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    61
            )
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    62
        )
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    63
    opts_len = max([len(opt[0]) for opt in out_opts])
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    64
    for first, second in out_opts:
45055
4c1b4805db57 pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents: 43659
diff changeset
    65
        procutil.stdout.write(b' %-*s  %s\n' % (opts_len, first, second))
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    66
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    67
48752
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    68
def _verifytext(input, ui, quiet=False, allow_binary=False):
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    69
    """verifies that text is non-binary (unless opts[text] is passed,
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    70
    then we just warn)"""
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    71
    if stringutil.binary(input.text()):
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    72
        msg = _(b"%s looks like a binary file.") % input.fctx.path()
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    73
        if not quiet:
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    74
            ui.warn(_(b'warning: %s\n') % msg)
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    75
        if not allow_binary:
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    76
            sys.exit(1)
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    77
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
    78
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    79
try:
45055
4c1b4805db57 pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents: 43659
diff changeset
    80
    for fp in (sys.stdin, procutil.stdout, sys.stderr):
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 34051
diff changeset
    81
        procutil.setbinary(fp)
19022
cba222f01056 tests: run check-code on Python files without .py extension
Mads Kiilerich <madski@unity3d.com>
parents: 14233
diff changeset
    82
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    83
    opts = {}
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    84
    try:
40260
b54d93fc3ba8 simplemerge: port to Python 3
Augie Fackler <augie@google.com>
parents: 39791
diff changeset
    85
        bargv = [a.encode('utf8') for a in sys.argv[1:]]
b54d93fc3ba8 simplemerge: port to Python 3
Augie Fackler <augie@google.com>
parents: 39791
diff changeset
    86
        args = fancyopts.fancyopts(bargv, options, opts)
30576
541949a10a68 fancyopts: switch from fancyopts.getopt.* to getopt.*
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30559
diff changeset
    87
    except getopt.GetoptError as e:
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    88
        raise ParseError(e)
39790
d3e940a32be0 py3: add b'' prefixes in contrib/simplemerge
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37120
diff changeset
    89
    if opts[b'help']:
4364
d5c3a70f8422 polish the simplemerge command; add a test
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4363
diff changeset
    90
        showhelp()
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    91
        sys.exit(0)
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
    92
    if len(args) != 3:
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
    93
        raise ParseError(_(b'wrong number of arguments').decode('utf8'))
48749
9ee70e175fed simplemerge: replace `**opts` passed to `simplemerge()` by keyword arguments
Martin von Zweigbergk <martinvonz@google.com>
parents: 48578
diff changeset
    94
    mode = b'merge'
48555
c91418480cb0 simplemerge: use 3-way markers if mode=='merge3', ignoring number of labels
Martin von Zweigbergk <martinvonz@google.com>
parents: 45830
diff changeset
    95
    if len(opts[b'label']) > 2:
48749
9ee70e175fed simplemerge: replace `**opts` passed to `simplemerge()` by keyword arguments
Martin von Zweigbergk <martinvonz@google.com>
parents: 48578
diff changeset
    96
        mode = b'merge3'
33903
ed6f64173121 contrib: make simplemerge script pass context-like objects
Phil Cohen <phillco@fb.com>
parents: 33895
diff changeset
    97
    local, base, other = args
48560
6ad70879d2bd simplemerge: move default labels to simplemerge extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48555
diff changeset
    98
    overrides = opts[b'label']
48578
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
    99
    if len(overrides) > 3:
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   100
        raise error.InputError(b'can only specify three labels.')
48560
6ad70879d2bd simplemerge: move default labels to simplemerge extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48555
diff changeset
   101
    labels = [local, other, base]
6ad70879d2bd simplemerge: move default labels to simplemerge extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48555
diff changeset
   102
    labels[: len(overrides)] = overrides
48578
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   103
    local_input = simplemerge.MergeInput(
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   104
        context.arbitraryfilectx(local), labels[0]
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   105
    )
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   106
    other_input = simplemerge.MergeInput(
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   107
        context.arbitraryfilectx(other), labels[1]
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   108
    )
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   109
    base_input = simplemerge.MergeInput(
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   110
        context.arbitraryfilectx(base), labels[2]
77e24ee8994b simplemerge: take arguments as annotated context objects
Martin von Zweigbergk <martinvonz@google.com>
parents: 48560
diff changeset
   111
    )
48752
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
   112
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
   113
    quiet = opts.get(b'quiet')
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
   114
    allow_binary = opts.get(b'text')
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
   115
    ui = uimod.ui.load()
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
   116
    _verifytext(local_input, ui, quiet=quiet, allow_binary=allow_binary)
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
   117
    _verifytext(base_input, ui, quiet=quiet, allow_binary=allow_binary)
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
   118
    _verifytext(other_input, ui, quiet=quiet, allow_binary=allow_binary)
109fec7bf7de simplemerge: let extension check for binary inputs (unless `--text`)
Martin von Zweigbergk <martinvonz@google.com>
parents: 48749
diff changeset
   119
48755
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   120
    merged_text, conflicts = simplemerge.simplemerge(
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   121
        local_input,
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   122
        base_input,
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   123
        other_input,
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   124
        mode,
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   125
        allow_binary=allow_binary,
43659
99e231afc29c black: blacken scripts
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43367
diff changeset
   126
    )
48755
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   127
    if opts.get(b'print'):
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   128
        ui.fout.write(merged_text)
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   129
    else:
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   130
        util.writefile(local, merged_text)
6ae3c97a0919 simplemerge: move printing of merge result to extension
Martin von Zweigbergk <martinvonz@google.com>
parents: 48752
diff changeset
   131
    sys.exit(1 if conflicts else 0)
28047
863075fd4cd0 misc: use modern exception syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   132
except ParseError as e:
43367
3c2799cbace4 py3: fix exception display encoding in contrib/simplemerge.py
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents: 40265
diff changeset
   133
    e = stringutil.forcebytestr(e)
45055
4c1b4805db57 pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents: 43659
diff changeset
   134
    procutil.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e))
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
   135
    showhelp()
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
   136
    sys.exit(1)
28047
863075fd4cd0 misc: use modern exception syntax
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26587
diff changeset
   137
except error.Abort as e:
45055
4c1b4805db57 pycompat: change users of pycompat.{stdin,stdout,stderr} to use procutil.std*
Manuel Jacob <me@manueljacob.de>
parents: 43659
diff changeset
   138
    procutil.stderr.write(b"abort: %s\n" % e)
6002
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
   139
    sys.exit(255)
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
   140
except KeyboardInterrupt:
abd66eb0889e merge: move the bulk of simplemerge into core
Matt Mackall <mpm@selenic.com>
parents: 5081
diff changeset
   141
    sys.exit(255)