##// END OF EJS Templates
tests: port extension in test-narrow-expanddirstate.t to Python 3...
Augie Fackler -
r36365:f6ddbcff default
parent child Browse files
Show More
@@ -1,160 +1,162
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 $ grep outside .hg/narrowspec
31 31 [1]
32 32 $ grep outside .hg/dirstate
33 33 [1]
34 34 $ hg status
35 35
36 36 `hg status` did not add outside.
37 37 $ grep outside .hg/narrowspec
38 38 [1]
39 39 $ grep outside .hg/dirstate
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 > from mercurial import encoding
51 52 > from mercurial import extensions
52 53 > from mercurial import localrepo
53 54 > from mercurial import match as matchmod
54 55 > from mercurial import narrowspec
55 56 > from mercurial import patch
56 57 > from mercurial import util as hgutil
57 58 >
58 59 > def expandnarrowspec(ui, repo, newincludes=None):
59 60 > if not newincludes:
60 61 > return
61 62 > import sys
62 63 > newincludes = set([newincludes])
63 64 > includes, excludes = repo.narrowpats
64 65 > currentmatcher = narrowspec.match(repo.root, includes, excludes)
65 66 > includes = includes | newincludes
66 67 > if not repo.currenttransaction():
67 > ui.develwarn('expandnarrowspec called outside of transaction!')
68 > ui.develwarn(b'expandnarrowspec called outside of transaction!')
68 69 > repo.setnarrowpats(includes, excludes)
69 70 > newmatcher = narrowspec.match(repo.root, includes, excludes)
70 71 > added = matchmod.differencematcher(newmatcher, currentmatcher)
71 > for f in repo['.'].manifest().walk(added):
72 > for f in repo[b'.'].manifest().walk(added):
72 73 > repo.dirstate.normallookup(f)
73 74 >
74 75 > def makeds(ui, repo):
75 76 > def wrapds(orig, self):
76 77 > ds = orig(self)
77 78 > class expandingdirstate(ds.__class__):
78 79 > @hgutil.propertycache
79 80 > def _map(self):
80 81 > ret = super(expandingdirstate, self)._map
81 82 > with repo.wlock(), repo.lock(), repo.transaction(
82 > 'expandnarrowspec'):
83 > expandnarrowspec(ui, repo, os.environ.get('DIRSTATEINCLUDES'))
83 > b'expandnarrowspec'):
84 > expandnarrowspec(ui, repo,
85 > encoding.environ.get(b'DIRSTATEINCLUDES'))
84 86 > return ret
85 87 > ds.__class__ = expandingdirstate
86 88 > return ds
87 89 > return wrapds
88 90 >
89 91 > def reposetup(ui, repo):
90 > extensions.wrapfilecache(localrepo.localrepository, 'dirstate',
92 > extensions.wrapfilecache(localrepo.localrepository, b'dirstate',
91 93 > makeds(ui, repo))
92 94 > def overridepatch(orig, *args, **kwargs):
93 95 > with repo.wlock():
94 > expandnarrowspec(ui, repo, os.environ.get('PATCHINCLUDES'))
96 > expandnarrowspec(ui, repo, encoding.environ.get(b'PATCHINCLUDES'))
95 97 > return orig(*args, **kwargs)
96 98 >
97 > extensions.wrapfunction(patch, 'patch', overridepatch)
99 > extensions.wrapfunction(patch, b'patch', overridepatch)
98 100 > EOF
99 101 $ cat >> ".hg/hgrc" <<EOF
100 102 > [extensions]
101 103 > expand_extension = $TESTTMP/expand_extension.py
102 104 > EOF
103 105
104 106 Since we do not have the ability to rely on a virtual filesystem or
105 107 remotefilelog in the test, we just fake it by copying the data from the 'master'
106 108 repo.
107 109 $ cp -a ../master/.hg/store/data/* .hg/store/data
108 110 Do that for patchdir as well.
109 111 $ cp -a ../master/patchdir .
110 112
111 113 `hg status` will now add outside, but not patchdir.
112 114 $ DIRSTATEINCLUDES=path:outside hg status
113 115 M outside/f2
114 116 $ grep outside .hg/narrowspec
115 117 path:outside
116 118 $ grep outside .hg/dirstate > /dev/null
117 119 $ grep patchdir .hg/narrowspec
118 120 [1]
119 121 $ grep patchdir .hg/dirstate
120 122 [1]
121 123
122 124 Get rid of the modification to outside/f2.
123 125 $ hg update -C .
124 126 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
125 127
126 128 This patch will not apply cleanly at the moment, so `hg import` will break
127 129 $ cat > "$TESTTMP/foo.patch" <<EOF
128 130 > --- patchdir/f3
129 131 > +++ patchdir/f3
130 132 > @@ -1,1 +1,1 @@
131 133 > -this should be "patch_this", but its not, so patch fails
132 134 > +this text is irrelevant
133 135 > EOF
134 136 $ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m ignored
135 137 applying $TESTTMP/foo.patch
136 138 patching file patchdir/f3
137 139 Hunk #1 FAILED at 0
138 140 1 out of 1 hunks FAILED -- saving rejects to file patchdir/f3.rej
139 141 abort: patch failed to apply
140 142 [255]
141 143 $ grep patchdir .hg/narrowspec
142 144 [1]
143 145 $ grep patchdir .hg/dirstate > /dev/null
144 146 [1]
145 147
146 148 Let's make it apply cleanly and see that it *did* expand properly
147 149 $ cat > "$TESTTMP/foo.patch" <<EOF
148 150 > --- patchdir/f3
149 151 > +++ patchdir/f3
150 152 > @@ -1,1 +1,1 @@
151 153 > -patch_this
152 154 > +patched_this
153 155 > EOF
154 156 $ PATCHINCLUDES=path:patchdir hg import -p0 -e "$TESTTMP/foo.patch" -m message
155 157 applying $TESTTMP/foo.patch
156 158 $ cat patchdir/f3
157 159 patched_this
158 160 $ grep patchdir .hg/narrowspec
159 161 path:patchdir
160 162 $ grep patchdir .hg/dirstate > /dev/null
General Comments 0
You need to be logged in to leave comments. Login now