Show More
@@ -1,105 +1,108 b'' | |||||
1 | # diffutil.py - utility functions related to diff and patch |
|
1 | # diffutil.py - utility functions related to diff and patch | |
2 | # |
|
2 | # | |
3 | # Copyright 2006 Brendan Cully <brendan@kublai.com> |
|
3 | # Copyright 2006 Brendan Cully <brendan@kublai.com> | |
4 | # Copyright 2007 Chris Mason <chris.mason@oracle.com> |
|
4 | # Copyright 2007 Chris Mason <chris.mason@oracle.com> | |
5 | # Copyright 2018 Octobus <octobus@octobus.net> |
|
5 | # Copyright 2018 Octobus <octobus@octobus.net> | |
6 | # |
|
6 | # | |
7 | # This software may be used and distributed according to the terms of the |
|
7 | # This software may be used and distributed according to the terms of the | |
8 | # GNU General Public License version 2 or any later version. |
|
8 | # GNU General Public License version 2 or any later version. | |
9 |
|
9 | |||
10 | from __future__ import absolute_import |
|
10 | from __future__ import absolute_import | |
11 |
|
11 | |||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 |
|
13 | |||
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 | def diffallopts(ui, opts=None, untrusted=False, section='diff', | |
|
20 | configprefix=''): | |||
20 | '''return diffopts with all features supported and parsed''' |
|
21 | '''return diffopts with all features supported and parsed''' | |
21 | return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section, |
|
22 | return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section, | |
22 |
git=True, whitespace=True, formatchanging=True |
|
23 | git=True, whitespace=True, formatchanging=True, | |
|
24 | configprefix=configprefix) | |||
23 |
|
25 | |||
24 | def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False, |
|
26 | def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False, | |
25 | whitespace=False, formatchanging=False): |
|
27 | whitespace=False, formatchanging=False, configprefix=''): | |
26 | '''return diffopts with only opted-in features parsed |
|
28 | '''return diffopts with only opted-in features parsed | |
27 |
|
29 | |||
28 | Features: |
|
30 | Features: | |
29 | - git: git-style diffs |
|
31 | - git: git-style diffs | |
30 | - whitespace: whitespace options like ignoreblanklines and ignorews |
|
32 | - whitespace: whitespace options like ignoreblanklines and ignorews | |
31 | - formatchanging: options that will likely break or cause correctness issues |
|
33 | - formatchanging: options that will likely break or cause correctness issues | |
32 | with most diff parsers |
|
34 | with most diff parsers | |
33 | ''' |
|
35 | ''' | |
34 | def get(key, name=None, getter=ui.configbool, forceplain=None): |
|
36 | def get(key, name=None, getter=ui.configbool, forceplain=None): | |
35 | if opts: |
|
37 | if opts: | |
36 | v = opts.get(key) |
|
38 | v = opts.get(key) | |
37 | # diffopts flags are either None-default (which is passed |
|
39 | # diffopts flags are either None-default (which is passed | |
38 | # through unchanged, so we can identify unset values), or |
|
40 | # through unchanged, so we can identify unset values), or | |
39 | # some other falsey default (eg --unified, which defaults |
|
41 | # some other falsey default (eg --unified, which defaults | |
40 | # to an empty string). We only want to override the config |
|
42 | # to an empty string). We only want to override the config | |
41 | # entries from hgrc with command line values if they |
|
43 | # entries from hgrc with command line values if they | |
42 | # appear to have been set, which is any truthy value, |
|
44 | # appear to have been set, which is any truthy value, | |
43 | # True, or False. |
|
45 | # True, or False. | |
44 | if v or isinstance(v, bool): |
|
46 | if v or isinstance(v, bool): | |
45 | return v |
|
47 | return v | |
46 | if forceplain is not None and ui.plain(): |
|
48 | if forceplain is not None and ui.plain(): | |
47 | return forceplain |
|
49 | return forceplain | |
48 |
return getter(section, name or key, |
|
50 | return getter(section, configprefix + (name or key), | |
|
51 | untrusted=untrusted) | |||
49 |
|
52 | |||
50 | # core options, expected to be understood by every diff parser |
|
53 | # core options, expected to be understood by every diff parser | |
51 | buildopts = { |
|
54 | buildopts = { | |
52 | 'nodates': get('nodates'), |
|
55 | 'nodates': get('nodates'), | |
53 | 'showfunc': get('show_function', 'showfunc'), |
|
56 | 'showfunc': get('show_function', 'showfunc'), | |
54 | 'context': get('unified', getter=ui.config), |
|
57 | 'context': get('unified', getter=ui.config), | |
55 | } |
|
58 | } | |
56 | buildopts['xdiff'] = ui.configbool('experimental', 'xdiff') |
|
59 | buildopts['xdiff'] = ui.configbool('experimental', 'xdiff') | |
57 |
|
60 | |||
58 | if git: |
|
61 | if git: | |
59 | buildopts['git'] = get('git') |
|
62 | buildopts['git'] = get('git') | |
60 |
|
63 | |||
61 | # since this is in the experimental section, we need to call |
|
64 | # since this is in the experimental section, we need to call | |
62 | # ui.configbool directory |
|
65 | # ui.configbool directory | |
63 | buildopts['showsimilarity'] = ui.configbool('experimental', |
|
66 | buildopts['showsimilarity'] = ui.configbool('experimental', | |
64 | 'extendedheader.similarity') |
|
67 | 'extendedheader.similarity') | |
65 |
|
68 | |||
66 | # need to inspect the ui object instead of using get() since we want to |
|
69 | # need to inspect the ui object instead of using get() since we want to | |
67 | # test for an int |
|
70 | # test for an int | |
68 | hconf = ui.config('experimental', 'extendedheader.index') |
|
71 | hconf = ui.config('experimental', 'extendedheader.index') | |
69 | if hconf is not None: |
|
72 | if hconf is not None: | |
70 | hlen = None |
|
73 | hlen = None | |
71 | try: |
|
74 | try: | |
72 | # the hash config could be an integer (for length of hash) or a |
|
75 | # the hash config could be an integer (for length of hash) or a | |
73 | # word (e.g. short, full, none) |
|
76 | # word (e.g. short, full, none) | |
74 | hlen = int(hconf) |
|
77 | hlen = int(hconf) | |
75 | if hlen < 0 or hlen > 40: |
|
78 | if hlen < 0 or hlen > 40: | |
76 | msg = _("invalid length for extendedheader.index: '%d'\n") |
|
79 | msg = _("invalid length for extendedheader.index: '%d'\n") | |
77 | ui.warn(msg % hlen) |
|
80 | ui.warn(msg % hlen) | |
78 | except ValueError: |
|
81 | except ValueError: | |
79 | # default value |
|
82 | # default value | |
80 | if hconf == 'short' or hconf == '': |
|
83 | if hconf == 'short' or hconf == '': | |
81 | hlen = 12 |
|
84 | hlen = 12 | |
82 | elif hconf == 'full': |
|
85 | elif hconf == 'full': | |
83 | hlen = 40 |
|
86 | hlen = 40 | |
84 | elif hconf != 'none': |
|
87 | elif hconf != 'none': | |
85 | msg = _("invalid value for extendedheader.index: '%s'\n") |
|
88 | msg = _("invalid value for extendedheader.index: '%s'\n") | |
86 | ui.warn(msg % hconf) |
|
89 | ui.warn(msg % hconf) | |
87 | finally: |
|
90 | finally: | |
88 | buildopts['index'] = hlen |
|
91 | buildopts['index'] = hlen | |
89 |
|
92 | |||
90 | if whitespace: |
|
93 | if whitespace: | |
91 | buildopts['ignorews'] = get('ignore_all_space', 'ignorews') |
|
94 | buildopts['ignorews'] = get('ignore_all_space', 'ignorews') | |
92 | buildopts['ignorewsamount'] = get('ignore_space_change', |
|
95 | buildopts['ignorewsamount'] = get('ignore_space_change', | |
93 | 'ignorewsamount') |
|
96 | 'ignorewsamount') | |
94 | buildopts['ignoreblanklines'] = get('ignore_blank_lines', |
|
97 | buildopts['ignoreblanklines'] = get('ignore_blank_lines', | |
95 | 'ignoreblanklines') |
|
98 | 'ignoreblanklines') | |
96 | buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol') |
|
99 | buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol') | |
97 | if formatchanging: |
|
100 | if formatchanging: | |
98 | buildopts['text'] = opts and opts.get('text') |
|
101 | buildopts['text'] = opts and opts.get('text') | |
99 | binary = None if opts is None else opts.get('binary') |
|
102 | binary = None if opts is None else opts.get('binary') | |
100 | buildopts['nobinary'] = (not binary if binary is not None |
|
103 | buildopts['nobinary'] = (not binary if binary is not None | |
101 | else get('nobinary', forceplain=False)) |
|
104 | else get('nobinary', forceplain=False)) | |
102 | buildopts['noprefix'] = get('noprefix', forceplain=False) |
|
105 | buildopts['noprefix'] = get('noprefix', forceplain=False) | |
103 | buildopts['worddiff'] = get('word_diff', 'word-diff', forceplain=False) |
|
106 | buildopts['worddiff'] = get('word_diff', 'word-diff', forceplain=False) | |
104 |
|
107 | |||
105 | return mdiff.diffopts(**pycompat.strkwargs(buildopts)) |
|
108 | return mdiff.diffopts(**pycompat.strkwargs(buildopts)) |
General Comments 0
You need to be logged in to leave comments.
Login now