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