annotate mercurial/sparse.py @ 33299:41448fc51510

sparse: variable to track if sparse is enabled Currently, the sparse extension sniffs repo instances for attributes defined by the sparse extension to determine if sparse is enabled. As we move code away from repo instances, these checks will be a bit more brittle. We introduce a module-level variable to track whether sparse is enabled as a temporary workaround.
author Gregory Szorc <gregory.szorc@gmail.com>
date Thu, 06 Jul 2017 12:06:37 -0700
parents f41a99c45956
children f7a106b3f089
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
33299
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
15 # Whether sparse features are enabled. This variable is intended to be
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
16 # temporary to facilitate porting sparse to core. It should eventually be
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
17 # a per-repo option, possibly a repo requirement.
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
18 enabled = False
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
19
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
20 def parseconfig(ui, raw):
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
21 """Parse sparse config file content.
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
22
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
23 Returns a tuple of includes, excludes, and profiles.
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
24 """
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
25 includes = set()
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
26 excludes = set()
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
27 current = includes
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
28 profiles = []
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
29 for line in raw.split('\n'):
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
30 line = line.strip()
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
31 if not line or line.startswith('#'):
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
32 # empty or comment line, skip
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
33 continue
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
34 elif line.startswith('%include '):
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
35 line = line[9:].strip()
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
36 if line:
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
37 profiles.append(line)
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
38 elif line == '[include]':
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
39 if current != includes:
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
40 # 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
41 raise error.Abort(_('sparse config cannot have includes ' +
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
42 'after excludes'))
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
43 continue
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
44 elif line == '[exclude]':
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
45 current = excludes
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
46 elif line:
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
47 if line.strip().startswith('/'):
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
48 ui.warn(_('warning: sparse profile cannot use' +
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
49 ' paths starting with /, ignoring %s\n') % line)
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
50 continue
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
51 current.add(line)
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
52
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
53 return includes, excludes, profiles
33298
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
54
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
55 # Exists as separate function to facilitate monkeypatching.
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
56 def readprofile(repo, profile, changeid):
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
57 """Resolve the raw content of a sparse profile file."""
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
58 # TODO add some kind of cache here because this incurs a manifest
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
59 # resolve and can be slow.
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
60 return repo.filectx(profile, changeid=changeid).data()