contrib/simplemerge
branchstable
changeset 40404 956ec6f1320d
parent 40265 d6b7c4e77bb4
child 43367 3c2799cbace4
equal deleted inserted replaced
40131:535fc8a22365 40404:956ec6f1320d
    10 from mercurial.i18n import _
    10 from mercurial.i18n import _
    11 from mercurial import (
    11 from mercurial import (
    12     context,
    12     context,
    13     error,
    13     error,
    14     fancyopts,
    14     fancyopts,
       
    15     pycompat,
    15     simplemerge,
    16     simplemerge,
    16     ui as uimod,
    17     ui as uimod,
    17 )
    18 )
    18 from mercurial.utils import (
    19 from mercurial.utils import (
    19     procutil,
    20     procutil,
    20 )
    21 )
    21 
    22 
    22 options = [('L', 'label', [], _('labels to use on conflict markers')),
    23 options = [(b'L', b'label', [], _(b'labels to use on conflict markers')),
    23            ('a', 'text', None, _('treat all files as text')),
    24            (b'a', b'text', None, _(b'treat all files as text')),
    24            ('p', 'print', None,
    25            (b'p', b'print', None,
    25             _('print results instead of overwriting LOCAL')),
    26             _(b'print results instead of overwriting LOCAL')),
    26            ('', 'no-minimal', None, _('no effect (DEPRECATED)')),
    27            (b'', b'no-minimal', None, _(b'no effect (DEPRECATED)')),
    27            ('h', 'help', None, _('display help and exit')),
    28            (b'h', b'help', None, _(b'display help and exit')),
    28            ('q', 'quiet', None, _('suppress output'))]
    29            (b'q', b'quiet', None, _(b'suppress output'))]
    29 
    30 
    30 usage = _('''simplemerge [OPTS] LOCAL BASE OTHER
    31 usage = _(b'''simplemerge [OPTS] LOCAL BASE OTHER
    31 
    32 
    32     Simple three-way file merge utility with a minimal feature set.
    33     Simple three-way file merge utility with a minimal feature set.
    33 
    34 
    34     Apply to LOCAL the changes necessary to go from BASE to OTHER.
    35     Apply to LOCAL the changes necessary to go from BASE to OTHER.
    35 
    36 
    38 
    39 
    39 class ParseError(Exception):
    40 class ParseError(Exception):
    40     """Exception raised on errors in parsing the command line."""
    41     """Exception raised on errors in parsing the command line."""
    41 
    42 
    42 def showhelp():
    43 def showhelp():
    43     sys.stdout.write(usage)
    44     pycompat.stdout.write(usage)
    44     sys.stdout.write('\noptions:\n')
    45     pycompat.stdout.write(b'\noptions:\n')
    45 
    46 
    46     out_opts = []
    47     out_opts = []
    47     for shortopt, longopt, default, desc in options:
    48     for shortopt, longopt, default, desc in options:
    48         out_opts.append(('%2s%s' % (shortopt and '-%s' % shortopt,
    49         out_opts.append((b'%2s%s' % (shortopt and b'-%s' % shortopt,
    49                                     longopt and ' --%s' % longopt),
    50                                      longopt and b' --%s' % longopt),
    50                          '%s' % desc))
    51                          b'%s' % desc))
    51     opts_len = max([len(opt[0]) for opt in out_opts])
    52     opts_len = max([len(opt[0]) for opt in out_opts])
    52     for first, second in out_opts:
    53     for first, second in out_opts:
    53         sys.stdout.write(' %-*s  %s\n' % (opts_len, first, second))
    54         pycompat.stdout.write(b' %-*s  %s\n' % (opts_len, first, second))
    54 
    55 
    55 try:
    56 try:
    56     for fp in (sys.stdin, sys.stdout, sys.stderr):
    57     for fp in (sys.stdin, pycompat.stdout, sys.stderr):
    57         procutil.setbinary(fp)
    58         procutil.setbinary(fp)
    58 
    59 
    59     opts = {}
    60     opts = {}
    60     try:
    61     try:
    61         args = fancyopts.fancyopts(sys.argv[1:], options, opts)
    62         bargv = [a.encode('utf8') for a in sys.argv[1:]]
       
    63         args = fancyopts.fancyopts(bargv, options, opts)
    62     except getopt.GetoptError as e:
    64     except getopt.GetoptError as e:
    63         raise ParseError(e)
    65         raise ParseError(e)
    64     if opts['help']:
    66     if opts[b'help']:
    65         showhelp()
    67         showhelp()
    66         sys.exit(0)
    68         sys.exit(0)
    67     if len(args) != 3:
    69     if len(args) != 3:
    68             raise ParseError(_('wrong number of arguments'))
    70             raise ParseError(_(b'wrong number of arguments').decode('utf8'))
    69     local, base, other = args
    71     local, base, other = args
    70     sys.exit(simplemerge.simplemerge(uimod.ui.load(),
    72     sys.exit(simplemerge.simplemerge(uimod.ui.load(),
    71                                      context.arbitraryfilectx(local),
    73                                      context.arbitraryfilectx(local),
    72                                      context.arbitraryfilectx(base),
    74                                      context.arbitraryfilectx(base),
    73                                      context.arbitraryfilectx(other),
    75                                      context.arbitraryfilectx(other),
    74                                      **opts))
    76                                      **pycompat.strkwargs(opts)))
    75 except ParseError as e:
    77 except ParseError as e:
    76     sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
    78     if pycompat.ispy3:
       
    79         e = str(e).encode('utf8')
       
    80     pycompat.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e))
    77     showhelp()
    81     showhelp()
    78     sys.exit(1)
    82     sys.exit(1)
    79 except error.Abort as e:
    83 except error.Abort as e:
    80     sys.stderr.write("abort: %s\n" % e)
    84     pycompat.stderr.write(b"abort: %s\n" % e)
    81     sys.exit(255)
    85     sys.exit(255)
    82 except KeyboardInterrupt:
    86 except KeyboardInterrupt:
    83     sys.exit(255)
    87     sys.exit(255)