contrib/simplemerge
changeset 48752 109fec7bf7de
parent 48749 9ee70e175fed
child 48755 6ae3c97a0919
equal deleted inserted replaced
48751:59c6724ddccb 48752:109fec7bf7de
    62     opts_len = max([len(opt[0]) for opt in out_opts])
    62     opts_len = max([len(opt[0]) for opt in out_opts])
    63     for first, second in out_opts:
    63     for first, second in out_opts:
    64         procutil.stdout.write(b' %-*s  %s\n' % (opts_len, first, second))
    64         procutil.stdout.write(b' %-*s  %s\n' % (opts_len, first, second))
    65 
    65 
    66 
    66 
       
    67 def _verifytext(input, ui, quiet=False, allow_binary=False):
       
    68     """verifies that text is non-binary (unless opts[text] is passed,
       
    69     then we just warn)"""
       
    70     if stringutil.binary(input.text()):
       
    71         msg = _(b"%s looks like a binary file.") % input.fctx.path()
       
    72         if not quiet:
       
    73             ui.warn(_(b'warning: %s\n') % msg)
       
    74         if not allow_binary:
       
    75             sys.exit(1)
       
    76 
       
    77 
    67 try:
    78 try:
    68     for fp in (sys.stdin, procutil.stdout, sys.stderr):
    79     for fp in (sys.stdin, procutil.stdout, sys.stderr):
    69         procutil.setbinary(fp)
    80         procutil.setbinary(fp)
    70 
    81 
    71     opts = {}
    82     opts = {}
    95         context.arbitraryfilectx(other), labels[1]
   106         context.arbitraryfilectx(other), labels[1]
    96     )
   107     )
    97     base_input = simplemerge.MergeInput(
   108     base_input = simplemerge.MergeInput(
    98         context.arbitraryfilectx(base), labels[2]
   109         context.arbitraryfilectx(base), labels[2]
    99     )
   110     )
       
   111 
       
   112     quiet = opts.get(b'quiet')
       
   113     allow_binary = opts.get(b'text')
       
   114     ui = uimod.ui.load()
       
   115     _verifytext(local_input, ui, quiet=quiet, allow_binary=allow_binary)
       
   116     _verifytext(base_input, ui, quiet=quiet, allow_binary=allow_binary)
       
   117     _verifytext(other_input, ui, quiet=quiet, allow_binary=allow_binary)
       
   118 
   100     sys.exit(
   119     sys.exit(
   101         simplemerge.simplemerge(
   120         simplemerge.simplemerge(
   102             uimod.ui.load(),
   121             ui,
   103             local_input,
   122             local_input,
   104             base_input,
   123             base_input,
   105             other_input,
   124             other_input,
   106             mode,
   125             mode,
   107             quiet=opts.get(b'quiet'),
   126             quiet=True,
   108             allow_binary=opts.get(b'text'),
   127             allow_binary=allow_binary,
   109             print_result=opts.get(b'print'),
   128             print_result=opts.get(b'print'),
   110         )
   129         )
   111     )
   130     )
   112 except ParseError as e:
   131 except ParseError as e:
   113     e = stringutil.forcebytestr(e)
   132     e = stringutil.forcebytestr(e)