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