Mercurial > hg
annotate 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 |
rev | line source |
---|---|
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # sparse.py - functionality for sparse checkouts |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2014 Facebook, Inc. |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 from .i18n import _ |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 from . import ( |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 error, |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 ) |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 def parseconfig(ui, raw): |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 """Parse sparse config file content. |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 Returns a tuple of includes, excludes, and profiles. |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 """ |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 includes = set() |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 excludes = set() |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 current = includes |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 profiles = [] |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 for line in raw.split('\n'): |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 line = line.strip() |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 if not line or line.startswith('#'): |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 # empty or comment line, skip |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 continue |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 elif line.startswith('%include '): |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 line = line[9:].strip() |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 if line: |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 profiles.append(line) |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 elif line == '[include]': |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 if current != includes: |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 # TODO pass filename into this API so we can report it. |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 raise error.Abort(_('sparse config cannot have includes ' + |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 'after excludes')) |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 continue |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 elif line == '[exclude]': |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 current = excludes |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 elif line: |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 if line.strip().startswith('/'): |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 ui.warn(_('warning: sparse profile cannot use' + |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 ' paths starting with /, ignoring %s\n') % line) |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 continue |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 current.add(line) |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 return includes, excludes, profiles |