mercurial/diffutil.py
changeset 43077 687b865b95ad
parent 43076 2372284d9457
child 45942 89a2afe31e82
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
    16     pycompat,
    16     pycompat,
    17 )
    17 )
    18 
    18 
    19 
    19 
    20 def diffallopts(
    20 def diffallopts(
    21     ui, opts=None, untrusted=False, section='diff', configprefix=''
    21     ui, opts=None, untrusted=False, section=b'diff', configprefix=b''
    22 ):
    22 ):
    23     '''return diffopts with all features supported and parsed'''
    23     '''return diffopts with all features supported and parsed'''
    24     return difffeatureopts(
    24     return difffeatureopts(
    25         ui,
    25         ui,
    26         opts=opts,
    26         opts=opts,
    35 
    35 
    36 def difffeatureopts(
    36 def difffeatureopts(
    37     ui,
    37     ui,
    38     opts=None,
    38     opts=None,
    39     untrusted=False,
    39     untrusted=False,
    40     section='diff',
    40     section=b'diff',
    41     git=False,
    41     git=False,
    42     whitespace=False,
    42     whitespace=False,
    43     formatchanging=False,
    43     formatchanging=False,
    44     configprefix='',
    44     configprefix=b'',
    45 ):
    45 ):
    46     '''return diffopts with only opted-in features parsed
    46     '''return diffopts with only opted-in features parsed
    47 
    47 
    48     Features:
    48     Features:
    49     - git: git-style diffs
    49     - git: git-style diffs
    70             section, configprefix + (name or key), untrusted=untrusted
    70             section, configprefix + (name or key), untrusted=untrusted
    71         )
    71         )
    72 
    72 
    73     # core options, expected to be understood by every diff parser
    73     # core options, expected to be understood by every diff parser
    74     buildopts = {
    74     buildopts = {
    75         'nodates': get('nodates'),
    75         b'nodates': get(b'nodates'),
    76         'showfunc': get('show_function', 'showfunc'),
    76         b'showfunc': get(b'show_function', b'showfunc'),
    77         'context': get('unified', getter=ui.config),
    77         b'context': get(b'unified', getter=ui.config),
    78     }
    78     }
    79     buildopts['xdiff'] = ui.configbool('experimental', 'xdiff')
    79     buildopts[b'xdiff'] = ui.configbool(b'experimental', b'xdiff')
    80 
    80 
    81     if git:
    81     if git:
    82         buildopts['git'] = get('git')
    82         buildopts[b'git'] = get(b'git')
    83 
    83 
    84         # since this is in the experimental section, we need to call
    84         # since this is in the experimental section, we need to call
    85         # ui.configbool directory
    85         # ui.configbool directory
    86         buildopts['showsimilarity'] = ui.configbool(
    86         buildopts[b'showsimilarity'] = ui.configbool(
    87             'experimental', 'extendedheader.similarity'
    87             b'experimental', b'extendedheader.similarity'
    88         )
    88         )
    89 
    89 
    90         # need to inspect the ui object instead of using get() since we want to
    90         # need to inspect the ui object instead of using get() since we want to
    91         # test for an int
    91         # test for an int
    92         hconf = ui.config('experimental', 'extendedheader.index')
    92         hconf = ui.config(b'experimental', b'extendedheader.index')
    93         if hconf is not None:
    93         if hconf is not None:
    94             hlen = None
    94             hlen = None
    95             try:
    95             try:
    96                 # the hash config could be an integer (for length of hash) or a
    96                 # the hash config could be an integer (for length of hash) or a
    97                 # word (e.g. short, full, none)
    97                 # word (e.g. short, full, none)
    98                 hlen = int(hconf)
    98                 hlen = int(hconf)
    99                 if hlen < 0 or hlen > 40:
    99                 if hlen < 0 or hlen > 40:
   100                     msg = _("invalid length for extendedheader.index: '%d'\n")
   100                     msg = _(b"invalid length for extendedheader.index: '%d'\n")
   101                     ui.warn(msg % hlen)
   101                     ui.warn(msg % hlen)
   102             except ValueError:
   102             except ValueError:
   103                 # default value
   103                 # default value
   104                 if hconf == 'short' or hconf == '':
   104                 if hconf == b'short' or hconf == b'':
   105                     hlen = 12
   105                     hlen = 12
   106                 elif hconf == 'full':
   106                 elif hconf == b'full':
   107                     hlen = 40
   107                     hlen = 40
   108                 elif hconf != 'none':
   108                 elif hconf != b'none':
   109                     msg = _("invalid value for extendedheader.index: '%s'\n")
   109                     msg = _(b"invalid value for extendedheader.index: '%s'\n")
   110                     ui.warn(msg % hconf)
   110                     ui.warn(msg % hconf)
   111             finally:
   111             finally:
   112                 buildopts['index'] = hlen
   112                 buildopts[b'index'] = hlen
   113 
   113 
   114     if whitespace:
   114     if whitespace:
   115         buildopts['ignorews'] = get('ignore_all_space', 'ignorews')
   115         buildopts[b'ignorews'] = get(b'ignore_all_space', b'ignorews')
   116         buildopts['ignorewsamount'] = get(
   116         buildopts[b'ignorewsamount'] = get(
   117             'ignore_space_change', 'ignorewsamount'
   117             b'ignore_space_change', b'ignorewsamount'
   118         )
   118         )
   119         buildopts['ignoreblanklines'] = get(
   119         buildopts[b'ignoreblanklines'] = get(
   120             'ignore_blank_lines', 'ignoreblanklines'
   120             b'ignore_blank_lines', b'ignoreblanklines'
   121         )
   121         )
   122         buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol')
   122         buildopts[b'ignorewseol'] = get(b'ignore_space_at_eol', b'ignorewseol')
   123     if formatchanging:
   123     if formatchanging:
   124         buildopts['text'] = opts and opts.get('text')
   124         buildopts[b'text'] = opts and opts.get(b'text')
   125         binary = None if opts is None else opts.get('binary')
   125         binary = None if opts is None else opts.get(b'binary')
   126         buildopts['nobinary'] = (
   126         buildopts[b'nobinary'] = (
   127             not binary
   127             not binary
   128             if binary is not None
   128             if binary is not None
   129             else get('nobinary', forceplain=False)
   129             else get(b'nobinary', forceplain=False)
   130         )
   130         )
   131         buildopts['noprefix'] = get('noprefix', forceplain=False)
   131         buildopts[b'noprefix'] = get(b'noprefix', forceplain=False)
   132         buildopts['worddiff'] = get('word_diff', 'word-diff', forceplain=False)
   132         buildopts[b'worddiff'] = get(
       
   133             b'word_diff', b'word-diff', forceplain=False
       
   134         )
   133 
   135 
   134     return mdiff.diffopts(**pycompat.strkwargs(buildopts))
   136     return mdiff.diffopts(**pycompat.strkwargs(buildopts))