Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/mercurial/sparse.py Sat Jul 15 13:07:57 2017 -0700 +++ b/mercurial/sparse.py Sat Jul 15 13:21:23 2017 -0700 @@ -33,8 +33,10 @@ """ includes = set() excludes = set() - current = includes profiles = set() + current = None + havesection = False + for line in raw.split('\n'): line = line.strip() if not line or line.startswith('#'): @@ -45,14 +47,23 @@ if line: profiles.add(line) elif line == '[include]': - if current != includes: + if havesection and current != includes: # TODO pass filename into this API so we can report it. raise error.Abort(_('sparse config cannot have includes ' + 'after excludes')) + havesection = True + current = includes continue elif line == '[exclude]': + havesection = True current = excludes elif line: + if current is None: + raise error.Abort(_('sparse config entry outside of ' + 'section: %s') % line, + hint=_('add an [include] or [exclude] line ' + 'to declare the entry type')) + if line.strip().startswith('/'): ui.warn(_('warning: sparse profile cannot use' + ' paths starting with /, ignoring %s\n') % line)