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