Mercurial > hg
annotate hgext/sparse.py @ 42044:bb271ec2fbfb
compression: introduce a `storage.revlog.zstd.level` configuration
This option control the zstd compression level used when compressing revlog
chunk. The usage of zstd for revlog compression has not graduated from
experimental yet, but we intend to fix that soon.
The option name for the compression level is more straight forward to pick, so
this changesets comes first. Having a dedicated option for each compression
engine is useful because they don't support the same range of values.
I ran the same measurement as for the zlib compression level (in the parent
changesets). The variation in repository size is stay mostly in the same (small)
range. The "read/write" performance see smallish variation, but are overall much
better than zlib. Write performance show the same tend of having better write
performance for when reaching high-end compression.
Again, we don't intend to change the default zstd compression level (currently:
3) in this series. However this is worth investigating in the future.
The Performance comparison of zlib vs zstd is quite impressive. The repository
size stay in the same range, but the performance are much better in all
situations.
Comparison summary
==================
We are looking at:
- performance range for zlib
- performance range for zstd
- comparison of default zstd (level-3) to default zlib (level 6)
- comparison of the slowest zstd time to the fastest zlib time
Read performance:
-----------------
| zlib | zstd | cmp | f2s
mercurial | 0.170159 - 0.189219 | 0.144127 - 0.149624 | 80% | 88%
pypy | 2.679217 - 2.768691 | 1.532317 - 1.705044 | 60% | 63%
netbeans | 122.477027 - 141.620281 | 72.996346 - 89.731560 | 58% | 73%
mozilla | 147.867662 - 170.572118 | 91.700995 - 105.853099 | 56% | 71%
Write performance:
------------------
| zlib | zstd | cmp | f2s
mercurial | 53.250304 - 56.2936129 | 40.877025 - 45.677286 | 75% | 86%
pypy | 460.721984 - 476.589918 | 270.545409 - 301.002219 | 63% | 65%
netbeans | 520.560316 - 715.930400 | 370.356311 - 428.329652 | 55% | 82%
mozilla | 739.803002 - 987.056093 | 505.152906 - 591.930683 | 57% | 80%
Raw data
--------
repo alg lvl .hg/store size 00manifest.d read write
mercurial zlib 1 49,402,813 5,963,475 0.170159 53.250304
mercurial zlib 6 47,197,397 5,875,730 0.182820 56.264320
mercurial zlib 9 47,121,596 5,849,781 0.189219 56.293612
mercurial zstd 1 49,737,084 5,966,355 0.144127 40.877025
mercurial zstd 3 48,961,867 5,895,208 0.146376 42.268142
mercurial zstd 5 48,200,592 5,938,676 0.149624 43.162875
mercurial zstd 10 47,833,520 5,913,353 0.145185 44.012489
mercurial zstd 15 47,314,604 5,728,679 0.147686 45.677286
mercurial zstd 20 47,330,502 5,830,539 0.145789 45.025407
mercurial zstd 22 47,330,076 5,830,539 0.143996 44.690460
pypy zlib 1 370,830,572 28,462,425 2.679217 460.721984
pypy zlib 6 340,112,317 27,648,747 2.768691 467.537158
pypy zlib 9 338,360,736 27,639,003 2.763495 476.589918
pypy zstd 1 362,377,479 27,916,214 1.532317 270.545409
pypy zstd 3 354,137,693 27,905,988 1.686718 294.951509
pypy zstd 5 342,640,043 27,655,774 1.705044 301.002219
pypy zstd 10 334,224,327 27,164,493 1.567287 285.186239
pypy zstd 15 329,000,363 26,645,965 1.637729 299.561332
pypy zstd 20 324,534,039 26,199,547 1.526813 302.149827
pypy zstd 22 324,530,595 26,198,932 1.525718 307.821218
netbeans zlib 1 1,281,847,810 165,495,457 122.477027 520.560316
netbeans zlib 6 1,205,284,353 159,161,207 139.876147 715.930400
netbeans zlib 9 1,197,135,671 155,034,586 141.620281 678.297064
netbeans zstd 1 1,259,581,737 160,840,613 72.996346 370.356311
netbeans zstd 3 1,232,978,122 157,691,551 81.622317 396.733087
netbeans zstd 5 1,208,034,075 160,246,880 83.080549 364.342626
netbeans zstd 10 1,188,624,176 156,083,417 79.323935 403.594602
netbeans zstd 15 1,176,973,589 153,859,477 89.731560 428.329652
netbeans zstd 20 1,162,958,258 151,147,535 82.842667 392.335349
netbeans zstd 22 1,162,707,029 151,150,220 82.565695 402.840655
mozilla zlib 1 2,775,497,186 298,527,987 147.867662 751.263721
mozilla zlib 6 2,596,856,420 286,597,671 170.572118 987.056093
mozilla zlib 9 2,587,542,494 287,018,264 163.622338 739.803002
mozilla zstd 1 2,723,159,348 286,617,532 91.700995 570.042751
mozilla zstd 3 2,665,055,001 286,152,013 95.240155 561.412805
mozilla zstd 5 2,607,819,817 288,060,030 101.978048 505.152906
mozilla zstd 10 2,558,761,085 283,967,648 104.113481 497.771202
mozilla zstd 15 2,526,216,060 275,581,300 105.853099 591.930683
mozilla zstd 20 2,485,114,806 266,478,859 95.268795 576.515389
mozilla zstd 22 2,484,869,080 266,456,505 94.429282 572.785537
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 27 Mar 2019 18:35:59 +0100 |
parents | f9344d04909e |
children | 87a34c767384 |
rev | line source |
---|---|
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # sparse.py - allow sparse checkouts of the working directory |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2014 Facebook, Inc. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 """allow sparse checkouts of the working directory (EXPERIMENTAL) |
33290
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
9 |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
10 (This extension is not yet protected by backwards compatibility |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
11 guarantees. Any aspect may break in future releases until this |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
12 notice is removed.) |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
13 |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
14 This extension allows the working directory to only consist of a |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
15 subset of files for the revision. This allows specific files or |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
16 directories to be explicitly included or excluded. Many repository |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
17 operations have performance proportional to the number of files in |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
18 the working directory. So only realizing a subset of files in the |
cd1c275c9482
sparse: expand module docstring
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33289
diff
changeset
|
19 working directory can improve performance. |
33294
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
20 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
21 Sparse Config Files |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
22 ------------------- |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
23 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
24 The set of files that are part of a sparse checkout are defined by |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
25 a sparse config file. The file defines 3 things: includes (files to |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
26 include in the sparse checkout), excludes (files to exclude from the |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
27 sparse checkout), and profiles (links to other config files). |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
28 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
29 The file format is newline delimited. Empty lines and lines beginning |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
30 with ``#`` are ignored. |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
31 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
32 Lines beginning with ``%include `` denote another sparse config file |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
33 to include. e.g. ``%include tests.sparse``. The filename is relative |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
34 to the repository root. |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
35 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
36 The special lines ``[include]`` and ``[exclude]`` denote the section |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
37 for includes and excludes that follow, respectively. It is illegal to |
33551
1d1779734c99
sparse: require [section] in sparse config files (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33496
diff
changeset
|
38 have ``[include]`` after ``[exclude]``. |
33294
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
39 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
40 Non-special lines resemble file patterns to be added to either includes |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
41 or excludes. The syntax of these lines is documented by :hg:`help patterns`. |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
42 Patterns are interpreted as ``glob:`` by default and match against the |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
43 root of the repository. |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
44 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
45 Exclusion patterns take precedence over inclusion patterns. So even |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
46 if a file is explicitly included, an ``[exclude]`` entry can remove it. |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
47 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
48 For example, say you have a repository with 3 directories, ``frontend/``, |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
49 ``backend/``, and ``tools/``. ``frontend/`` and ``backend/`` correspond |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
50 to different projects and it is uncommon for someone working on one |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
51 to need the files for the other. But ``tools/`` contains files shared |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
52 between both projects. Your sparse config files may resemble:: |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
53 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
54 # frontend.sparse |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
55 frontend/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
56 tools/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
57 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
58 # backend.sparse |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
59 backend/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
60 tools/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
61 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
62 Say the backend grows in size. Or there's a directory with thousands |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
63 of files you wish to exclude. You can modify the profile to exclude |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
64 certain files:: |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
65 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
66 [include] |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
67 backend/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
68 tools/** |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
69 |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
70 [exclude] |
a5921ad2eb99
sparse: document config file format
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33293
diff
changeset
|
71 tools/tests/** |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 """ |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 from __future__ import absolute_import |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 from mercurial.i18n import _ |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 from mercurial import ( |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 commands, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 dirstate, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 error, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 extensions, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 hg, |
35885
7625b4f7db70
cmdutil: split functions of log-like commands to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35192
diff
changeset
|
83 logcmdutil, |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 match as matchmod, |
35192
d8d06a930d60
py3: use byteskwargs in sparse.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33685
diff
changeset
|
85 pycompat, |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 registrar, |
33297
ba5d89774db6
sparse: move config parsing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33296
diff
changeset
|
87 sparse, |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 util, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 ) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 # be specifying the version(s) of Mercurial they are tested with, or |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 # leave the attribute unspecified. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 testedwith = 'ships-with-hg-core' |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 cmdtable = {} |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 command = registrar.command(cmdtable) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 def extsetup(ui): |
33299
41448fc51510
sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33298
diff
changeset
|
101 sparse.enabled = True |
41448fc51510
sparse: variable to track if sparse is enabled
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33298
diff
changeset
|
102 |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 _setupclone(ui) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 _setuplog(ui) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 _setupadd(ui) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 _setupdirstate(ui) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 def replacefilecache(cls, propname, replacement): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 """Replace a filecache property with a new class. This allows changing the |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 cache invalidation condition.""" |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 origcls = cls |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 assert callable(replacement) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 while cls is not object: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 if propname in cls.__dict__: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 orig = cls.__dict__[propname] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 setattr(cls, propname, replacement(orig)) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 break |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 cls = cls.__bases__[0] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 if cls is object: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 raise AttributeError(_("type '%s' has no property '%s'") % (origcls, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 propname)) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 def _setuplog(ui): |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
38112
diff
changeset
|
125 entry = commands.table['log|history'] |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 entry[1].append(('', 'sparse', None, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 "limit to changesets affecting the sparse checkout")) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 |
35887
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35885
diff
changeset
|
129 def _initialrevs(orig, repo, opts): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 revs = orig(repo, opts) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 if opts.get('sparse'): |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33319
diff
changeset
|
132 sparsematch = sparse.matcher(repo) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 def ctxmatch(rev): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
134 ctx = repo[rev] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 return any(f for f in ctx.files() if sparsematch(f)) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 revs = revs.filter(ctxmatch) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 return revs |
35887
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35885
diff
changeset
|
138 extensions.wrapfunction(logcmdutil, '_initialrevs', _initialrevs) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
139 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
140 def _clonesparsecmd(orig, ui, repo, *args, **opts): |
38112
d7cecea0b254
py3: add r'' prefixes to fix kwargs handling in hgext/sparse.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36200
diff
changeset
|
141 include_pat = opts.get(r'include') |
d7cecea0b254
py3: add r'' prefixes to fix kwargs handling in hgext/sparse.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36200
diff
changeset
|
142 exclude_pat = opts.get(r'exclude') |
d7cecea0b254
py3: add r'' prefixes to fix kwargs handling in hgext/sparse.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36200
diff
changeset
|
143 enableprofile_pat = opts.get(r'enable_profile') |
41148
8eaf693b1409
sparse: don't enable on clone if it was a narrow clone
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40295
diff
changeset
|
144 narrow_pat = opts.get(r'narrow') |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 include = exclude = enableprofile = False |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
146 if include_pat: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 pat = include_pat |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 include = True |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 if exclude_pat: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 pat = exclude_pat |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 exclude = True |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 if enableprofile_pat: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 pat = enableprofile_pat |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 enableprofile = True |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 if sum([include, exclude, enableprofile]) > 1: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 raise error.Abort(_("too many flags specified.")) |
41148
8eaf693b1409
sparse: don't enable on clone if it was a narrow clone
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40295
diff
changeset
|
157 # if --narrow is passed, it means they are includes and excludes for narrow |
8eaf693b1409
sparse: don't enable on clone if it was a narrow clone
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40295
diff
changeset
|
158 # clone |
8eaf693b1409
sparse: don't enable on clone if it was a narrow clone
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
40295
diff
changeset
|
159 if not narrow_pat and (include or exclude or enableprofile): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 def clonesparse(orig, self, node, overwrite, *args, **kwargs): |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
161 sparse.updateconfig(self.unfiltered(), pat, {}, include=include, |
33685
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33551
diff
changeset
|
162 exclude=exclude, enableprofile=enableprofile, |
e1c56486d1aa
sparse: treat paths as cwd-relative
Kostia Balytskyi <ikostia@fb.com>
parents:
33551
diff
changeset
|
163 usereporootpaths=True) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 return orig(self, node, overwrite, *args, **kwargs) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
165 extensions.wrapfunction(hg, 'updaterepo', clonesparse) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 return orig(ui, repo, *args, **opts) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
167 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 def _setupclone(ui): |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
38112
diff
changeset
|
169 entry = commands.table['clone'] |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
170 entry[1].append(('', 'enable-profile', [], |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 'enable a sparse profile')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 entry[1].append(('', 'include', [], |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 'include sparse pattern')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 entry[1].append(('', 'exclude', [], |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
175 'exclude sparse pattern')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
176 extensions.wrapcommand(commands.table, 'clone', _clonesparsecmd) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
178 def _setupadd(ui): |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
38112
diff
changeset
|
179 entry = commands.table['add'] |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 entry[1].append(('s', 'sparse', None, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 'also include directories of added files in sparse config')) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 def _add(orig, ui, repo, *pats, **opts): |
38112
d7cecea0b254
py3: add r'' prefixes to fix kwargs handling in hgext/sparse.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36200
diff
changeset
|
184 if opts.get(r'sparse'): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 dirs = set() |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 for pat in pats: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 dirname, basename = util.split(pat) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 dirs.add(dirname) |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
189 sparse.updateconfig(repo, list(dirs), opts, include=True) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 return orig(ui, repo, *pats, **opts) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 extensions.wrapcommand(commands.table, 'add', _add) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
193 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 def _setupdirstate(ui): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
195 """Modify the dirstate to prevent stat'ing excluded files, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
196 and to prevent modifications to files outside the checkout. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 """ |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 |
33496
258298f4712b
sparse: override dirstate.walk() instead of dirstate._ignore
Martin von Zweigbergk <martinvonz@google.com>
parents:
33374
diff
changeset
|
199 def walk(orig, self, match, subrepos, unknown, ignored, full=True): |
36200
deb851914fd7
dirstate: drop explicit files that shouldn't match (BC) (issue4679)
Yuya Nishihara <yuya@tcha.org>
parents:
35887
diff
changeset
|
200 # hack to not exclude explicitly-specified paths so that they can |
deb851914fd7
dirstate: drop explicit files that shouldn't match (BC) (issue4679)
Yuya Nishihara <yuya@tcha.org>
parents:
35887
diff
changeset
|
201 # be warned later on e.g. dirstate.add() |
41676
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41675
diff
changeset
|
202 em = matchmod.exact(match.files()) |
36200
deb851914fd7
dirstate: drop explicit files that shouldn't match (BC) (issue4679)
Yuya Nishihara <yuya@tcha.org>
parents:
35887
diff
changeset
|
203 sm = matchmod.unionmatcher([self._sparsematcher, em]) |
deb851914fd7
dirstate: drop explicit files that shouldn't match (BC) (issue4679)
Yuya Nishihara <yuya@tcha.org>
parents:
35887
diff
changeset
|
204 match = matchmod.intersectmatchers(match, sm) |
33496
258298f4712b
sparse: override dirstate.walk() instead of dirstate._ignore
Martin von Zweigbergk <martinvonz@google.com>
parents:
33374
diff
changeset
|
205 return orig(self, match, subrepos, unknown, ignored, full) |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33319
diff
changeset
|
206 |
33496
258298f4712b
sparse: override dirstate.walk() instead of dirstate._ignore
Martin von Zweigbergk <martinvonz@google.com>
parents:
33374
diff
changeset
|
207 extensions.wrapfunction(dirstate.dirstate, 'walk', walk) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
208 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
209 # dirstate.rebuild should not add non-matching files |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
210 def _rebuild(orig, self, parent, allfiles, changedfiles=None): |
33373
fb320398a21c
dirstate: expose a sparse matcher on dirstate (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33372
diff
changeset
|
211 matcher = self._sparsematcher |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33319
diff
changeset
|
212 if not matcher.always(): |
41150
b05eb98a6b67
sparse: fix debugrebuilddirsate when narrow extension is enabled
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41148
diff
changeset
|
213 allfiles = [f for f in allfiles if matcher(f)] |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 if changedfiles: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
215 changedfiles = [f for f in changedfiles if matcher(f)] |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
216 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
217 if changedfiles is not None: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 # In _rebuild, these files will be deleted from the dirstate |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
219 # when they are not found to be in allfiles |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
220 dirstatefilestoremove = set(f for f in self if not matcher(f)) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 changedfiles = dirstatefilestoremove.union(changedfiles) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 return orig(self, parent, allfiles, changedfiles) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 extensions.wrapfunction(dirstate.dirstate, 'rebuild', _rebuild) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 # Prevent adding files that are outside the sparse checkout |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 editfuncs = ['normal', 'add', 'normallookup', 'copy', 'remove', 'merge'] |
33293
c9cbf4de27ba
sparse: rename command to debugsparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33292
diff
changeset
|
228 hint = _('include file with `hg debugsparse --include <pattern>` or use ' + |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 '`hg add -s <file>` to include file directory while adding') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 for func in editfuncs: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 def _wrapper(orig, self, *args): |
33373
fb320398a21c
dirstate: expose a sparse matcher on dirstate (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33372
diff
changeset
|
232 sparsematch = self._sparsematcher |
33320
153456f02426
sparse: move function for resolving sparse matcher into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33319
diff
changeset
|
233 if not sparsematch.always(): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 for f in args: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 if (f is not None and not sparsematch(f) and |
33372
4481f1fd27b1
sparse: use self instead of repo.dirstate
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33371
diff
changeset
|
236 f not in self): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 raise error.Abort(_("cannot add '%s' - it is outside " |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 "the sparse checkout") % f, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
239 hint=hint) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 return orig(self, *args) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 extensions.wrapfunction(dirstate.dirstate, func, _wrapper) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
38112
diff
changeset
|
243 @command('debugsparse', [ |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 ('I', 'include', False, _('include files in the sparse checkout')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 ('X', 'exclude', False, _('exclude files in the sparse checkout')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
246 ('d', 'delete', False, _('delete an include/exclude rule')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
247 ('f', 'force', False, _('allow changing rules even with pending changes')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
248 ('', 'enable-profile', False, _('enables the specified profile')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
249 ('', 'disable-profile', False, _('disables the specified profile')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
250 ('', 'import-rules', False, _('imports rules from a file')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
251 ('', 'clear-rules', False, _('clears local include/exclude rules')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
252 ('', 'refresh', False, _('updates the working after sparseness changes')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
253 ('', 'reset', False, _('makes the repo full again')), |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
254 ] + commands.templateopts, |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
38112
diff
changeset
|
255 _('[--OPTION] PATTERN...'), |
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
38112
diff
changeset
|
256 helpbasic=True) |
33293
c9cbf4de27ba
sparse: rename command to debugsparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33292
diff
changeset
|
257 def debugsparse(ui, repo, *pats, **opts): |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
258 """make the current checkout sparse, or edit the existing checkout |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
259 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
260 The sparse command is used to make the current checkout sparse. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
261 This means files that don't meet the sparse condition will not be |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
262 written to disk, or show up in any working copy operations. It does |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
263 not affect files in history in any way. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
264 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
265 Passing no arguments prints the currently applied sparse rules. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
266 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
267 --include and --exclude are used to add and remove files from the sparse |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
268 checkout. The effects of adding an include or exclude rule are applied |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
269 immediately. If applying the new rule would cause a file with pending |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
270 changes to be added or removed, the command will fail. Pass --force to |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
271 force a rule change even with pending changes (the changes on disk will |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
272 be preserved). |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
273 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
274 --delete removes an existing include/exclude rule. The effects are |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
275 immediate. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
276 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
277 --refresh refreshes the files on disk based on the sparse rules. This is |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
278 only necessary if .hg/sparse was changed by hand. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
279 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
280 --enable-profile and --disable-profile accept a path to a .hgsparse file. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
281 This allows defining sparse checkouts and tracking them inside the |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
282 repository. This is useful for defining commonly used sparse checkouts for |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
283 many people to use. As the profile definition changes over time, the sparse |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
284 checkout will automatically be updated appropriately, depending on which |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
285 changeset is checked out. Changes to .hgsparse are not applied until they |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
286 have been committed. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
287 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
288 --import-rules accepts a path to a file containing rules in the .hgsparse |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
289 format, allowing you to add --include, --exclude and --enable-profile rules |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
290 in bulk. Like the --include, --exclude and --enable-profile switches, the |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
291 changes are applied immediately. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
292 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
293 --clear-rules removes all local include and exclude rules, while leaving |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
294 any enabled profiles in place. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
295 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
296 Returns 0 if editing the sparse checkout succeeds. |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 """ |
35192
d8d06a930d60
py3: use byteskwargs in sparse.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33685
diff
changeset
|
298 opts = pycompat.byteskwargs(opts) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
299 include = opts.get('include') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
300 exclude = opts.get('exclude') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
301 force = opts.get('force') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
302 enableprofile = opts.get('enable_profile') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 disableprofile = opts.get('disable_profile') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
304 importrules = opts.get('import_rules') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
305 clearrules = opts.get('clear_rules') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
306 delete = opts.get('delete') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
307 refresh = opts.get('refresh') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
308 reset = opts.get('reset') |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
309 count = sum([include, exclude, enableprofile, disableprofile, delete, |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
310 importrules, refresh, clearrules, reset]) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
311 if count > 1: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
312 raise error.Abort(_("too many flags specified")) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
313 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
314 if count == 0: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
315 if repo.vfs.exists('sparse'): |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
316 ui.status(repo.vfs.read("sparse") + "\n") |
33304
3e1accab7447
sparse: move some temporary includes functions into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33303
diff
changeset
|
317 temporaryincludes = sparse.readtemporaryincludes(repo) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
318 if temporaryincludes: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
319 ui.status(_("Temporarily Included Files (for merge/rebase):\n")) |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
320 ui.status(("\n".join(temporaryincludes) + "\n")) |
41988
f9344d04909e
debugsparse: abort if the repository is not sparse instead of ui.status()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41676
diff
changeset
|
321 return |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
322 else: |
41988
f9344d04909e
debugsparse: abort if the repository is not sparse instead of ui.status()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41676
diff
changeset
|
323 raise error.Abort(_('the debugsparse command is only supported on' |
f9344d04909e
debugsparse: abort if the repository is not sparse instead of ui.status()
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
41676
diff
changeset
|
324 ' sparse repositories')) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
325 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
326 if include or exclude or delete or reset or enableprofile or disableprofile: |
33374
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
327 sparse.updateconfig(repo, pats, opts, include=include, exclude=exclude, |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
328 reset=reset, delete=delete, |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
329 enableprofile=enableprofile, |
4dc04cdf2520
sparse: move config updating function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33373
diff
changeset
|
330 disableprofile=disableprofile, force=force) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
331 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
332 if importrules: |
33371
c6415195fa78
sparse: move code for importing rules from files into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33370
diff
changeset
|
333 sparse.importfromfiles(repo, opts, pats, force=force) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
334 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
335 if clearrules: |
33354
4695f1829045
sparse: move code for clearing rules to core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33353
diff
changeset
|
336 sparse.clearrules(repo, force=force) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
337 |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
338 if refresh: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
339 try: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
340 wlock = repo.wlock() |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
341 fcounts = map( |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
342 len, |
33324
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
343 sparse.refreshwdir(repo, repo.status(), sparse.matcher(repo), |
33d0859c37bd
sparse: move working directory refreshing into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33323
diff
changeset
|
344 force=force)) |
33355
9087f9997f42
sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33354
diff
changeset
|
345 sparse.printchanges(ui, opts, added=fcounts[0], dropped=fcounts[1], |
9087f9997f42
sparse: move printing of sparse config changes function into core
Gregory Szorc <gregory.szorc@gmail.com>
parents:
33354
diff
changeset
|
346 conflicting=fcounts[2]) |
33289
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
347 finally: |
abd7dedbaa36
sparse: vendor Facebook-developed extension
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
348 wlock.release() |