annotate mercurial/sparse.py @ 42430:5b217451a2c2

py3: fix test-bookmarks-corner-case.t For some reasons, the output of print was not going through. Replaced that ui.status(). Differential Revision: https://phab.mercurial-scm.org/D6481
author Pulkit Goyal <pulkit@yandex-team.ru>
date Wed, 05 Jun 2019 22:09:26 +0300
parents aaad36b88298
children 87a34c767384
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
33317
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
10 import hashlib
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
11 import os
33317
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
12
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
13 from .i18n import _
35582
72b91f905065 py3: use node.hex(h.digest()) instead of h.hexdigest()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34548
diff changeset
14 from .node import (
72b91f905065 py3: use node.hex(h.digest()) instead of h.hexdigest()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34548
diff changeset
15 hex,
72b91f905065 py3: use node.hex(h.digest()) instead of h.hexdigest()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34548
diff changeset
16 nullid,
72b91f905065 py3: use node.hex(h.digest()) instead of h.hexdigest()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34548
diff changeset
17 )
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
18 from . import (
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
19 error,
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
20 match as matchmod,
33321
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
21 merge as mergemod,
33685
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
22 pathutil,
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
23 pycompat,
33556
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
24 scmutil,
33371
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
25 util,
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
26 )
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
27
33299
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
28 # 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
29 # 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
30 # 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
31 enabled = False
41448fc51510 sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33298
diff changeset
32
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
33 def parseconfig(ui, raw, action):
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
34 """Parse sparse config file content.
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
35
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
36 action is the command which is trigerring this read, can be narrow, sparse
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
37
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
38 Returns a tuple of includes, excludes, and profiles.
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
39 """
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
40 includes = set()
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
41 excludes = set()
33550
32f348d741e5 sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33499
diff changeset
42 profiles = set()
33551
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
43 current = None
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
44 havesection = False
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
45
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
46 for line in raw.split('\n'):
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
47 line = line.strip()
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
48 if not line or line.startswith('#'):
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
49 # empty or comment line, skip
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 elif line.startswith('%include '):
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
52 line = line[9:].strip()
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
53 if line:
33550
32f348d741e5 sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33499
diff changeset
54 profiles.add(line)
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
55 elif line == '[include]':
33551
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
56 if havesection and current != includes:
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
57 # TODO pass filename into this API so we can report it.
38862
1ff45c518e6f sparse: use named parameters in i18n strings
Yuya Nishihara <yuya@tcha.org>
parents: 38861
diff changeset
58 raise error.Abort(_('%(action)s config cannot have includes '
1ff45c518e6f sparse: use named parameters in i18n strings
Yuya Nishihara <yuya@tcha.org>
parents: 38861
diff changeset
59 'after excludes') % {'action': action})
33551
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
60 havesection = True
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
61 current = includes
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
62 continue
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
63 elif line == '[exclude]':
33551
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
64 havesection = True
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
65 current = excludes
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
66 elif line:
33551
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
67 if current is None:
38862
1ff45c518e6f sparse: use named parameters in i18n strings
Yuya Nishihara <yuya@tcha.org>
parents: 38861
diff changeset
68 raise error.Abort(_('%(action)s config entry outside of '
1ff45c518e6f sparse: use named parameters in i18n strings
Yuya Nishihara <yuya@tcha.org>
parents: 38861
diff changeset
69 'section: %(line)s')
1ff45c518e6f sparse: use named parameters in i18n strings
Yuya Nishihara <yuya@tcha.org>
parents: 38861
diff changeset
70 % {'action': action, 'line': line},
33551
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
71 hint=_('add an [include] or [exclude] line '
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
72 'to declare the entry type'))
1d1779734c99 sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33550
diff changeset
73
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
74 if line.strip().startswith('/'):
38862
1ff45c518e6f sparse: use named parameters in i18n strings
Yuya Nishihara <yuya@tcha.org>
parents: 38861
diff changeset
75 ui.warn(_('warning: %(action)s profile cannot use'
1ff45c518e6f sparse: use named parameters in i18n strings
Yuya Nishihara <yuya@tcha.org>
parents: 38861
diff changeset
76 ' paths starting with /, ignoring %(line)s\n')
1ff45c518e6f sparse: use named parameters in i18n strings
Yuya Nishihara <yuya@tcha.org>
parents: 38861
diff changeset
77 % {'action': action, 'line': line})
33297
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
78 continue
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
79 current.add(line)
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
80
ba5d89774db6 sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
81 return includes, excludes, profiles
33298
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
82
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
83 # Exists as separate function to facilitate monkeypatching.
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
84 def readprofile(repo, profile, changeid):
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
85 """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
86 # 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
87 # resolve and can be slow.
f41a99c45956 sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33297
diff changeset
88 return repo.filectx(profile, changeid=changeid).data()
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
89
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
90 def patternsforrev(repo, rev):
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
91 """Obtain sparse checkout patterns for the given rev.
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
92
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
93 Returns a tuple of iterables representing includes, excludes, and
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
94 patterns.
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
95 """
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
96 # Feature isn't enabled. No-op.
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
97 if not enabled:
33550
32f348d741e5 sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33499
diff changeset
98 return set(), set(), set()
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
99
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
100 raw = repo.vfs.tryread('sparse')
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
101 if not raw:
33550
32f348d741e5 sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33499
diff changeset
102 return set(), set(), set()
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
103
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
104 if rev is None:
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
105 raise error.Abort(_('cannot parse sparse patterns from working '
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
106 'directory'))
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
107
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
108 includes, excludes, profiles = parseconfig(repo.ui, raw, 'sparse')
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
109 ctx = repo[rev]
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
110
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
111 if profiles:
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
112 visited = set()
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
113 while profiles:
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
114 profile = profiles.pop()
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
115 if profile in visited:
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
116 continue
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
117
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
118 visited.add(profile)
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
119
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
120 try:
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
121 raw = readprofile(repo, profile, rev)
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
122 except error.ManifestLookupError:
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
123 msg = (
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
124 "warning: sparse profile '%s' not found "
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
125 "in rev %s - ignoring it\n" % (profile, ctx))
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
126 # experimental config: sparse.missingwarning
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
127 if repo.ui.configbool(
33499
0407a51b9d8c codemod: register core configitems using a script
Jun Wu <quark@fb.com>
parents: 33447
diff changeset
128 'sparse', 'missingwarning'):
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
129 repo.ui.warn(msg)
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
130 else:
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
131 repo.ui.debug(msg)
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
132 continue
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
133
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
134 pincludes, pexcludes, subprofs = parseconfig(repo.ui, raw, 'sparse')
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
135 includes.update(pincludes)
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
136 excludes.update(pexcludes)
33550
32f348d741e5 sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33499
diff changeset
137 profiles.update(subprofs)
33300
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
138
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
139 profiles = visited
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
140
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
141 if includes:
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
142 includes.add('.hg*')
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
143
f7a106b3f089 sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33299
diff changeset
144 return includes, excludes, profiles
33301
ca4b78eb11e7 sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33300
diff changeset
145
33370
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
146 def activeconfig(repo):
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
147 """Determine the active sparse config rules.
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
148
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
149 Rules are constructed by reading the current sparse config and bringing in
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
150 referenced profiles from parents of the working directory.
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
151 """
33301
ca4b78eb11e7 sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33300
diff changeset
152 revs = [repo.changelog.rev(node) for node in
ca4b78eb11e7 sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33300
diff changeset
153 repo.dirstate.parents() if node != nullid]
ca4b78eb11e7 sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33300
diff changeset
154
33370
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
155 allincludes = set()
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
156 allexcludes = set()
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
157 allprofiles = set()
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
158
33301
ca4b78eb11e7 sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33300
diff changeset
159 for rev in revs:
33370
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
160 includes, excludes, profiles = patternsforrev(repo, rev)
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
161 allincludes |= includes
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
162 allexcludes |= excludes
33550
32f348d741e5 sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33499
diff changeset
163 allprofiles |= profiles
33301
ca4b78eb11e7 sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33300
diff changeset
164
33370
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
165 return allincludes, allexcludes, allprofiles
33302
36a415b5a4b2 localrepo: add sparse caches
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33301
diff changeset
166
33317
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
167 def configsignature(repo, includetemp=True):
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
168 """Obtain the signature string for the current sparse configuration.
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
169
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
170 This is used to construct a cache key for matchers.
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
171 """
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
172 cache = repo._sparsesignaturecache
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
173
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
174 signature = cache.get('signature')
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
175
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
176 if includetemp:
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
177 tempsignature = cache.get('tempsignature')
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
178 else:
33318
526255fe7899 sparse: clean up config signature code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33317
diff changeset
179 tempsignature = '0'
33317
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
180
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
181 if signature is None or (includetemp and tempsignature is None):
35582
72b91f905065 py3: use node.hex(h.digest()) instead of h.hexdigest()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34548
diff changeset
182 signature = hex(hashlib.sha1(repo.vfs.tryread('sparse')).digest())
33317
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
183 cache['signature'] = signature
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
184
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
185 if includetemp:
33318
526255fe7899 sparse: clean up config signature code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33317
diff changeset
186 raw = repo.vfs.tryread('tempsparse')
35582
72b91f905065 py3: use node.hex(h.digest()) instead of h.hexdigest()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34548
diff changeset
187 tempsignature = hex(hashlib.sha1(raw).digest())
33317
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
188 cache['tempsignature'] = tempsignature
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
189
33318
526255fe7899 sparse: clean up config signature code
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33317
diff changeset
190 return '%s %s' % (signature, tempsignature)
33317
df1287268cc0 sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33304
diff changeset
191
33303
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
192 def writeconfig(repo, includes, excludes, profiles):
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
193 """Write the sparse config file given a sparse configuration."""
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
194 with repo.vfs('sparse', 'wb') as fh:
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
195 for p in sorted(profiles):
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
196 fh.write('%%include %s\n' % p)
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
197
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
198 if includes:
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
199 fh.write('[include]\n')
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
200 for i in sorted(includes):
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
201 fh.write(i)
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
202 fh.write('\n')
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
203
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
204 if excludes:
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
205 fh.write('[exclude]\n')
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
206 for e in sorted(excludes):
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
207 fh.write(e)
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
208 fh.write('\n')
8b571495d811 sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33302
diff changeset
209
33325
38df146d0697 sparse: inline signature cache clearing
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33324
diff changeset
210 repo._sparsesignaturecache.clear()
33304
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
211
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
212 def readtemporaryincludes(repo):
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
213 raw = repo.vfs.tryread('tempsparse')
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
214 if not raw:
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
215 return set()
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
216
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
217 return set(raw.split('\n'))
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
218
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
219 def writetemporaryincludes(repo, includes):
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
220 repo.vfs.write('tempsparse', '\n'.join(sorted(includes)))
33325
38df146d0697 sparse: inline signature cache clearing
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33324
diff changeset
221 repo._sparsesignaturecache.clear()
33304
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
222
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
223 def addtemporaryincludes(repo, additional):
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
224 includes = readtemporaryincludes(repo)
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
225 for i in additional:
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
226 includes.add(i)
3e1accab7447 sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33303
diff changeset
227 writetemporaryincludes(repo, includes)
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
228
33321
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
229 def prunetemporaryincludes(repo):
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
230 if not enabled or not repo.vfs.exists('tempsparse'):
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
231 return
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
232
33356
ccb3e5399921 sparse: access status fields by name instead of deconstructing it
Martin von Zweigbergk <martinvonz@google.com>
parents: 33355
diff changeset
233 s = repo.status()
ccb3e5399921 sparse: access status fields by name instead of deconstructing it
Martin von Zweigbergk <martinvonz@google.com>
parents: 33355
diff changeset
234 if s.modified or s.added or s.removed or s.deleted:
33321
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
235 # Still have pending changes. Don't bother trying to prune.
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
236 return
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
237
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
238 sparsematch = matcher(repo, includetemp=False)
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
239 dirstate = repo.dirstate
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
240 actions = []
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
241 dropped = []
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
242 tempincludes = readtemporaryincludes(repo)
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
243 for file in tempincludes:
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
244 if file in dirstate and not sparsematch(file):
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
245 message = _('dropping temporarily included sparse files')
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
246 actions.append((file, None, message))
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
247 dropped.append(file)
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
248
41039
54c3b4bd01f2 merge: extract helper for creating empty "actions" dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 39527
diff changeset
249 typeactions = mergemod.emptyactions()
33321
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
250 typeactions['r'] = actions
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
251 mergemod.applyupdates(repo, typeactions, repo[None], repo['.'], False)
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
252
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
253 # Fix dirstate
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
254 for file in dropped:
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
255 dirstate.drop(file)
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
256
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
257 repo.vfs.unlink('tempsparse')
33325
38df146d0697 sparse: inline signature cache clearing
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33324
diff changeset
258 repo._sparsesignaturecache.clear()
33321
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
259 msg = _('cleaned up %d temporarily added file(s) from the '
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
260 'sparse checkout\n')
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
261 repo.ui.status(msg % len(tempincludes))
d09e948dc303 sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33320
diff changeset
262
33447
6f4e5e5940a5 match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 33376
diff changeset
263 def forceincludematcher(matcher, includes):
6f4e5e5940a5 match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 33376
diff changeset
264 """Returns a matcher that returns true for any of the forced includes
6f4e5e5940a5 match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 33376
diff changeset
265 before testing against the actual matcher."""
6f4e5e5940a5 match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 33376
diff changeset
266 kindpats = [('path', include, '') for include in includes]
41675
ddbebce94665 match: delete unused root and cwd arguments to constructors (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41397
diff changeset
267 includematcher = matchmod.includematcher('', kindpats)
33447
6f4e5e5940a5 match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 33376
diff changeset
268 return matchmod.unionmatcher([includematcher, matcher])
6f4e5e5940a5 match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 33376
diff changeset
269
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
270 def matcher(repo, revs=None, includetemp=True):
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
271 """Obtain a matcher for sparse working directories for the given revs.
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
272
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
273 If multiple revisions are specified, the matcher is the union of all
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
274 revs.
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
275
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
276 ``includetemp`` indicates whether to use the temporary sparse profile.
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
277 """
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
278 # If sparse isn't enabled, sparse matcher matches everything.
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
279 if not enabled:
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41675
diff changeset
280 return matchmod.always()
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
281
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
282 if not revs or revs == [None]:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
283 revs = [repo.changelog.rev(node)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
284 for node in repo.dirstate.parents() if node != nullid]
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
285
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
286 signature = configsignature(repo, includetemp=includetemp)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
287
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
288 key = '%s %s' % (signature, ' '.join(map(pycompat.bytestr, revs)))
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
289
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
290 result = repo._sparsematchercache.get(key)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
291 if result:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
292 return result
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
293
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
294 matchers = []
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
295 for rev in revs:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
296 try:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
297 includes, excludes, profiles = patternsforrev(repo, rev)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
298
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
299 if includes or excludes:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
300 matcher = matchmod.match(repo.root, '', [],
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
301 include=includes, exclude=excludes,
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
302 default='relpath')
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
303 matchers.append(matcher)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
304 except IOError:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
305 pass
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
306
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
307 if not matchers:
41676
0531dff73d0b match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41675
diff changeset
308 result = matchmod.always()
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
309 elif len(matchers) == 1:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
310 result = matchers[0]
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
311 else:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
312 result = matchmod.unionmatcher(matchers)
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
313
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
314 if includetemp:
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
315 tempincludes = readtemporaryincludes(repo)
33447
6f4e5e5940a5 match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents: 33376
diff changeset
316 result = forceincludematcher(result, tempincludes)
33320
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
317
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
318 repo._sparsematchercache[key] = result
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
319
153456f02426 sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33318
diff changeset
320 return result
33322
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
321
33323
252500520d60 sparse: refactor update actions filtering and call from core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33322
diff changeset
322 def filterupdatesactions(repo, wctx, mctx, branchmerge, actions):
252500520d60 sparse: refactor update actions filtering and call from core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33322
diff changeset
323 """Filter updates to only lay out files that match the sparse rules."""
252500520d60 sparse: refactor update actions filtering and call from core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33322
diff changeset
324 if not enabled:
252500520d60 sparse: refactor update actions filtering and call from core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33322
diff changeset
325 return actions
33322
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
326
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
327 oldrevs = [pctx.rev() for pctx in wctx.parents()]
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
328 oldsparsematch = matcher(repo, oldrevs)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
329
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
330 if oldsparsematch.always():
33323
252500520d60 sparse: refactor update actions filtering and call from core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33322
diff changeset
331 return actions
33322
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
332
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
333 files = set()
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
334 prunedactions = {}
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
335
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
336 if branchmerge:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
337 # If we're merging, use the wctx filter, since we're merging into
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
338 # the wctx.
41397
0bd56c291359 cleanup: use p1() and p2() instead of parents()[0] and parents()[1]
Martin von Zweigbergk <martinvonz@google.com>
parents: 41039
diff changeset
339 sparsematch = matcher(repo, [wctx.p1().rev()])
33322
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
340 else:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
341 # If we're updating, use the target context's filter, since we're
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
342 # moving to the target context.
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
343 sparsematch = matcher(repo, [mctx.rev()])
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
344
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
345 temporaryfiles = []
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
346 for file, action in actions.iteritems():
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
347 type, args, msg = action
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
348 files.add(file)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
349 if sparsematch(file):
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
350 prunedactions[file] = action
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
351 elif type == 'm':
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
352 temporaryfiles.append(file)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
353 prunedactions[file] = action
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
354 elif branchmerge:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
355 if type != 'k':
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
356 temporaryfiles.append(file)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
357 prunedactions[file] = action
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
358 elif type == 'f':
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
359 prunedactions[file] = action
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
360 elif file in wctx:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
361 prunedactions[file] = ('r', args, msg)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
362
39527
9db856446298 sparse: add local files to temporaryfiles if they exist out of sparse
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38862
diff changeset
363 if branchmerge and type == mergemod.ACTION_MERGE:
9db856446298 sparse: add local files to temporaryfiles if they exist out of sparse
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38862
diff changeset
364 f1, f2, fa, move, anc = args
9db856446298 sparse: add local files to temporaryfiles if they exist out of sparse
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38862
diff changeset
365 if not sparsematch(f1):
9db856446298 sparse: add local files to temporaryfiles if they exist out of sparse
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38862
diff changeset
366 temporaryfiles.append(f1)
9db856446298 sparse: add local files to temporaryfiles if they exist out of sparse
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 38862
diff changeset
367
33322
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
368 if len(temporaryfiles) > 0:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
369 repo.ui.status(_('temporarily included %d file(s) in the sparse '
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
370 'checkout for merging\n') % len(temporaryfiles))
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
371 addtemporaryincludes(repo, temporaryfiles)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
372
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
373 # Add the new files to the working copy so they can be merged, etc
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
374 actions = []
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
375 message = 'temporarily adding to sparse checkout'
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
376 wctxmanifest = repo[None].manifest()
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
377 for file in temporaryfiles:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
378 if file in wctxmanifest:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
379 fctx = repo[None][file]
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
380 actions.append((file, (fctx.flags(), False), message))
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
381
41039
54c3b4bd01f2 merge: extract helper for creating empty "actions" dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 39527
diff changeset
382 typeactions = mergemod.emptyactions()
33322
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
383 typeactions['g'] = actions
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
384 mergemod.applyupdates(repo, typeactions, repo[None], repo['.'],
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
385 False)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
386
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
387 dirstate = repo.dirstate
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
388 for file, flags, msg in actions:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
389 dirstate.normal(file)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
390
33370
482320104672 sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33356
diff changeset
391 profiles = activeconfig(repo)[2]
33322
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
392 changedprofiles = profiles & files
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
393 # If an active profile changed during the update, refresh the checkout.
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
394 # Don't do this during a branch merge, since all incoming changes should
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
395 # have been handled by the temporary includes above.
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
396 if changedprofiles and not branchmerge:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
397 mf = mctx.manifest()
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
398 for file in mf:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
399 old = oldsparsematch(file)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
400 new = sparsematch(file)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
401 if not old and new:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
402 flags = mf.flags(file)
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
403 prunedactions[file] = ('g', (flags, False), '')
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
404 elif old and not new:
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
405 prunedactions[file] = ('r', [], '')
fa6c2c3064fd sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33321
diff changeset
406
33323
252500520d60 sparse: refactor update actions filtering and call from core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33322
diff changeset
407 return prunedactions
33324
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
408
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
409 def refreshwdir(repo, origstatus, origsparsematch, force=False):
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
410 """Refreshes working directory by taking sparse config into account.
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
411
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
412 The old status and sparse matcher is compared against the current sparse
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
413 matcher.
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
414
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
415 Will abort if a file with pending changes is being excluded or included
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
416 unless ``force`` is True.
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
417 """
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
418 # Verify there are no pending changes
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
419 pending = set()
33356
ccb3e5399921 sparse: access status fields by name instead of deconstructing it
Martin von Zweigbergk <martinvonz@google.com>
parents: 33355
diff changeset
420 pending.update(origstatus.modified)
ccb3e5399921 sparse: access status fields by name instead of deconstructing it
Martin von Zweigbergk <martinvonz@google.com>
parents: 33355
diff changeset
421 pending.update(origstatus.added)
ccb3e5399921 sparse: access status fields by name instead of deconstructing it
Martin von Zweigbergk <martinvonz@google.com>
parents: 33355
diff changeset
422 pending.update(origstatus.removed)
33324
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
423 sparsematch = matcher(repo)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
424 abort = False
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
425
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
426 for f in pending:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
427 if not sparsematch(f):
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
428 repo.ui.warn(_("pending changes to '%s'\n") % f)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
429 abort = not force
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
430
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
431 if abort:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
432 raise error.Abort(_('could not update sparseness due to pending '
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
433 'changes'))
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
434
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
435 # Calculate actions
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
436 dirstate = repo.dirstate
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
437 ctx = repo['.']
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
438 added = []
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
439 lookup = []
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
440 dropped = []
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
441 mf = ctx.manifest()
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
442 files = set(mf)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
443
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
444 actions = {}
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
445
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
446 for file in files:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
447 old = origsparsematch(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
448 new = sparsematch(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
449 # Add files that are newly included, or that don't exist in
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
450 # the dirstate yet.
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
451 if (new and not old) or (old and new and not file in dirstate):
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
452 fl = mf.flags(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
453 if repo.wvfs.exists(file):
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
454 actions[file] = ('e', (fl,), '')
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
455 lookup.append(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
456 else:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
457 actions[file] = ('g', (fl, False), '')
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
458 added.append(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
459 # Drop files that are newly excluded, or that still exist in
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
460 # the dirstate.
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
461 elif (old and not new) or (not old and not new and file in dirstate):
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
462 dropped.append(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
463 if file not in pending:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
464 actions[file] = ('r', [], '')
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
465
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
466 # Verify there are no pending changes in newly included files
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
467 abort = False
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
468 for file in lookup:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
469 repo.ui.warn(_("pending changes to '%s'\n") % file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
470 abort = not force
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
471 if abort:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
472 raise error.Abort(_('cannot change sparseness due to pending '
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
473 'changes (delete the files or use '
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
474 '--force to bring them back dirty)'))
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
475
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
476 # Check for files that were only in the dirstate.
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
477 for file, state in dirstate.iteritems():
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
478 if not file in files:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
479 old = origsparsematch(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
480 new = sparsematch(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
481 if old and not new:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
482 dropped.append(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
483
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
484 # Apply changes to disk
41039
54c3b4bd01f2 merge: extract helper for creating empty "actions" dict
Martin von Zweigbergk <martinvonz@google.com>
parents: 39527
diff changeset
485 typeactions = mergemod.emptyactions()
33324
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
486 for f, (m, args, msg) in actions.iteritems():
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
487 typeactions[m].append((f, args, msg))
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
488
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
489 mergemod.applyupdates(repo, typeactions, repo[None], repo['.'], False)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
490
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
491 # Fix dirstate
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
492 for file in added:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
493 dirstate.normal(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
494
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
495 for file in dropped:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
496 dirstate.drop(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
497
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
498 for file in lookup:
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
499 # File exists on disk, and we're bringing it back in an unknown state.
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
500 dirstate.normallookup(file)
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
501
33d0859c37bd sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33323
diff changeset
502 return added, dropped, lookup
33353
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
503
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
504 def aftercommit(repo, node):
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
505 """Perform actions after a working directory commit."""
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
506 # This function is called unconditionally, even if sparse isn't
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
507 # enabled.
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
508 ctx = repo[node]
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
509
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
510 profiles = patternsforrev(repo, ctx.rev())[2]
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
511
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
512 # profiles will only have data if sparse is enabled.
33550
32f348d741e5 sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33499
diff changeset
513 if profiles & set(ctx.files()):
33353
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
514 origstatus = repo.status()
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
515 origsparsematch = matcher(repo)
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
516 refreshwdir(repo, origstatus, origsparsematch, force=True)
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
517
160efb559f67 sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33325
diff changeset
518 prunetemporaryincludes(repo)
33354
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
519
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
520 def _updateconfigandrefreshwdir(repo, includes, excludes, profiles,
33556
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
521 force=False, removing=False):
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
522 """Update the sparse config and working directory state."""
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
523 raw = repo.vfs.tryread('sparse')
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
524 oldincludes, oldexcludes, oldprofiles = parseconfig(repo.ui, raw, 'sparse')
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
525
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
526 oldstatus = repo.status()
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
527 oldmatch = matcher(repo)
33556
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
528 oldrequires = set(repo.requirements)
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
529
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
530 # TODO remove this try..except once the matcher integrates better
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
531 # with dirstate. We currently have to write the updated config
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
532 # because that will invalidate the matcher cache and force a
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
533 # re-read. We ideally want to update the cached matcher on the
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
534 # repo instance then flush the new config to disk once wdir is
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
535 # updated. But this requires massive rework to matcher() and its
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
536 # consumers.
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
537
33556
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
538 if 'exp-sparse' in oldrequires and removing:
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
539 repo.requirements.discard('exp-sparse')
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
540 scmutil.writerequires(repo.vfs, repo.requirements)
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
541 elif 'exp-sparse' not in oldrequires:
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
542 repo.requirements.add('exp-sparse')
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
543 scmutil.writerequires(repo.vfs, repo.requirements)
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
544
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
545 try:
33556
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
546 writeconfig(repo, includes, excludes, profiles)
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
547 return refreshwdir(repo, oldstatus, oldmatch, force=force)
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
548 except Exception:
33556
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
549 if repo.requirements != oldrequires:
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
550 repo.requirements.clear()
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
551 repo.requirements |= oldrequires
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
552 scmutil.writerequires(repo.vfs, repo.requirements)
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
553 writeconfig(repo, oldincludes, oldexcludes, oldprofiles)
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
554 raise
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
555
33354
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
556 def clearrules(repo, force=False):
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
557 """Clears include/exclude rules from the sparse config.
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
558
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
559 The remaining sparse config only has profiles, if defined. The working
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
560 directory is refreshed, as needed.
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
561 """
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
562 with repo.wlock():
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
563 raw = repo.vfs.tryread('sparse')
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
564 includes, excludes, profiles = parseconfig(repo.ui, raw, 'sparse')
33354
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
565
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
566 if not includes and not excludes:
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
567 return
4695f1829045 sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33353
diff changeset
568
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
569 _updateconfigandrefreshwdir(repo, set(), set(), profiles, force=force)
33355
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
570
33371
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
571 def importfromfiles(repo, opts, paths, force=False):
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
572 """Import sparse config rules from files.
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
573
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
574 The updated sparse config is written out and the working directory
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
575 is refreshed, as needed.
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
576 """
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
577 with repo.wlock():
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
578 # read current configuration
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
579 raw = repo.vfs.tryread('sparse')
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
580 includes, excludes, profiles = parseconfig(repo.ui, raw, 'sparse')
33371
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
581 aincludes, aexcludes, aprofiles = activeconfig(repo)
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
582
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
583 # Import rules on top; only take in rules that are not yet
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
584 # part of the active rules.
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
585 changed = False
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
586 for p in paths:
37576
6ef94f24aa82 py3: make sure we open file in bytes mode
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35742
diff changeset
587 with util.posixfile(util.expandpath(p), mode='rb') as fh:
33371
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
588 raw = fh.read()
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
589
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
590 iincludes, iexcludes, iprofiles = parseconfig(repo.ui, raw,
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
591 'sparse')
33371
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
592 oldsize = len(includes) + len(excludes) + len(profiles)
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
593 includes.update(iincludes - aincludes)
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
594 excludes.update(iexcludes - aexcludes)
33550
32f348d741e5 sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33499
diff changeset
595 profiles.update(iprofiles - aprofiles)
33371
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
596 if len(includes) + len(excludes) + len(profiles) > oldsize:
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
597 changed = True
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
598
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
599 profilecount = includecount = excludecount = 0
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
600 fcounts = (0, 0, 0)
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
601
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
602 if changed:
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
603 profilecount = len(profiles - aprofiles)
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
604 includecount = len(includes - aincludes)
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
605 excludecount = len(excludes - aexcludes)
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
606
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
607 fcounts = map(len, _updateconfigandrefreshwdir(
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
608 repo, includes, excludes, profiles, force=force))
33371
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
609
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
610 printchanges(repo.ui, opts, profilecount, includecount, excludecount,
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
611 *fcounts)
c6415195fa78 sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33370
diff changeset
612
33374
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
613 def updateconfig(repo, pats, opts, include=False, exclude=False, reset=False,
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
614 delete=False, enableprofile=False, disableprofile=False,
33685
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
615 force=False, usereporootpaths=False):
33374
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
616 """Perform a sparse config update.
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
617
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
618 Only one of the actions may be performed.
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
619
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
620 The new config is written out and a working directory refresh is performed.
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
621 """
33375
df6dd6d536bb sparse: clean up updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33374
diff changeset
622 with repo.wlock():
33374
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
623 raw = repo.vfs.tryread('sparse')
38838
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
624 oldinclude, oldexclude, oldprofiles = parseconfig(repo.ui, raw,
8fe62ad9f4ff sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 37576
diff changeset
625 'sparse')
33374
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
626
33376
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
627 if reset:
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
628 newinclude = set()
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
629 newexclude = set()
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
630 newprofiles = set()
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
631 else:
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
632 newinclude = set(oldinclude)
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
633 newexclude = set(oldexclude)
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
634 newprofiles = set(oldprofiles)
33374
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
635
33683
7dcb517122f9 sparse: properly error out when absolute paths are used
Kostia Balytskyi <ikostia@fb.com>
parents: 33556
diff changeset
636 if any(os.path.isabs(pat) for pat in pats):
7dcb517122f9 sparse: properly error out when absolute paths are used
Kostia Balytskyi <ikostia@fb.com>
parents: 33556
diff changeset
637 raise error.Abort(_('paths cannot be absolute'))
7dcb517122f9 sparse: properly error out when absolute paths are used
Kostia Balytskyi <ikostia@fb.com>
parents: 33556
diff changeset
638
33685
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
639 if not usereporootpaths:
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
640 # let's treat paths as relative to cwd
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
641 root, cwd = repo.root, repo.getcwd()
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
642 abspats = []
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
643 for kindpat in pats:
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
644 kind, pat = matchmod._patsplit(kindpat, None)
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
645 if kind in matchmod.cwdrelativepatternkinds or kind is None:
41759
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
646 ap = ((kind + ':' if kind else '') +
aaad36b88298 cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents: 41676
diff changeset
647 pathutil.canonpath(root, cwd, pat))
33685
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
648 abspats.append(ap)
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
649 else:
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
650 abspats.append(kindpat)
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
651 pats = abspats
e1c56486d1aa sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents: 33683
diff changeset
652
33683
7dcb517122f9 sparse: properly error out when absolute paths are used
Kostia Balytskyi <ikostia@fb.com>
parents: 33556
diff changeset
653 if include:
33376
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
654 newinclude.update(pats)
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
655 elif exclude:
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
656 newexclude.update(pats)
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
657 elif enableprofile:
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
658 newprofiles.update(pats)
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
659 elif disableprofile:
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
660 newprofiles.difference_update(pats)
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
661 elif delete:
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
662 newinclude.difference_update(pats)
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
663 newexclude.difference_update(pats)
33374
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
664
33376
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
665 profilecount = (len(newprofiles - oldprofiles) -
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
666 len(oldprofiles - newprofiles))
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
667 includecount = (len(newinclude - oldinclude) -
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
668 len(oldinclude - newinclude))
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
669 excludecount = (len(newexclude - oldexclude) -
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
670 len(oldexclude - newexclude))
33374
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
671
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
672 fcounts = map(len, _updateconfigandrefreshwdir(
33556
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
673 repo, newinclude, newexclude, newprofiles, force=force,
22371eabb3b1 sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33555
diff changeset
674 removing=reset))
33376
d5a38eae67e5 sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33375
diff changeset
675
33555
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
676 printchanges(repo.ui, opts, profilecount, includecount,
6755b719048c sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33551
diff changeset
677 excludecount, *fcounts)
33374
4dc04cdf2520 sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33371
diff changeset
678
33355
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
679 def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0,
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
680 added=0, dropped=0, conflicting=0):
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
681 """Print output summarizing sparse config changes."""
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
682 with ui.formatter('sparse', opts) as fm:
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
683 fm.startitem()
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
684 fm.condwrite(ui.verbose, 'profiles_added', _('Profiles changed: %d\n'),
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
685 profilecount)
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
686 fm.condwrite(ui.verbose, 'include_rules_added',
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
687 _('Include rules changed: %d\n'), includecount)
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
688 fm.condwrite(ui.verbose, 'exclude_rules_added',
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
689 _('Exclude rules changed: %d\n'), excludecount)
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
690
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
691 # In 'plain' verbose mode, mergemod.applyupdates already outputs what
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
692 # files are added or removed outside of the templating formatter
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
693 # framework. No point in repeating ourselves in that case.
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
694 if not fm.isplain():
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
695 fm.condwrite(ui.verbose, 'files_added', _('Files added: %d\n'),
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
696 added)
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
697 fm.condwrite(ui.verbose, 'files_dropped', _('Files dropped: %d\n'),
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
698 dropped)
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
699 fm.condwrite(ui.verbose, 'files_conflicting',
9087f9997f42 sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33354
diff changeset
700 _('Files conflicting: %d\n'), conflicting)