14 from . import ( |
14 from . import ( |
15 mdiff, |
15 mdiff, |
16 pycompat, |
16 pycompat, |
17 ) |
17 ) |
18 |
18 |
19 def diffallopts(ui, opts=None, untrusted=False, section='diff', |
19 |
20 configprefix=''): |
20 def diffallopts( |
|
21 ui, opts=None, untrusted=False, section='diff', configprefix='' |
|
22 ): |
21 '''return diffopts with all features supported and parsed''' |
23 '''return diffopts with all features supported and parsed''' |
22 return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section, |
24 return difffeatureopts( |
23 git=True, whitespace=True, formatchanging=True, |
25 ui, |
24 configprefix=configprefix) |
26 opts=opts, |
|
27 untrusted=untrusted, |
|
28 section=section, |
|
29 git=True, |
|
30 whitespace=True, |
|
31 formatchanging=True, |
|
32 configprefix=configprefix, |
|
33 ) |
25 |
34 |
26 def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False, |
35 |
27 whitespace=False, formatchanging=False, configprefix=''): |
36 def difffeatureopts( |
|
37 ui, |
|
38 opts=None, |
|
39 untrusted=False, |
|
40 section='diff', |
|
41 git=False, |
|
42 whitespace=False, |
|
43 formatchanging=False, |
|
44 configprefix='', |
|
45 ): |
28 '''return diffopts with only opted-in features parsed |
46 '''return diffopts with only opted-in features parsed |
29 |
47 |
30 Features: |
48 Features: |
31 - git: git-style diffs |
49 - git: git-style diffs |
32 - whitespace: whitespace options like ignoreblanklines and ignorews |
50 - whitespace: whitespace options like ignoreblanklines and ignorews |
33 - formatchanging: options that will likely break or cause correctness issues |
51 - formatchanging: options that will likely break or cause correctness issues |
34 with most diff parsers |
52 with most diff parsers |
35 ''' |
53 ''' |
|
54 |
36 def get(key, name=None, getter=ui.configbool, forceplain=None): |
55 def get(key, name=None, getter=ui.configbool, forceplain=None): |
37 if opts: |
56 if opts: |
38 v = opts.get(key) |
57 v = opts.get(key) |
39 # diffopts flags are either None-default (which is passed |
58 # diffopts flags are either None-default (which is passed |
40 # through unchanged, so we can identify unset values), or |
59 # through unchanged, so we can identify unset values), or |
45 # True, or False. |
64 # True, or False. |
46 if v or isinstance(v, bool): |
65 if v or isinstance(v, bool): |
47 return v |
66 return v |
48 if forceplain is not None and ui.plain(): |
67 if forceplain is not None and ui.plain(): |
49 return forceplain |
68 return forceplain |
50 return getter(section, configprefix + (name or key), |
69 return getter( |
51 untrusted=untrusted) |
70 section, configprefix + (name or key), untrusted=untrusted |
|
71 ) |
52 |
72 |
53 # core options, expected to be understood by every diff parser |
73 # core options, expected to be understood by every diff parser |
54 buildopts = { |
74 buildopts = { |
55 'nodates': get('nodates'), |
75 'nodates': get('nodates'), |
56 'showfunc': get('show_function', 'showfunc'), |
76 'showfunc': get('show_function', 'showfunc'), |
61 if git: |
81 if git: |
62 buildopts['git'] = get('git') |
82 buildopts['git'] = get('git') |
63 |
83 |
64 # since this is in the experimental section, we need to call |
84 # since this is in the experimental section, we need to call |
65 # ui.configbool directory |
85 # ui.configbool directory |
66 buildopts['showsimilarity'] = ui.configbool('experimental', |
86 buildopts['showsimilarity'] = ui.configbool( |
67 'extendedheader.similarity') |
87 'experimental', 'extendedheader.similarity' |
|
88 ) |
68 |
89 |
69 # 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 |
70 # test for an int |
91 # test for an int |
71 hconf = ui.config('experimental', 'extendedheader.index') |
92 hconf = ui.config('experimental', 'extendedheader.index') |
72 if hconf is not None: |
93 if hconf is not None: |
90 finally: |
111 finally: |
91 buildopts['index'] = hlen |
112 buildopts['index'] = hlen |
92 |
113 |
93 if whitespace: |
114 if whitespace: |
94 buildopts['ignorews'] = get('ignore_all_space', 'ignorews') |
115 buildopts['ignorews'] = get('ignore_all_space', 'ignorews') |
95 buildopts['ignorewsamount'] = get('ignore_space_change', |
116 buildopts['ignorewsamount'] = get( |
96 'ignorewsamount') |
117 'ignore_space_change', 'ignorewsamount' |
97 buildopts['ignoreblanklines'] = get('ignore_blank_lines', |
118 ) |
98 'ignoreblanklines') |
119 buildopts['ignoreblanklines'] = get( |
|
120 'ignore_blank_lines', 'ignoreblanklines' |
|
121 ) |
99 buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol') |
122 buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol') |
100 if formatchanging: |
123 if formatchanging: |
101 buildopts['text'] = opts and opts.get('text') |
124 buildopts['text'] = opts and opts.get('text') |
102 binary = None if opts is None else opts.get('binary') |
125 binary = None if opts is None else opts.get('binary') |
103 buildopts['nobinary'] = (not binary if binary is not None |
126 buildopts['nobinary'] = ( |
104 else get('nobinary', forceplain=False)) |
127 not binary |
|
128 if binary is not None |
|
129 else get('nobinary', forceplain=False) |
|
130 ) |
105 buildopts['noprefix'] = get('noprefix', forceplain=False) |
131 buildopts['noprefix'] = get('noprefix', forceplain=False) |
106 buildopts['worddiff'] = get('word_diff', 'word-diff', forceplain=False) |
132 buildopts['worddiff'] = get('word_diff', 'word-diff', forceplain=False) |
107 |
133 |
108 return mdiff.diffopts(**pycompat.strkwargs(buildopts)) |
134 return mdiff.diffopts(**pycompat.strkwargs(buildopts)) |