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