Mercurial > hg
comparison tests/test-narrow-expanddirstate.t @ 36079:a2a6e724d61a
narrow: import experimental extension from narrowhg revision cb51d673e9c5
Adjustments:
* renamed src to hgext/narrow
* marked extension experimental
* added correct copyright header where it was missing
* updated hgrc extension enable line in library.sh
* renamed library.sh to narrow-library.sh
* dropped all files from repo root as they're not interesting
* dropped test-pyflakes.t, test-check-code.t and test-check-py3-compat.t
* renamed remaining tests to all be test-narrow-* when they didn't already
* fixed test-narrow-expanddirstate.t to refer to narrow and not narrowhg
* fixed tests that wanted `update -C .` instead of `merge --abort`
* corrected a two-space indent in narrowspec.py
* added a missing _() in narrowcommands.py
* fixed imports to pass the import checker
* narrow only adds its --include and --exclude to clone if sparse isn't
enabled to avoid breaking test-duplicateoptions.py. This is a kludge,
and we'll need to come up with a better solution in the future.
These were more or less the minimum to import something that would
pass tests and not create a bunch of files we'll never use.
Changes I intend to make as followups:
* rework the test-narrow-*-tree.t tests to use the new testcases
functionality in run-tests.py
* remove lots of monkeypatches of core things
Differential Revision: https://phab.mercurial-scm.org/D1974
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 29 Jan 2018 16:19:33 -0500 |
parents | |
children | 9fd8c2a3db5a |
comparison
equal
deleted
inserted
replaced
36078:7f68235f23ff | 36079:a2a6e724d61a |
---|---|
1 $ . "$TESTDIR/narrow-library.sh" | |
2 | |
3 $ hg init master | |
4 $ cd master | |
5 | |
6 $ mkdir inside | |
7 $ echo inside > inside/f1 | |
8 $ mkdir outside | |
9 $ echo outside > outside/f2 | |
10 $ mkdir patchdir | |
11 $ echo patch_this > patchdir/f3 | |
12 $ hg ci -Aqm 'initial' | |
13 | |
14 $ cd .. | |
15 | |
16 $ hg clone --narrow ssh://user@dummy/master narrow --include inside | |
17 requesting all changes | |
18 adding changesets | |
19 adding manifests | |
20 adding file changes | |
21 added 1 changesets with 1 changes to 1 files | |
22 new changesets dff6a2a6d433 | |
23 updating to branch default | |
24 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
25 | |
26 $ cd narrow | |
27 | |
28 $ mkdir outside | |
29 $ echo other_contents > outside/f2 | |
30 $ grep outside .hg/narrowspec | |
31 [1] | |
32 $ grep outside .hg/dirstate | |
33 [1] | |
34 $ hg status | |
35 | |
36 `hg status` did not add outside. | |
37 $ grep outside .hg/narrowspec | |
38 [1] | |
39 $ grep outside .hg/dirstate | |
40 [1] | |
41 | |
42 Unfortunately this is not really a candidate for adding to narrowhg proper, | |
43 since it depends on some other source for providing the manifests (when using | |
44 treemanifests) and file contents. Something like a virtual filesystem and/or | |
45 remotefilelog. We want to be useful when not using those systems, so we do not | |
46 have this method available in narrowhg proper at the moment. | |
47 $ cat > "$TESTTMP/expand_extension.py" <<EOF | |
48 > import os | |
49 > import sys | |
50 > | |
51 > from mercurial import extensions | |
52 > from mercurial import localrepo | |
53 > from mercurial import match as matchmod | |
54 > from mercurial import patch | |
55 > from mercurial import util as hgutil | |
56 > | |
57 > def expandnarrowspec(ui, repo, newincludes=None): | |
58 > if not newincludes: | |
59 > return | |
60 > import sys | |
61 > newincludes = set([newincludes]) | |
62 > narrowhg = extensions.find('narrow') | |
63 > includes, excludes = repo.narrowpats | |
64 > currentmatcher = narrowhg.narrowspec.match(repo.root, includes, excludes) | |
65 > includes = includes | newincludes | |
66 > if not repo.currenttransaction(): | |
67 > ui.develwarn('expandnarrowspec called outside of transaction!') | |
68 > repo.setnarrowpats(includes, excludes) | |
69 > newmatcher = narrowhg.narrowspec.match(repo.root, includes, excludes) | |
70 > added = matchmod.differencematcher(newmatcher, currentmatcher) | |
71 > for f in repo['.'].manifest().walk(added): | |
72 > repo.dirstate.normallookup(f) | |
73 > | |
74 > def makeds(ui, repo): | |
75 > def wrapds(orig, self): | |
76 > ds = orig(self) | |
77 > class expandingdirstate(ds.__class__): | |
78 > # Mercurial 4.4 uses this version. | |
79 > @hgutil.propertycache | |
80 > def _map(self): | |
81 > ret = super(expandingdirstate, self)._map | |
82 > with repo.wlock(), repo.lock(), repo.transaction( | |
83 > 'expandnarrowspec'): | |
84 > expandnarrowspec(ui, repo, os.environ.get('DIRSTATEINCLUDES')) | |
85 > return ret | |
86 > # Mercurial 4.3.3 and earlier uses this version. It seems that | |
87 > # narrowhg does not currently support this version, but we include | |
88 > # it just in case backwards compatibility is restored. | |
89 > def _read(self): | |
90 > ret = super(expandingdirstate, self)._read() | |
91 > with repo.wlock(), repo.lock(), repo.transaction( | |
92 > 'expandnarrowspec'): | |
93 > expandnarrowspec(ui, repo, os.environ.get('DIRSTATEINCLUDES')) | |
94 > return ret | |
95 > ds.__class__ = expandingdirstate | |
96 > return ds | |
97 > return wrapds | |
98 > | |
99 > def reposetup(ui, repo): | |
100 > extensions.wrapfilecache(localrepo.localrepository, 'dirstate', | |
101 > makeds(ui, repo)) | |
102 > def overridepatch(orig, *args, **kwargs): | |
103 > with repo.wlock(): | |
104 > expandnarrowspec(ui, repo, os.environ.get('PATCHINCLUDES')) | |
105 > return orig(*args, **kwargs) | |
106 > | |
107 > extensions.wrapfunction(patch, 'patch', overridepatch) | |
108 > EOF | |
109 $ cat >> ".hg/hgrc" <<EOF | |
110 > [extensions] | |
111 > expand_extension = $TESTTMP/expand_extension.py | |
112 > EOF | |
113 | |
114 Since we do not have the ability to rely on a virtual filesystem or | |
115 remotefilelog in the test, we just fake it by copying the data from the 'master' | |
116 repo. | |
117 $ cp -a ../master/.hg/store/data/* .hg/store/data | |
118 Do that for patchdir as well. | |
119 $ cp -a ../master/patchdir . | |
120 | |
121 `hg status` will now add outside, but not patchdir. | |
122 $ DIRSTATEINCLUDES=path:outside hg status | |
123 M outside/f2 | |
124 $ grep outside .hg/narrowspec | |
125 path:outside | |
126 $ grep outside .hg/dirstate > /dev/null | |
127 $ grep patchdir .hg/narrowspec | |
128 [1] | |
129 $ grep patchdir .hg/dirstate | |
130 [1] | |
131 | |
132 Get rid of the modification to outside/f2. | |
133 $ hg update -C . | |
134 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
135 | |
136 This patch will not apply cleanly at the moment, so `hg import` will break | |
137 $ cat > "$TESTTMP/foo.patch" <<EOF | |
138 > --- patchdir/f3 | |
139 > +++ patchdir/f3 | |
140 > @@ -1,1 +1,1 @@ | |
141 > -this should be "patch_this", but its not, so patch fails | |
142 > +this text is irrelevant | |
143 > EOF | |
144 $ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m ignored | |
145 applying $TESTTMP/foo.patch | |
146 patching file patchdir/f3 | |
147 Hunk #1 FAILED at 0 | |
148 1 out of 1 hunks FAILED -- saving rejects to file patchdir/f3.rej | |
149 abort: patch failed to apply | |
150 [255] | |
151 $ grep patchdir .hg/narrowspec | |
152 [1] | |
153 $ grep patchdir .hg/dirstate > /dev/null | |
154 [1] | |
155 | |
156 Let's make it apply cleanly and see that it *did* expand properly | |
157 $ cat > "$TESTTMP/foo.patch" <<EOF | |
158 > --- patchdir/f3 | |
159 > +++ patchdir/f3 | |
160 > @@ -1,1 +1,1 @@ | |
161 > -patch_this | |
162 > +patched_this | |
163 > EOF | |
164 $ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m message | |
165 applying $TESTTMP/foo.patch | |
166 $ cat patchdir/f3 | |
167 patched_this | |
168 $ grep patchdir .hg/narrowspec | |
169 path:patchdir | |
170 $ grep patchdir .hg/dirstate > /dev/null |