Mercurial > hg
comparison tests/test-sparse-import.t @ 33289:abd7dedbaa36
sparse: vendor Facebook-developed extension
Facebook has developed an extension to enable "sparse" checkouts -
a working directory with a subset of files. This feature is a critical
component in enabling repositories to scale to infinite number of
files while retaining reasonable performance. It's worth noting
that sparse checkout is only one possible solution to this problem:
another is virtual filesystems that realize files on first access.
But given that virtual filesystems may not be accessible to all
users, sparse checkout is necessary as a fallback.
Per mailing list discussion at
https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-March/095868.html
we want to add sparse checkout to the Mercurial distribution via
roughly the following mechanism:
1. Vendor extension as-is with minimal modifications (this patch)
2. Refactor extension so it is more clearly experimental and inline
with Mercurial practices
3. Move code from extension into core where possible
4. Drop experimental labeling and/or move feature into core
after sign-off from narrow clone feature owners
This commit essentially copies the sparse extension and tests
from revision 71e0a2aeca92a4078fe1b8c76e32c88ff1929737 of the
https://bitbucket.org/facebook/hg-experimental repository.
A list of modifications made as part of vendoring is as follows:
* "EXPERIMENTAL" added to module docstring
* Imports were changed to match Mercurial style conventions
* "testedwith" value was updated to core Mercurial special value and
comment boilerplate was inserted
* A "clone_sparse" function was renamed to "clonesparse" to appease
the style checker
* Paths to the sparse extension in tests reflect built-in location
* test-sparse-extensions.t was renamed to test-sparse-fsmonitor.t
and references to "simplecache" were removed. The test always skips
because it isn't trivial to run it given the way we currently run
fsmonitor tests
* A double empty line was removed from test-sparse-profiles.t
There are aspects of the added code that are obviously not ideal.
The goal is to make a minimal number of modifications as part of
the vendoring to make it easier to track changes from the original
implementation. Refactoring will occur in subsequent patches.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 01 Jul 2017 10:43:29 -0700 |
parents | |
children | c9cbf4de27ba |
comparison
equal
deleted
inserted
replaced
33288:f08a178adadf | 33289:abd7dedbaa36 |
---|---|
1 test sparse | |
2 | |
3 $ hg init myrepo | |
4 $ cd myrepo | |
5 $ cat >> $HGRCPATH <<EOF | |
6 > [extensions] | |
7 > sparse= | |
8 > purge= | |
9 > strip= | |
10 > rebase= | |
11 > EOF | |
12 | |
13 $ echo a > index.html | |
14 $ echo x > data.py | |
15 $ echo z > readme.txt | |
16 $ cat > base.sparse <<EOF | |
17 > [include] | |
18 > *.sparse | |
19 > EOF | |
20 $ hg ci -Aqm 'initial' | |
21 $ cat > webpage.sparse <<EOF | |
22 > %include base.sparse | |
23 > [include] | |
24 > *.html | |
25 > EOF | |
26 $ hg ci -Aqm 'initial' | |
27 | |
28 Import a rules file against a 'blank' sparse profile | |
29 | |
30 $ cat > $TESTTMP/rules_to_import <<EOF | |
31 > [include] | |
32 > *.py | |
33 > EOF | |
34 $ hg sparse --import-rules $TESTTMP/rules_to_import | |
35 $ ls | |
36 data.py | |
37 | |
38 $ hg sparse --reset | |
39 $ rm .hg/sparse | |
40 | |
41 $ cat > $TESTTMP/rules_to_import <<EOF | |
42 > %include base.sparse | |
43 > [include] | |
44 > *.py | |
45 > EOF | |
46 $ hg sparse --import-rules $TESTTMP/rules_to_import | |
47 $ ls | |
48 base.sparse | |
49 data.py | |
50 webpage.sparse | |
51 | |
52 $ hg sparse --reset | |
53 $ rm .hg/sparse | |
54 | |
55 Start against an existing profile; rules *already active* should be ignored | |
56 | |
57 $ hg sparse --enable-profile webpage.sparse | |
58 $ hg sparse --include *.py | |
59 $ cat > $TESTTMP/rules_to_import <<EOF | |
60 > %include base.sparse | |
61 > [include] | |
62 > *.html | |
63 > *.txt | |
64 > [exclude] | |
65 > *.py | |
66 > EOF | |
67 $ hg sparse --import-rules $TESTTMP/rules_to_import | |
68 $ ls | |
69 base.sparse | |
70 index.html | |
71 readme.txt | |
72 webpage.sparse | |
73 $ cat .hg/sparse | |
74 %include webpage.sparse | |
75 [include] | |
76 *.py | |
77 *.txt | |
78 [exclude] | |
79 *.py | |
80 | |
81 $ hg sparse --reset | |
82 $ rm .hg/sparse | |
83 | |
84 Same tests, with -Tjson enabled to output summaries | |
85 | |
86 $ cat > $TESTTMP/rules_to_import <<EOF | |
87 > [include] | |
88 > *.py | |
89 > EOF | |
90 $ hg sparse --import-rules $TESTTMP/rules_to_import -Tjson | |
91 [ | |
92 { | |
93 "exclude_rules_added": 0, | |
94 "files_added": 0, | |
95 "files_conflicting": 0, | |
96 "files_dropped": 4, | |
97 "include_rules_added": 1, | |
98 "profiles_added": 0 | |
99 } | |
100 ] | |
101 | |
102 $ hg sparse --reset | |
103 $ rm .hg/sparse | |
104 | |
105 $ cat > $TESTTMP/rules_to_import <<EOF | |
106 > %include base.sparse | |
107 > [include] | |
108 > *.py | |
109 > EOF | |
110 $ hg sparse --import-rules $TESTTMP/rules_to_import -Tjson | |
111 [ | |
112 { | |
113 "exclude_rules_added": 0, | |
114 "files_added": 0, | |
115 "files_conflicting": 0, | |
116 "files_dropped": 2, | |
117 "include_rules_added": 1, | |
118 "profiles_added": 1 | |
119 } | |
120 ] | |
121 | |
122 $ hg sparse --reset | |
123 $ rm .hg/sparse | |
124 | |
125 $ hg sparse --enable-profile webpage.sparse | |
126 $ hg sparse --include *.py | |
127 $ cat > $TESTTMP/rules_to_import <<EOF | |
128 > %include base.sparse | |
129 > [include] | |
130 > *.html | |
131 > *.txt | |
132 > [exclude] | |
133 > *.py | |
134 > EOF | |
135 $ hg sparse --import-rules $TESTTMP/rules_to_import -Tjson | |
136 [ | |
137 { | |
138 "exclude_rules_added": 1, | |
139 "files_added": 1, | |
140 "files_conflicting": 0, | |
141 "files_dropped": 1, | |
142 "include_rules_added": 1, | |
143 "profiles_added": 0 | |
144 } | |
145 ] | |
146 | |
147 If importing results in no new rules being added, no refresh should take place! | |
148 | |
149 $ cat > $TESTTMP/trap_sparse_refresh.py <<EOF | |
150 > from mercurial import error, extensions | |
151 > def extsetup(ui): | |
152 > def abort_refresh(ui, *args): | |
153 > raise error.Abort('sparse._refresh called!') | |
154 > def sparseloaded(loaded): | |
155 > if not loaded: | |
156 > return | |
157 > sparse = extensions.find('sparse') | |
158 > sparse._refresh = abort_refresh | |
159 > extensions.afterloaded('sparse', sparseloaded) | |
160 > EOF | |
161 $ cat >> $HGRCPATH <<EOF | |
162 > [extensions] | |
163 > trap_sparse_refresh=$TESTTMP/trap_sparse_refresh.py | |
164 > EOF | |
165 $ cat > $TESTTMP/rules_to_import <<EOF | |
166 > [include] | |
167 > *.py | |
168 > EOF | |
169 $ hg sparse --import-rules $TESTTMP/rules_to_import | |
170 | |
171 If an exception is raised during refresh, restore the existing rules again. | |
172 | |
173 $ cat > $TESTTMP/rules_to_import <<EOF | |
174 > [exclude] | |
175 > *.html | |
176 > EOF | |
177 $ hg sparse --import-rules $TESTTMP/rules_to_import | |
178 abort: sparse._refresh called! | |
179 [255] | |
180 $ cat .hg/sparse | |
181 %include webpage.sparse | |
182 [include] | |
183 *.py | |
184 *.txt | |
185 [exclude] | |
186 *.py |