Mercurial > hg
annotate mercurial/sparse.py @ 51296:3972d090aba2
hgweb: update _runwsgi try/except range to be valid
The `tmpl` variable is used in the `except` and `finally`, so we need it created
before the `try` is open.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 19 Dec 2023 21:38:46 +0100 |
parents | 7a8bfc05b691 |
children | 0d7ccb163b4f |
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 |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
9 import os |
33317
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
10 |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 from .i18n import _ |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
45525
diff
changeset
|
12 from .node import hex |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 from . import ( |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 error, |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
15 match as matchmod, |
33321
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
16 merge as mergemod, |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44060
diff
changeset
|
17 mergestate as mergestatemod, |
33685
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
18 pathutil, |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
19 pycompat, |
45372
77b8588dd84e
requirements: introduce new requirements related module
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45355
diff
changeset
|
20 requirements, |
33556
22371eabb3b1
sparse: add a requirement when a repository uses sparse (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33555
diff
changeset
|
21 scmutil, |
33371
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
22 util, |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 ) |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
24 from .utils import hashutil |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 |
45355
a1f51c7dce0f
repository: introduce constant for sparse repo requirement and use it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45346
diff
changeset
|
26 |
33299
41448fc51510
sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33298
diff
changeset
|
27 # 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
|
28 # 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
|
29 # 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
|
30 enabled = False |
41448fc51510
sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33298
diff
changeset
|
31 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
32 |
49354
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
33 def use_sparse(repo): |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
34 if getattr(repo, "_has_sparse", False): |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
35 # When enabling sparse the first time we need it to be enabled before |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
36 # actually enabling it. This hack could be avoided if the code was |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
37 # improved further, however this is an improvement over the previously |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
38 # existing global variable. |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
39 return True |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
40 return requirements.SPARSE_REQUIREMENT in repo.requirements |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
41 |
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
42 |
38838
8fe62ad9f4ff
sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
37576
diff
changeset
|
43 def parseconfig(ui, raw, action): |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 """Parse sparse config file content. |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 |
38838
8fe62ad9f4ff
sparse: add an action argument to parseconfig()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
37576
diff
changeset
|
46 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
|
47 |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 Returns a tuple of includes, excludes, and profiles. |
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 """ |
48778
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
50 with util.timedcm( |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
51 'sparse.parseconfig(ui, %d bytes, action=%s)', len(raw), action |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
52 ): |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
53 includes = set() |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
54 excludes = set() |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
55 profiles = set() |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
56 current = None |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
57 havesection = False |
33551
1d1779734c99
sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33550
diff
changeset
|
58 |
48778
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
59 for line in raw.split(b'\n'): |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
60 line = line.strip() |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
61 if not line or line.startswith(b'#'): |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
62 # empty or comment line, skip |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
63 continue |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
64 elif line.startswith(b'%include '): |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
65 line = line[9:].strip() |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
66 if line: |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
67 profiles.add(line) |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
68 elif line == b'[include]': |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
69 if havesection and current != includes: |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
70 # TODO pass filename into this API so we can report it. |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
71 raise error.Abort( |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
72 _( |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
73 b'%(action)s config cannot have includes ' |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
74 b'after excludes' |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
75 ) |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
76 % {b'action': action} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
77 ) |
48778
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
78 havesection = True |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
79 current = includes |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
80 continue |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
81 elif line == b'[exclude]': |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
82 havesection = True |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
83 current = excludes |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
84 elif line: |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
85 if current is None: |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
86 raise error.Abort( |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
87 _( |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
88 b'%(action)s config entry outside of ' |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
89 b'section: %(line)s' |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
90 ) |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
91 % {b'action': action, b'line': line}, |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
92 hint=_( |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
93 b'add an [include] or [exclude] line ' |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
94 b'to declare the entry type' |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
95 ), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
96 ) |
33551
1d1779734c99
sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33550
diff
changeset
|
97 |
48778
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
98 if line.strip().startswith(b'/'): |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
99 ui.warn( |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
100 _( |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
101 b'warning: %(action)s profile cannot use' |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
102 b' paths starting with /, ignoring %(line)s\n' |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
103 ) |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
104 % {b'action': action, b'line': line} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
105 ) |
48778
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
106 continue |
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
107 current.add(line) |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 |
48778
c4149a110b5f
sparse: add timing block for parsing sparse configs
Augie Fackler <augie@google.com>
parents:
48737
diff
changeset
|
109 return includes, excludes, profiles |
33298
f41a99c45956
sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33297
diff
changeset
|
110 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
111 |
33298
f41a99c45956
sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33297
diff
changeset
|
112 # Exists as separate function to facilitate monkeypatching. |
f41a99c45956
sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33297
diff
changeset
|
113 def readprofile(repo, profile, changeid): |
f41a99c45956
sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33297
diff
changeset
|
114 """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
|
115 # 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
|
116 # resolve and can be slow. |
f41a99c45956
sparse: move profile reading into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33297
diff
changeset
|
117 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
|
118 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
119 |
33300
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
120 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
|
121 """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
|
122 |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
123 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
|
124 patterns. |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
125 """ |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
126 # Feature isn't enabled. No-op. |
49354
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
127 if not use_sparse(repo): |
33550
32f348d741e5
sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33499
diff
changeset
|
128 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
|
129 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
130 raw = repo.vfs.tryread(b'sparse') |
33300
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
131 if not raw: |
33550
32f348d741e5
sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33499
diff
changeset
|
132 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
|
133 |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
134 if rev is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
135 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
136 _(b'cannot parse sparse patterns from working directory') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
137 ) |
33300
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
138 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 includes, excludes, profiles = parseconfig(repo.ui, raw, b'sparse') |
33300
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
140 ctx = repo[rev] |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
141 |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
142 if profiles: |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
143 visited = set() |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
144 while profiles: |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
145 profile = profiles.pop() |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
146 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
|
147 continue |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
148 |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
149 visited.add(profile) |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
150 |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
151 try: |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
152 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
|
153 except error.ManifestLookupError: |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
154 msg = ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
155 b"warning: sparse profile '%s' not found " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
156 b"in rev %s - ignoring it\n" % (profile, ctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
157 ) |
33300
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
158 # experimental config: sparse.missingwarning |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
159 if repo.ui.configbool(b'sparse', b'missingwarning'): |
33300
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
160 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
|
161 else: |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
162 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
|
163 continue |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
164 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 pincludes, pexcludes, subprofs = parseconfig( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
166 repo.ui, raw, b'sparse' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
167 ) |
33300
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
168 includes.update(pincludes) |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
169 excludes.update(pexcludes) |
33550
32f348d741e5
sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33499
diff
changeset
|
170 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
|
171 |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
172 profiles = visited |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
173 |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
174 if includes: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
175 includes.add(b'.hg*') |
33300
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
176 |
f7a106b3f089
sparse: move resolving of sparse patterns for rev into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33299
diff
changeset
|
177 return includes, excludes, profiles |
33301
ca4b78eb11e7
sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33300
diff
changeset
|
178 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
179 |
33370
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
180 def activeconfig(repo): |
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
181 """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
|
182 |
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
183 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
|
184 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
|
185 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
186 revs = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
187 repo.changelog.rev(node) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
188 for node in repo.dirstate.parents() |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
45525
diff
changeset
|
189 if node != repo.nullid |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
190 ] |
33301
ca4b78eb11e7
sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33300
diff
changeset
|
191 |
33370
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
192 allincludes = set() |
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
193 allexcludes = set() |
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
194 allprofiles = set() |
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
195 |
33301
ca4b78eb11e7
sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33300
diff
changeset
|
196 for rev in revs: |
33370
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
197 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
|
198 allincludes |= includes |
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
199 allexcludes |= excludes |
33550
32f348d741e5
sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33499
diff
changeset
|
200 allprofiles |= profiles |
33301
ca4b78eb11e7
sparse: move active profiles function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33300
diff
changeset
|
201 |
33370
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
202 return allincludes, allexcludes, allprofiles |
33302
36a415b5a4b2
localrepo: add sparse caches
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33301
diff
changeset
|
203 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
204 |
33317
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
205 def configsignature(repo, includetemp=True): |
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
206 """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
|
207 |
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
208 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
|
209 """ |
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
210 cache = repo._sparsesignaturecache |
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
211 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
212 signature = cache.get(b'signature') |
33317
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
213 |
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
214 if includetemp: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
215 tempsignature = cache.get(b'tempsignature') |
33317
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
216 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
217 tempsignature = b'0' |
33317
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
218 |
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
219 if signature is None or (includetemp and tempsignature is None): |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
220 signature = hex(hashutil.sha1(repo.vfs.tryread(b'sparse')).digest()) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
221 cache[b'signature'] = signature |
33317
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
222 |
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
223 if includetemp: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
224 raw = repo.vfs.tryread(b'tempsparse') |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
225 tempsignature = hex(hashutil.sha1(raw).digest()) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
226 cache[b'tempsignature'] = tempsignature |
33317
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
227 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
228 return b'%s %s' % (signature, tempsignature) |
33317
df1287268cc0
sparse: move config signature logic into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33304
diff
changeset
|
229 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
230 |
33303
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
231 def writeconfig(repo, includes, excludes, profiles): |
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
232 """Write the sparse config file given a sparse configuration.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
233 with repo.vfs(b'sparse', b'wb') as fh: |
33303
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
234 for p in sorted(profiles): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
235 fh.write(b'%%include %s\n' % p) |
33303
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
236 |
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
237 if includes: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
238 fh.write(b'[include]\n') |
33303
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
239 for i in sorted(includes): |
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
240 fh.write(i) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
241 fh.write(b'\n') |
33303
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
242 |
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
243 if excludes: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
244 fh.write(b'[exclude]\n') |
33303
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
245 for e in sorted(excludes): |
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
246 fh.write(e) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
247 fh.write(b'\n') |
33303
8b571495d811
sparse: move config file writing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33302
diff
changeset
|
248 |
33325
38df146d0697
sparse: inline signature cache clearing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33324
diff
changeset
|
249 repo._sparsesignaturecache.clear() |
33304
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
250 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
251 |
33304
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
252 def readtemporaryincludes(repo): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
253 raw = repo.vfs.tryread(b'tempsparse') |
33304
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
254 if not raw: |
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
255 return set() |
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
256 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
257 return set(raw.split(b'\n')) |
33304
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
258 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
259 |
33304
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
260 def writetemporaryincludes(repo, includes): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
261 repo.vfs.write(b'tempsparse', b'\n'.join(sorted(includes))) |
33325
38df146d0697
sparse: inline signature cache clearing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33324
diff
changeset
|
262 repo._sparsesignaturecache.clear() |
33304
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
263 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
264 |
33304
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
265 def addtemporaryincludes(repo, additional): |
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
266 includes = readtemporaryincludes(repo) |
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
267 for i in additional: |
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
268 includes.add(i) |
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
269 writetemporaryincludes(repo, includes) |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
270 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
271 |
33321
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
272 def prunetemporaryincludes(repo): |
49354
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
273 if not use_sparse(repo) or not repo.vfs.exists(b'tempsparse'): |
33321
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
274 return |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
275 |
33356
ccb3e5399921
sparse: access status fields by name instead of deconstructing it
Martin von Zweigbergk <martinvonz@google.com>
parents:
33355
diff
changeset
|
276 s = repo.status() |
ccb3e5399921
sparse: access status fields by name instead of deconstructing it
Martin von Zweigbergk <martinvonz@google.com>
parents:
33355
diff
changeset
|
277 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
|
278 # 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
|
279 return |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
280 |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
281 sparsematch = matcher(repo, includetemp=False) |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
282 dirstate = repo.dirstate |
45334
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
283 mresult = mergemod.mergeresult() |
33321
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
284 dropped = [] |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
285 tempincludes = readtemporaryincludes(repo) |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
286 for file in tempincludes: |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
287 if file in dirstate and not sparsematch(file): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
288 message = _(b'dropping temporarily included sparse files') |
45339
9320f66854f6
sparse: replace merge action values with mergestate.ACTION_* constants
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45334
diff
changeset
|
289 mresult.addfile(file, mergestatemod.ACTION_REMOVE, None, message) |
33321
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
290 dropped.append(file) |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
291 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
292 mergemod.applyupdates( |
45334
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
293 repo, mresult, repo[None], repo[b'.'], False, wantfiledata=False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
294 ) |
33321
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
295 |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
296 # Fix dirstate |
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
297 for file in dropped: |
47748
000ea893aad3
sparse: use `update_file` instead of `drop`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47747
diff
changeset
|
298 dirstate.update_file(file, p1_tracked=False, wc_tracked=False) |
33321
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
299 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
300 repo.vfs.unlink(b'tempsparse') |
33325
38df146d0697
sparse: inline signature cache clearing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33324
diff
changeset
|
301 repo._sparsesignaturecache.clear() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
302 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
303 b'cleaned up %d temporarily added file(s) from the ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
304 b'sparse checkout\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
305 ) |
33321
d09e948dc303
sparse: move pruning of temporary includes into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33320
diff
changeset
|
306 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
|
307 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
308 |
33447
6f4e5e5940a5
match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
33376
diff
changeset
|
309 def forceincludematcher(matcher, includes): |
6f4e5e5940a5
match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
33376
diff
changeset
|
310 """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
|
311 before testing against the actual matcher.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
312 kindpats = [(b'path', include, b'') for include in includes] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
313 includematcher = matchmod.includematcher(b'', kindpats) |
33447
6f4e5e5940a5
match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
33376
diff
changeset
|
314 return matchmod.unionmatcher([includematcher, matcher]) |
6f4e5e5940a5
match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
33376
diff
changeset
|
315 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
316 |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
317 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
|
318 """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
|
319 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
320 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
|
321 revs. |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
322 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
323 ``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
|
324 """ |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
325 # If sparse isn't enabled, sparse matcher matches everything. |
49354
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
326 if not use_sparse(repo): |
41676
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41675
diff
changeset
|
327 return matchmod.always() |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
328 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
329 if not revs or revs == [None]: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
330 revs = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
331 repo.changelog.rev(node) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
332 for node in repo.dirstate.parents() |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
45525
diff
changeset
|
333 if node != repo.nullid |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
334 ] |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
335 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
336 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
|
337 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
338 key = b'%s %s' % (signature, b' '.join(map(pycompat.bytestr, revs))) |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
339 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
340 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
|
341 if result: |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
342 return result |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
343 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
344 matchers = [] |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
345 for rev in revs: |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
346 try: |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
347 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
|
348 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
349 if includes or excludes: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
350 matcher = matchmod.match( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
351 repo.root, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
352 b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
353 [], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
354 include=includes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
355 exclude=excludes, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
356 default=b'relpath', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
357 ) |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
358 matchers.append(matcher) |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
359 except IOError: |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
360 pass |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
361 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
362 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
|
363 result = matchmod.always() |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
364 elif len(matchers) == 1: |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
365 result = matchers[0] |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
366 else: |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
367 result = matchmod.unionmatcher(matchers) |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
368 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
369 if includetemp: |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
370 tempincludes = readtemporaryincludes(repo) |
33447
6f4e5e5940a5
match: write forceincludematcher using unionmatcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
33376
diff
changeset
|
371 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
|
372 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
373 repo._sparsematchercache[key] = result |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
374 |
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33318
diff
changeset
|
375 return result |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
376 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
377 |
45290
d70c972cec74
sparse: pass mergeresult obj in sparse.filterupdatesactions() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
378 def filterupdatesactions(repo, wctx, mctx, branchmerge, mresult): |
33323
252500520d60
sparse: refactor update actions filtering and call from core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33322
diff
changeset
|
379 """Filter updates to only lay out files that match the sparse rules.""" |
49354
216f273b6b30
sparse: start moving away from the global variable for detection of usage
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48913
diff
changeset
|
380 if not use_sparse(repo): |
45290
d70c972cec74
sparse: pass mergeresult obj in sparse.filterupdatesactions() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
381 return |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
382 |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
383 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
|
384 oldsparsematch = matcher(repo, oldrevs) |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
385 |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
386 if oldsparsematch.always(): |
45290
d70c972cec74
sparse: pass mergeresult obj in sparse.filterupdatesactions() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
387 return |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
388 |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
389 files = set() |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
390 prunedactions = {} |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
391 |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
392 if branchmerge: |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
393 # 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
|
394 # 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
|
395 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
|
396 else: |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
397 # 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
|
398 # moving to the target context. |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
399 sparsematch = matcher(repo, [mctx.rev()]) |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
400 |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
401 temporaryfiles = [] |
45346
3c783ff08d40
mergeresult: introduce filemap() which yields filename based mapping
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45339
diff
changeset
|
402 for file, action in mresult.filemap(): |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
403 type, args, msg = action |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
404 files.add(file) |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
405 if sparsematch(file): |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
406 prunedactions[file] = action |
45294
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
407 elif type == mergestatemod.ACTION_MERGE: |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
408 temporaryfiles.append(file) |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
409 prunedactions[file] = action |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
410 elif branchmerge: |
48713
5dfaca4464d1
merge-actions: add an explicite "no_op" attribute
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48665
diff
changeset
|
411 if not type.no_op: |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
412 temporaryfiles.append(file) |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
413 prunedactions[file] = action |
45294
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
414 elif type == mergestatemod.ACTION_FORGET: |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
415 prunedactions[file] = action |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
416 elif file in wctx: |
45294
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
417 prunedactions[file] = (mergestatemod.ACTION_REMOVE, args, msg) |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
418 |
45295
6a8eafaeff3b
sparse: add comment for an if condition which I tried to refactor
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45294
diff
changeset
|
419 # in case or rename on one side, it is possible that f1 might not |
6a8eafaeff3b
sparse: add comment for an if condition which I tried to refactor
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45294
diff
changeset
|
420 # be present in sparse checkout we should include it |
6a8eafaeff3b
sparse: add comment for an if condition which I tried to refactor
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45294
diff
changeset
|
421 # TODO: should we do the same for f2? |
6a8eafaeff3b
sparse: add comment for an if condition which I tried to refactor
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45294
diff
changeset
|
422 # exists as a separate check because file can be in sparse and hence |
6a8eafaeff3b
sparse: add comment for an if condition which I tried to refactor
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45294
diff
changeset
|
423 # if we try to club this condition in above `elif type == ACTION_MERGE` |
6a8eafaeff3b
sparse: add comment for an if condition which I tried to refactor
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45294
diff
changeset
|
424 # it won't be triggered |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44060
diff
changeset
|
425 if branchmerge and type == mergestatemod.ACTION_MERGE: |
39527
9db856446298
sparse: add local files to temporaryfiles if they exist out of sparse
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
38862
diff
changeset
|
426 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
|
427 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
|
428 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
|
429 |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
430 if len(temporaryfiles) > 0: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
431 repo.ui.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
432 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
433 b'temporarily included %d file(s) in the sparse ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
434 b'checkout for merging\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
435 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
436 % len(temporaryfiles) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
437 ) |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
438 addtemporaryincludes(repo, temporaryfiles) |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
439 |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
440 # Add the new files to the working copy so they can be merged, etc |
45334
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
441 tmresult = mergemod.mergeresult() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
442 message = b'temporarily adding to sparse checkout' |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
443 wctxmanifest = repo[None].manifest() |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
444 for file in temporaryfiles: |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
445 if file in wctxmanifest: |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
446 fctx = repo[None][file] |
45334
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
447 tmresult.addfile( |
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
448 file, |
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
449 mergestatemod.ACTION_GET, |
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
450 (fctx.flags(), False), |
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
451 message, |
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
452 ) |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
453 |
49961
7a8bfc05b691
dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49960
diff
changeset
|
454 with repo.dirstate.changing_parents(repo): |
47708
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
455 mergemod.applyupdates( |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
456 repo, |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
457 tmresult, |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
458 repo[None], |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
459 repo[b'.'], |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
460 False, |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
461 wantfiledata=False, |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
462 ) |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
463 |
47708
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
464 dirstate = repo.dirstate |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
465 for file, flags, msg in tmresult.getactions( |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
466 [mergestatemod.ACTION_GET] |
7bdfd88251c0
sparse: apply update with in a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47606
diff
changeset
|
467 ): |
47709
a0e79084389d
sparse: use `update_file` instead of `normal` during `applyupdates`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47708
diff
changeset
|
468 dirstate.update_file(file, p1_tracked=True, wc_tracked=True) |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
469 |
33370
482320104672
sparse: refactor activeprofiles into a generic function (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33356
diff
changeset
|
470 profiles = activeconfig(repo)[2] |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
471 changedprofiles = profiles & files |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
472 # 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
|
473 # 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
|
474 # 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
|
475 if changedprofiles and not branchmerge: |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
476 mf = mctx.manifest() |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
477 for file in mf: |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
478 old = oldsparsematch(file) |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
479 new = sparsematch(file) |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
480 if not old and new: |
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
481 flags = mf.flags(file) |
45294
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
482 prunedactions[file] = ( |
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
483 mergestatemod.ACTION_GET, |
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
484 (flags, False), |
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
485 b'', |
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
486 ) |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
487 elif old and not new: |
45294
30f3e278c5d7
mergeactions: use action constants instead of string values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45290
diff
changeset
|
488 prunedactions[file] = (mergestatemod.ACTION_REMOVE, [], b'') |
33322
fa6c2c3064fd
sparse: move update action filtering into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33321
diff
changeset
|
489 |
45290
d70c972cec74
sparse: pass mergeresult obj in sparse.filterupdatesactions() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
490 mresult.setactions(prunedactions) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
491 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
492 |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
493 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
|
494 """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
|
495 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
496 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
|
497 matcher. |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
498 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
499 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
|
500 unless ``force`` is True. |
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 # Verify there are no pending changes |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
503 pending = set() |
33356
ccb3e5399921
sparse: access status fields by name instead of deconstructing it
Martin von Zweigbergk <martinvonz@google.com>
parents:
33355
diff
changeset
|
504 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
|
505 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
|
506 pending.update(origstatus.removed) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
507 sparsematch = matcher(repo) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
508 abort = False |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
509 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
510 for f in pending: |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
511 if not sparsematch(f): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
512 repo.ui.warn(_(b"pending changes to '%s'\n") % f) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
513 abort = not force |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
514 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
515 if abort: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
516 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
517 _(b'could not update sparseness due to pending changes') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
518 ) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
519 |
45334
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
520 # Calculate merge result |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
521 dirstate = repo.dirstate |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
522 ctx = repo[b'.'] |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
523 added = [] |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
524 lookup = [] |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
525 dropped = [] |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
526 mf = ctx.manifest() |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
527 files = set(mf) |
45334
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
528 mresult = mergemod.mergeresult() |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
529 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
530 for file in files: |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
531 old = origsparsematch(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
532 new = sparsematch(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
533 # 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
|
534 # the dirstate yet. |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
535 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
|
536 fl = mf.flags(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
537 if repo.wvfs.exists(file): |
45339
9320f66854f6
sparse: replace merge action values with mergestate.ACTION_* constants
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45334
diff
changeset
|
538 mresult.addfile(file, mergestatemod.ACTION_EXEC, (fl,), b'') |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
539 lookup.append(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
540 else: |
45339
9320f66854f6
sparse: replace merge action values with mergestate.ACTION_* constants
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45334
diff
changeset
|
541 mresult.addfile( |
9320f66854f6
sparse: replace merge action values with mergestate.ACTION_* constants
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45334
diff
changeset
|
542 file, mergestatemod.ACTION_GET, (fl, False), b'' |
9320f66854f6
sparse: replace merge action values with mergestate.ACTION_* constants
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45334
diff
changeset
|
543 ) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
544 added.append(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
545 # 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
|
546 # the dirstate. |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
547 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
|
548 dropped.append(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
549 if file not in pending: |
45339
9320f66854f6
sparse: replace merge action values with mergestate.ACTION_* constants
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45334
diff
changeset
|
550 mresult.addfile(file, mergestatemod.ACTION_REMOVE, [], b'') |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
551 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
552 # 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
|
553 abort = False |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
554 for file in lookup: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
555 repo.ui.warn(_(b"pending changes to '%s'\n") % file) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
556 abort = not force |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
557 if abort: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
558 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
559 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
560 b'cannot change sparseness due to pending ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
561 b'changes (delete the files or use ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
562 b'--force to bring them back dirty)' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
563 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
564 ) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
565 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
566 # Check for files that were only in the dirstate. |
48913
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
567 for file, state in dirstate.items(): |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
568 if not file in files: |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
569 old = origsparsematch(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
570 new = sparsematch(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
571 if old and not new: |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
572 dropped.append(file) |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
573 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
574 mergemod.applyupdates( |
45334
b9b055f15035
merge: pass mergeresult obj instead of actions in applyupdates() (API)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45295
diff
changeset
|
575 repo, mresult, repo[None], repo[b'.'], False, wantfiledata=False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
576 ) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
577 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
578 # Fix dirstate |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
579 for file in added: |
47710
3148204e649e
sparse: use `update_file` instead of `normal` in `refreshwdir`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47709
diff
changeset
|
580 dirstate.update_file(file, p1_tracked=True, wc_tracked=True) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
581 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
582 for file in dropped: |
47747
452e7048293d
sparse: use `update_file` instead of `drop` in `refreshwdir`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47737
diff
changeset
|
583 dirstate.update_file(file, p1_tracked=False, wc_tracked=False) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
584 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
585 for file in lookup: |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
586 # File exists on disk, and we're bringing it back in an unknown state. |
47737
e0e69a7d7af8
sparse: use `update_file` instead of `normallookup` in refreshwdir
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47710
diff
changeset
|
587 dirstate.update_file( |
e0e69a7d7af8
sparse: use `update_file` instead of `normallookup` in refreshwdir
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47710
diff
changeset
|
588 file, p1_tracked=True, wc_tracked=True, possibly_dirty=True |
e0e69a7d7af8
sparse: use `update_file` instead of `normallookup` in refreshwdir
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47710
diff
changeset
|
589 ) |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
590 |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
591 return added, dropped, lookup |
33353
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
592 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
593 |
33353
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
594 def aftercommit(repo, node): |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
595 """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
|
596 # 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
|
597 # enabled. |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
598 ctx = repo[node] |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
599 |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
600 profiles = patternsforrev(repo, ctx.rev())[2] |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
601 |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
602 # 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
|
603 if profiles & set(ctx.files()): |
33353
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
604 origstatus = repo.status() |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
605 origsparsematch = matcher(repo) |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
606 refreshwdir(repo, origstatus, origsparsematch, force=True) |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
607 |
160efb559f67
sparse: move post commit actions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33325
diff
changeset
|
608 prunetemporaryincludes(repo) |
33354
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
609 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
610 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
611 def _updateconfigandrefreshwdir( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
612 repo, includes, excludes, profiles, force=False, removing=False |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
613 ): |
33555
6755b719048c
sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33551
diff
changeset
|
614 """Update the sparse config and working directory state.""" |
48665
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
615 with repo.lock(): |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
616 raw = repo.vfs.tryread(b'sparse') |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
617 oldincludes, oldexcludes, oldprofiles = parseconfig( |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
618 repo.ui, raw, b'sparse' |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
619 ) |
33555
6755b719048c
sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33551
diff
changeset
|
620 |
48665
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
621 oldstatus = repo.status() |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
622 oldmatch = matcher(repo) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
623 oldrequires = set(repo.requirements) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
624 |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
625 # TODO remove this try..except once the matcher integrates better |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
626 # with dirstate. We currently have to write the updated config |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
627 # because that will invalidate the matcher cache and force a |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
628 # re-read. We ideally want to update the cached matcher on the |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
629 # repo instance then flush the new config to disk once wdir is |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
630 # updated. But this requires massive rework to matcher() and its |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
631 # consumers. |
33555
6755b719048c
sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33551
diff
changeset
|
632 |
48665
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
633 if requirements.SPARSE_REQUIREMENT in oldrequires and removing: |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
634 repo.requirements.discard(requirements.SPARSE_REQUIREMENT) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
635 scmutil.writereporequirements(repo) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
636 elif requirements.SPARSE_REQUIREMENT not in oldrequires: |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
637 repo.requirements.add(requirements.SPARSE_REQUIREMENT) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
638 scmutil.writereporequirements(repo) |
33555
6755b719048c
sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33551
diff
changeset
|
639 |
48665
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
640 try: |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
641 writeconfig(repo, includes, excludes, profiles) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
642 return refreshwdir(repo, oldstatus, oldmatch, force=force) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
643 except Exception: |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
644 if repo.requirements != oldrequires: |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
645 repo.requirements.clear() |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
646 repo.requirements |= oldrequires |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
647 scmutil.writereporequirements(repo) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
648 writeconfig(repo, oldincludes, oldexcludes, oldprofiles) |
a62ba3345534
sparse: take lock before writing requirements
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48494
diff
changeset
|
649 raise |
33555
6755b719048c
sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33551
diff
changeset
|
650 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
651 |
33354
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
652 def clearrules(repo, force=False): |
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
653 """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
|
654 |
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
655 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
|
656 directory is refreshed, as needed. |
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
657 """ |
49961
7a8bfc05b691
dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49960
diff
changeset
|
658 with repo.wlock(), repo.dirstate.changing_parents(repo): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
659 raw = repo.vfs.tryread(b'sparse') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
660 includes, excludes, profiles = parseconfig(repo.ui, raw, b'sparse') |
33354
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
661 |
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
662 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
|
663 return |
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
664 |
33555
6755b719048c
sparse: consolidate common code for writing sparse config
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33551
diff
changeset
|
665 _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
|
666 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
667 |
33371
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
668 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
|
669 """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
|
670 |
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
671 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
|
672 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
|
673 """ |
49961
7a8bfc05b691
dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49960
diff
changeset
|
674 with repo.wlock(), repo.dirstate.changing_parents(repo): |
33371
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
675 # read current configuration |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
676 raw = repo.vfs.tryread(b'sparse') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
677 includes, excludes, profiles = parseconfig(repo.ui, raw, b'sparse') |
33371
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
678 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
|
679 |
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
680 # 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
|
681 # 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
|
682 changed = False |
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
683 for p in paths: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
684 with util.posixfile(util.expandpath(p), mode=b'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
|
685 raw = fh.read() |
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
686 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
687 iincludes, iexcludes, iprofiles = parseconfig( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
688 repo.ui, raw, b'sparse' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
689 ) |
33371
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
690 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
|
691 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
|
692 excludes.update(iexcludes - aexcludes) |
33550
32f348d741e5
sparse: use set for capturing profiles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33499
diff
changeset
|
693 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
|
694 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
|
695 changed = True |
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
696 |
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
697 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
|
698 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
|
699 |
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
700 if changed: |
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
701 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
|
702 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
|
703 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
|
704 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
705 fcounts = map( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
706 len, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
707 _updateconfigandrefreshwdir( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
708 repo, includes, excludes, profiles, force=force |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
709 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
710 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
711 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
712 printchanges( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
713 repo.ui, opts, profilecount, includecount, excludecount, *fcounts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
714 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
715 |
33371
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
716 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
717 def updateconfig( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
718 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
719 opts, |
48737
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
720 include=(), |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
721 exclude=(), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
722 reset=False, |
48737
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
723 delete=(), |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
724 enableprofile=(), |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
725 disableprofile=(), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
726 force=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
727 usereporootpaths=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
728 ): |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
729 """Perform a sparse config update. |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
730 |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
731 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
|
732 """ |
49961
7a8bfc05b691
dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49960
diff
changeset
|
733 with repo.wlock(), repo.lock(), repo.dirstate.changing_parents(repo): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
734 raw = repo.vfs.tryread(b'sparse') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
735 oldinclude, oldexclude, oldprofiles = parseconfig( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
736 repo.ui, raw, b'sparse' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
737 ) |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
738 |
33376
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
739 if reset: |
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
740 newinclude = set() |
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
741 newexclude = set() |
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
742 newprofiles = set() |
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
743 else: |
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
744 newinclude = set(oldinclude) |
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
745 newexclude = set(oldexclude) |
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
746 newprofiles = set(oldprofiles) |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
747 |
48737
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
748 def normalize_pats(pats): |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
749 if any(os.path.isabs(pat) for pat in pats): |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
750 raise error.Abort(_(b'paths cannot be absolute')) |
33683
7dcb517122f9
sparse: properly error out when absolute paths are used
Kostia Balytskyi <ikostia@fb.com>
parents:
33556
diff
changeset
|
751 |
48737
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
752 if usereporootpaths: |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
753 return pats |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
754 |
33685
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
755 # let's treat paths as relative to cwd |
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
756 root, cwd = repo.root, repo.getcwd() |
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
757 abspats = [] |
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
758 for kindpat in pats: |
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
759 kind, pat = matchmod._patsplit(kindpat, None) |
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
760 if kind in matchmod.cwdrelativepatternkinds or kind is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
761 ap = (kind + b':' if kind else b'') + pathutil.canonpath( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
762 root, cwd, pat |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
763 ) |
33685
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
764 abspats.append(ap) |
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
765 else: |
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
766 abspats.append(kindpat) |
48737
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
767 return abspats |
33685
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33683
diff
changeset
|
768 |
48737
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
769 include = normalize_pats(include) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
770 exclude = normalize_pats(exclude) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
771 delete = normalize_pats(delete) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
772 disableprofile = normalize_pats(disableprofile) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
773 enableprofile = normalize_pats(enableprofile) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
774 |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
775 newinclude.difference_update(delete) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
776 newexclude.difference_update(delete) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
777 newprofiles.difference_update(disableprofile) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
778 newinclude.update(include) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
779 newprofiles.update(enableprofile) |
a6efb9180764
sparse: rework debugsparse's interface
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
48713
diff
changeset
|
780 newexclude.update(exclude) |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
781 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
782 profilecount = len(newprofiles - oldprofiles) - len( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
783 oldprofiles - newprofiles |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
784 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
785 includecount = len(newinclude - oldinclude) - len( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
786 oldinclude - newinclude |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
787 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
788 excludecount = len(newexclude - oldexclude) - len( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
789 oldexclude - newexclude |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
790 ) |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
791 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
792 fcounts = map( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
793 len, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
794 _updateconfigandrefreshwdir( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
795 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
796 newinclude, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
797 newexclude, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
798 newprofiles, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
799 force=force, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
800 removing=reset, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
801 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
802 ) |
33376
d5a38eae67e5
sparse: shorten try..except block in updateconfig()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33375
diff
changeset
|
803 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
804 printchanges( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
805 repo.ui, opts, profilecount, includecount, excludecount, *fcounts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
806 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
807 |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
808 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
809 def printchanges( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
810 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
811 opts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
812 profilecount=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
813 includecount=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
814 excludecount=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
815 added=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
816 dropped=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
817 conflicting=0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
818 ): |
33355
9087f9997f42
sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33354
diff
changeset
|
819 """Print output summarizing sparse config changes.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
820 with ui.formatter(b'sparse', opts) as fm: |
33355
9087f9997f42
sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33354
diff
changeset
|
821 fm.startitem() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
822 fm.condwrite( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
823 ui.verbose, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
824 b'profiles_added', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
825 _(b'Profiles changed: %d\n'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
826 profilecount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
827 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
828 fm.condwrite( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
829 ui.verbose, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
830 b'include_rules_added', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
831 _(b'Include rules changed: %d\n'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
832 includecount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
833 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
834 fm.condwrite( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
835 ui.verbose, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
836 b'exclude_rules_added', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
837 _(b'Exclude rules changed: %d\n'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
838 excludecount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
839 ) |
33355
9087f9997f42
sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33354
diff
changeset
|
840 |
9087f9997f42
sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33354
diff
changeset
|
841 # 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
|
842 # 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
|
843 # 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
|
844 if not fm.isplain(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
845 fm.condwrite( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
846 ui.verbose, b'files_added', _(b'Files added: %d\n'), added |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
847 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
848 fm.condwrite( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
849 ui.verbose, b'files_dropped', _(b'Files dropped: %d\n'), dropped |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
850 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
851 fm.condwrite( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
852 ui.verbose, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
853 b'files_conflicting', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
854 _(b'Files conflicting: %d\n'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
855 conflicting, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42456
diff
changeset
|
856 ) |