diff --git a/contrib/simplemerge b/contrib/simplemerge --- a/contrib/simplemerge +++ b/contrib/simplemerge @@ -13,7 +13,6 @@ context, error, fancyopts, - pycompat, simplemerge, ui as uimod, ) @@ -80,8 +79,9 @@ sys.exit(0) if len(args) != 3: raise ParseError(_(b'wrong number of arguments').decode('utf8')) + mode = b'merge' if len(opts[b'label']) > 2: - opts[b'mode'] = b'merge3' + mode = b'merge3' local, base, other = args overrides = opts[b'label'] if len(overrides) > 3: @@ -103,7 +103,10 @@ local_input, base_input, other_input, - **pycompat.strkwargs(opts) + mode, + quiet=opts.get(b'quiet'), + allow_binary=opts.get(b'text'), + print_result=opts.get(b'print'), ) ) except ParseError as e: diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py --- a/mercurial/simplemerge.py +++ b/mercurial/simplemerge.py @@ -273,14 +273,14 @@ return sl -def _verifytext(text, path, ui, opts): +def _verifytext(text, path, ui, quiet=False, allow_binary=False): """verifies that text is non-binary (unless opts[text] is passed, then we just warn)""" if stringutil.binary(text): msg = _(b"%s looks like a binary file.") % path - if not opts.get('quiet'): + if not quiet: ui.warn(_(b'warning: %s\n') % msg) - if not opts.get('text'): + if not allow_binary: raise error.Abort(msg) return text @@ -484,7 +484,16 @@ label_detail = attr.ib(default=None) -def simplemerge(ui, local, base, other, **opts): +def simplemerge( + ui, + local, + base, + other, + mode=b'merge', + quiet=False, + allow_binary=False, + print_result=False, +): """Performs the simplemerge algorithm. The merged result is written into `localctx`. @@ -498,7 +507,13 @@ # Maintain that behavior today for BC, though perhaps in the future # it'd be worth considering whether merging encoded data (what the # repository usually sees) might be more useful. - return _verifytext(ctx.decodeddata(), ctx.path(), ui, opts) + return _verifytext( + ctx.decodeddata(), + ctx.path(), + ui, + quiet=quiet, + allow_binary=allow_binary, + ) try: localtext = readctx(local.fctx) @@ -509,7 +524,6 @@ m3 = Merge3Text(basetext, localtext, othertext) conflicts = False - mode = opts.get('mode', b'merge') if mode == b'union': lines = _resolve(m3, (1, 2)) elif mode == b'local': @@ -528,7 +542,7 @@ lines, conflicts = render_minimized(m3, *labels) mergedtext = b''.join(lines) - if opts.get('print'): + if print_result: ui.fout.write(mergedtext) else: # local.fctx.flags() already has the merged flags (done in