comparison hgext/githelp.py @ 41414:031d91623fdc

githelp: make argument parsing more compatible with Python 3 There were various mixing of str and bytes in here. This change fixes most of the failures in test-githelp.t. Differential Revision: https://phab.mercurial-scm.org/D5725
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 26 Jan 2019 14:14:44 -0800
parents 876494fd967d
children 873a28d7e962
comparison
equal deleted inserted replaced
41413:fad627d2047c 41414:031d91623fdc
23 from mercurial.i18n import _ 23 from mercurial.i18n import _
24 from mercurial import ( 24 from mercurial import (
25 encoding, 25 encoding,
26 error, 26 error,
27 fancyopts, 27 fancyopts,
28 pycompat,
28 registrar, 29 registrar,
29 scmutil, 30 scmutil,
30 ) 31 )
31 from mercurial.utils import ( 32 from mercurial.utils import (
32 procutil, 33 procutil,
81 while True: 82 while True:
82 try: 83 try:
83 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True) 84 args = fancyopts.fancyopts(list(args), cmdoptions, opts, True)
84 break 85 break
85 except getopt.GetoptError as ex: 86 except getopt.GetoptError as ex:
86 if "requires argument" in ex.msg: 87 if r"requires argument" in ex.msg:
87 raise 88 raise
88 if ('--' + ex.opt) in ex.msg: 89 if (r'--' + ex.opt) in ex.msg:
89 flag = '--' + ex.opt 90 flag = '--' + pycompat.bytestr(ex.opt)
90 elif ('-' + ex.opt) in ex.msg: 91 elif (r'-' + ex.opt) in ex.msg:
91 flag = '-' + ex.opt 92 flag = '-' + pycompat.bytestr(ex.opt)
92 else: 93 else:
93 raise error.Abort(_("unknown option %s") % ex.opt) 94 raise error.Abort(_("unknown option %s") %
95 pycompat.bytestr(ex.opt))
94 try: 96 try:
95 args.remove(flag) 97 args.remove(flag)
96 except Exception: 98 except Exception:
97 msg = _("unknown option '%s' packed with other options") 99 msg = _("unknown option '%s' packed with other options")
98 hint = _("please try passing the option as its own flag: -%s") 100 hint = _("please try passing the option as its own flag: -%s")
99 raise error.Abort(msg % ex.opt, hint=hint % ex.opt) 101 raise error.Abort(msg % pycompat.bytestr(ex.opt),
102 hint=hint % pycompat.bytestr(ex.opt))
100 103
101 ui.warn(_("ignoring unknown option %s\n") % flag) 104 ui.warn(_("ignoring unknown option %s\n") % flag)
102 105
103 args = list([convert(x) for x in args]) 106 args = list([convert(x) for x in args])
104 opts = dict([(k, convert(v)) if isinstance(v, str) else (k, v) 107 opts = dict([(k, convert(v)) if isinstance(v, str) else (k, v)