Mercurial > hg
comparison mercurial/sparse.py @ 33551:1d1779734c99
sparse: require [section] in sparse config files (BC)
Previously, [include] was implicit and pattern lines before a
[section] were added to includes.
Because the format may change in the future and explicit behavior,
well, more explicit, this commit changes the config parser to
reject pattern lines that don't occur in a [section].
Differential Revision: https://phab.mercurial-scm.org/D96
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 15 Jul 2017 13:21:23 -0700 |
parents | 32f348d741e5 |
children | 6755b719048c |
comparison
equal
deleted
inserted
replaced
33550:32f348d741e5 | 33551:1d1779734c99 |
---|---|
31 | 31 |
32 Returns a tuple of includes, excludes, and profiles. | 32 Returns a tuple of includes, excludes, and profiles. |
33 """ | 33 """ |
34 includes = set() | 34 includes = set() |
35 excludes = set() | 35 excludes = set() |
36 current = includes | |
37 profiles = set() | 36 profiles = set() |
37 current = None | |
38 havesection = False | |
39 | |
38 for line in raw.split('\n'): | 40 for line in raw.split('\n'): |
39 line = line.strip() | 41 line = line.strip() |
40 if not line or line.startswith('#'): | 42 if not line or line.startswith('#'): |
41 # empty or comment line, skip | 43 # empty or comment line, skip |
42 continue | 44 continue |
43 elif line.startswith('%include '): | 45 elif line.startswith('%include '): |
44 line = line[9:].strip() | 46 line = line[9:].strip() |
45 if line: | 47 if line: |
46 profiles.add(line) | 48 profiles.add(line) |
47 elif line == '[include]': | 49 elif line == '[include]': |
48 if current != includes: | 50 if havesection and current != includes: |
49 # TODO pass filename into this API so we can report it. | 51 # TODO pass filename into this API so we can report it. |
50 raise error.Abort(_('sparse config cannot have includes ' + | 52 raise error.Abort(_('sparse config cannot have includes ' + |
51 'after excludes')) | 53 'after excludes')) |
54 havesection = True | |
55 current = includes | |
52 continue | 56 continue |
53 elif line == '[exclude]': | 57 elif line == '[exclude]': |
58 havesection = True | |
54 current = excludes | 59 current = excludes |
55 elif line: | 60 elif line: |
61 if current is None: | |
62 raise error.Abort(_('sparse config entry outside of ' | |
63 'section: %s') % line, | |
64 hint=_('add an [include] or [exclude] line ' | |
65 'to declare the entry type')) | |
66 | |
56 if line.strip().startswith('/'): | 67 if line.strip().startswith('/'): |
57 ui.warn(_('warning: sparse profile cannot use' + | 68 ui.warn(_('warning: sparse profile cannot use' + |
58 ' paths starting with /, ignoring %s\n') % line) | 69 ' paths starting with /, ignoring %s\n') % line) |
59 continue | 70 continue |
60 current.add(line) | 71 current.add(line) |