##// END OF EJS Templates
tests: update narrowspec when narrowspec, not dirstate, is accessed...
Martin von Zweigbergk -
r41069:92fde288 default
parent child Browse files
Show More
@@ -1,164 +1,158 b''
1 1 $ . "$TESTDIR/narrow-library.sh"
2 2
3 3 $ hg init master
4 4 $ cd master
5 5
6 6 $ mkdir inside
7 7 $ echo inside > inside/f1
8 8 $ mkdir outside
9 9 $ echo outside > outside/f2
10 10 $ mkdir patchdir
11 11 $ echo patch_this > patchdir/f3
12 12 $ hg ci -Aqm 'initial'
13 13
14 14 $ cd ..
15 15
16 16 $ hg clone --narrow ssh://user@dummy/master narrow --include inside
17 17 requesting all changes
18 18 adding changesets
19 19 adding manifests
20 20 adding file changes
21 21 added 1 changesets with 1 changes to 1 files
22 22 new changesets dff6a2a6d433
23 23 updating to branch default
24 24 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
25 25
26 26 $ cd narrow
27 27
28 28 $ mkdir outside
29 29 $ echo other_contents > outside/f2
30 30 $ hg tracked | grep outside
31 31 [1]
32 32 $ hg files | grep outside
33 33 [1]
34 34 $ hg status
35 35
36 36 `hg status` did not add outside.
37 37 $ hg tracked | grep outside
38 38 [1]
39 39 $ hg files | grep outside
40 40 [1]
41 41
42 42 Unfortunately this is not really a candidate for adding to narrowhg proper,
43 43 since it depends on some other source for providing the manifests (when using
44 44 treemanifests) and file contents. Something like a virtual filesystem and/or
45 45 remotefilelog. We want to be useful when not using those systems, so we do not
46 46 have this method available in narrowhg proper at the moment.
47 47 $ cat > "$TESTTMP/expand_extension.py" <<EOF
48 48 > import os
49 49 > import sys
50 50 >
51 51 > from mercurial import encoding
52 52 > from mercurial import extensions
53 53 > from mercurial import localrepo
54 54 > from mercurial import match as matchmod
55 55 > from mercurial import narrowspec
56 56 > from mercurial import patch
57 57 > from mercurial import util as hgutil
58 58 >
59 > narrowspecexpanded = False
59 60 > def expandnarrowspec(ui, repo, newincludes=None):
60 61 > if not newincludes:
61 62 > return
63 > if getattr(repo, '_narrowspecexpanded', False):
64 > return
65 > repo._narrowspecexpanded = True
62 66 > import sys
63 67 > newincludes = set([newincludes])
64 68 > includes, excludes = repo.narrowpats
65 69 > currentmatcher = narrowspec.match(repo.root, includes, excludes)
66 70 > includes = includes | newincludes
67 71 > if not repo.currenttransaction():
68 72 > ui.develwarn(b'expandnarrowspec called outside of transaction!')
69 73 > repo.setnarrowpats(includes, excludes)
70 74 > newmatcher = narrowspec.match(repo.root, includes, excludes)
71 75 > added = matchmod.differencematcher(newmatcher, currentmatcher)
72 76 > for f in repo[b'.'].manifest().walk(added):
73 77 > repo.dirstate.normallookup(f)
74 78 >
75 > def wrapds(ui, repo, ds):
76 > class expandingdirstate(ds.__class__):
77 > @hgutil.propertycache
78 > def _map(self):
79 > ret = super(expandingdirstate, self)._map
79 > def reposetup(ui, repo):
80 > class expandingrepo(repo.__class__):
81 > def narrowmatch(self, *args, **kwargs):
80 82 > with repo.wlock(), repo.lock(), repo.transaction(
81 83 > b'expandnarrowspec'):
82 84 > expandnarrowspec(ui, repo,
83 85 > encoding.environ.get(b'DIRSTATEINCLUDES'))
84 > return ret
85 > ds.__class__ = expandingdirstate
86 > return ds
87 >
88 > def reposetup(ui, repo):
89 > class expandingrepo(repo.__class__):
90 > def _makedirstate(self):
91 > dirstate = super(expandingrepo, self)._makedirstate()
92 > return wrapds(ui, repo, dirstate)
86 > return super(expandingrepo, self).narrowmatch(*args, **kwargs)
93 87 > repo.__class__ = expandingrepo
94 88 >
95 89 > def extsetup(unused_ui):
96 90 > def overridepatch(orig, ui, repo, *args, **kwargs):
97 91 > with repo.wlock():
98 92 > expandnarrowspec(ui, repo, encoding.environ.get(b'PATCHINCLUDES'))
99 93 > return orig(ui, repo, *args, **kwargs)
100 94 >
101 95 > extensions.wrapfunction(patch, b'patch', overridepatch)
102 96 > EOF
103 97 $ cat >> ".hg/hgrc" <<EOF
104 98 > [extensions]
105 99 > expand_extension = $TESTTMP/expand_extension.py
106 100 > EOF
107 101
108 102 Since we do not have the ability to rely on a virtual filesystem or
109 103 remotefilelog in the test, we just fake it by copying the data from the 'master'
110 104 repo.
111 105 $ cp -a ../master/.hg/store/data/* .hg/store/data
112 106 Do that for patchdir as well.
113 107 $ cp -a ../master/patchdir .
114 108
115 109 `hg status` will now add outside, but not patchdir.
116 110 $ DIRSTATEINCLUDES=path:outside hg status
117 111 M outside/f2
118 112 $ hg tracked | grep outside
119 113 I path:outside
120 114 $ hg files | grep outside > /dev/null
121 115 $ hg tracked | grep patchdir
122 116 [1]
123 117 $ hg files | grep patchdir
124 118 [1]
125 119
126 120 Get rid of the modification to outside/f2.
127 121 $ hg update -C .
128 122 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
129 123
130 124 This patch will not apply cleanly at the moment, so `hg import` will break
131 125 $ cat > "$TESTTMP/foo.patch" <<EOF
132 126 > --- patchdir/f3
133 127 > +++ patchdir/f3
134 128 > @@ -1,1 +1,1 @@
135 129 > -this should be "patch_this", but its not, so patch fails
136 130 > +this text is irrelevant
137 131 > EOF
138 132 $ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m ignored
139 133 applying $TESTTMP/foo.patch
140 134 patching file patchdir/f3
141 135 Hunk #1 FAILED at 0
142 136 1 out of 1 hunks FAILED -- saving rejects to file patchdir/f3.rej
143 137 abort: patch failed to apply
144 138 [255]
145 139 $ hg tracked | grep patchdir
146 140 [1]
147 141 $ hg files | grep patchdir > /dev/null
148 142 [1]
149 143
150 144 Let's make it apply cleanly and see that it *did* expand properly
151 145 $ cat > "$TESTTMP/foo.patch" <<EOF
152 146 > --- patchdir/f3
153 147 > +++ patchdir/f3
154 148 > @@ -1,1 +1,1 @@
155 149 > -patch_this
156 150 > +patched_this
157 151 > EOF
158 152 $ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m message
159 153 applying $TESTTMP/foo.patch
160 154 $ cat patchdir/f3
161 155 patched_this
162 156 $ hg tracked | grep patchdir
163 157 I path:patchdir
164 158 $ hg files | grep patchdir > /dev/null
General Comments 0
You need to be logged in to leave comments. Login now