Mercurial > hg
comparison mercurial/sparse.py @ 33297:ba5d89774db6
sparse: move config parsing into core
This patch marks the beginning of moving code from the sparse
extension into core. The goal is to move as much of the
functionality as possible into core, where it will be an
experimental feature. The extension will likely continue to
exist to enable the feature and provide UI elements.
As part of the move, the repo method was converted to a module
function. It doesn't need to exist on repos.
An error message was also updated to reflect that an error isn't
necessarily from the .hg/sparse file. The API should be updated
later to pass in a filename so the error can be more descriptive.
Copyright of the added file was copied from the sparse extension.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 06 Jul 2017 12:14:03 -0700 |
parents | |
children | f41a99c45956 |
comparison
equal
deleted
inserted
replaced
33296:ee616196227c | 33297:ba5d89774db6 |
---|---|
1 # sparse.py - functionality for sparse checkouts | |
2 # | |
3 # Copyright 2014 Facebook, Inc. | |
4 # | |
5 # This software may be used and distributed according to the terms of the | |
6 # GNU General Public License version 2 or any later version. | |
7 | |
8 from __future__ import absolute_import | |
9 | |
10 from .i18n import _ | |
11 from . import ( | |
12 error, | |
13 ) | |
14 | |
15 def parseconfig(ui, raw): | |
16 """Parse sparse config file content. | |
17 | |
18 Returns a tuple of includes, excludes, and profiles. | |
19 """ | |
20 includes = set() | |
21 excludes = set() | |
22 current = includes | |
23 profiles = [] | |
24 for line in raw.split('\n'): | |
25 line = line.strip() | |
26 if not line or line.startswith('#'): | |
27 # empty or comment line, skip | |
28 continue | |
29 elif line.startswith('%include '): | |
30 line = line[9:].strip() | |
31 if line: | |
32 profiles.append(line) | |
33 elif line == '[include]': | |
34 if current != includes: | |
35 # TODO pass filename into this API so we can report it. | |
36 raise error.Abort(_('sparse config cannot have includes ' + | |
37 'after excludes')) | |
38 continue | |
39 elif line == '[exclude]': | |
40 current = excludes | |
41 elif line: | |
42 if line.strip().startswith('/'): | |
43 ui.warn(_('warning: sparse profile cannot use' + | |
44 ' paths starting with /, ignoring %s\n') % line) | |
45 continue | |
46 current.add(line) | |
47 | |
48 return includes, excludes, profiles |