##// END OF EJS Templates
cleanup: remove import of already imported module
Manuel Jacob -
r50177:d7f3f745 default
parent child Browse files
Show More
@@ -1,248 +1,246 b''
1 1 import os
2 2 import stat
3 3 import sys
4 4 from mercurial.node import hex
5 5 from mercurial import (
6 6 context,
7 7 diffutil,
8 8 encoding,
9 9 hg,
10 10 scmutil,
11 11 ui as uimod,
12 12 )
13 13
14 14 print_ = print
15 15
16 16
17 17 def print(*args, **kwargs):
18 18 """print() wrapper that flushes stdout buffers to avoid py3 buffer issues
19 19
20 20 We could also just write directly to sys.stdout.buffer the way the
21 21 ui object will, but this was easier for porting the test.
22 22 """
23 23 print_(*args, **kwargs)
24 24 sys.stdout.flush()
25 25
26 26
27 27 def printb(data, end=b'\n'):
28 28 out = getattr(sys.stdout, 'buffer', sys.stdout)
29 29 out.write(data + end)
30 30 out.flush()
31 31
32 32
33 33 ui = uimod.ui.load()
34 34
35 35 repo = hg.repository(ui, b'test1', create=1)
36 36 os.chdir('test1')
37 37
38 38 # create 'foo' with fixed time stamp
39 39 f = open('foo', 'wb')
40 40 f.write(b'foo\n')
41 41 f.close()
42 42 os.utime('foo', (1000, 1000))
43 43
44 44 # add+commit 'foo'
45 45 repo[None].add([b'foo'])
46 46 repo.commit(text=b'commit1', date=b"0 0")
47 47
48 48 d = repo[None][b'foo'].date()
49 49 if os.name == 'nt':
50 50 d = d[:2]
51 51 print("workingfilectx.date = (%d, %d)" % d)
52 52
53 53 # test memctx with non-ASCII commit message
54 54
55 55
56 56 def filectxfn(repo, memctx, path):
57 57 return context.memfilectx(repo, memctx, b"foo", b"")
58 58
59 59
60 60 ctx = context.memctx(
61 61 repo,
62 62 [b'tip', None],
63 63 encoding.tolocal(b"Gr\xc3\xbcezi!"),
64 64 [b"foo"],
65 65 filectxfn,
66 66 )
67 67 ctx.commit()
68 68 for enc in "ASCII", "Latin-1", "UTF-8":
69 69 encoding.encoding = enc
70 70 printb(b"%-8s: %s" % (enc.encode('ascii'), repo[b"tip"].description()))
71 71
72 72 # test performing a status
73 73
74 74
75 75 def getfilectx(repo, memctx, f):
76 76 fctx = memctx.p1()[f]
77 77 data, flags = fctx.data(), fctx.flags()
78 78 if f == b'foo':
79 79 data += b'bar\n'
80 80 return context.memfilectx(
81 81 repo, memctx, f, data, b'l' in flags, b'x' in flags
82 82 )
83 83
84 84
85 85 ctxa = repo[0]
86 86 ctxb = context.memctx(
87 87 repo,
88 88 [ctxa.node(), None],
89 89 b"test diff",
90 90 [b"foo"],
91 91 getfilectx,
92 92 ctxa.user(),
93 93 ctxa.date(),
94 94 )
95 95
96 96 print(ctxb.status(ctxa))
97 97
98 98 # test performing a diff on a memctx
99 99 diffopts = diffutil.diffallopts(repo.ui, {b'git': True})
100 100 for d in ctxb.diff(ctxa, opts=diffopts):
101 101 printb(d, end=b'')
102 102
103 103 # test safeness and correctness of "ctx.status()"
104 104 print('= checking context.status():')
105 105
106 106 # ancestor "wcctx ~ 2"
107 107 actx2 = repo[b'.']
108 108
109 109 repo.wwrite(b'bar-m', b'bar-m\n', b'')
110 110 repo.wwrite(b'bar-r', b'bar-r\n', b'')
111 111 repo[None].add([b'bar-m', b'bar-r'])
112 112 repo.commit(text=b'add bar-m, bar-r', date=b"0 0")
113 113
114 114 # ancestor "wcctx ~ 1"
115 115 actx1 = repo[b'.']
116 116
117 117 repo.wwrite(b'bar-m', b'bar-m bar-m\n', b'')
118 118 repo.wwrite(b'bar-a', b'bar-a\n', b'')
119 119 repo[None].add([b'bar-a'])
120 120 repo[None].forget([b'bar-r'])
121 121
122 122 # status at this point:
123 123 # M bar-m
124 124 # A bar-a
125 125 # R bar-r
126 126 # C foo
127 127
128 from mercurial import scmutil
129
130 128 print('== checking workingctx.status:')
131 129
132 130 wctx = repo[None]
133 131 print('wctx._status=%s' % (str(wctx._status)))
134 132
135 133 print('=== with "pattern match":')
136 134 print(
137 135 actx1.status(other=wctx, match=scmutil.matchfiles(repo, [b'bar-m', b'foo']))
138 136 )
139 137 print('wctx._status=%s' % (str(wctx._status)))
140 138 print(
141 139 actx2.status(other=wctx, match=scmutil.matchfiles(repo, [b'bar-m', b'foo']))
142 140 )
143 141 print('wctx._status=%s' % (str(wctx._status)))
144 142
145 143 print('=== with "always match" and "listclean=True":')
146 144 print(actx1.status(other=wctx, listclean=True))
147 145 print('wctx._status=%s' % (str(wctx._status)))
148 146 print(actx2.status(other=wctx, listclean=True))
149 147 print('wctx._status=%s' % (str(wctx._status)))
150 148
151 149 print("== checking workingcommitctx.status:")
152 150
153 151 wcctx = context.workingcommitctx(
154 152 repo,
155 153 scmutil.status([b'bar-m'], [b'bar-a'], [], [], [], [], []),
156 154 text=b'',
157 155 date=b'0 0',
158 156 )
159 157 print('wcctx._status=%s' % (str(wcctx._status)))
160 158
161 159 print('=== with "always match":')
162 160 print(actx1.status(other=wcctx))
163 161 print('wcctx._status=%s' % (str(wcctx._status)))
164 162 print(actx2.status(other=wcctx))
165 163 print('wcctx._status=%s' % (str(wcctx._status)))
166 164
167 165 print('=== with "always match" and "listclean=True":')
168 166 print(actx1.status(other=wcctx, listclean=True))
169 167 print('wcctx._status=%s' % (str(wcctx._status)))
170 168 print(actx2.status(other=wcctx, listclean=True))
171 169 print('wcctx._status=%s' % (str(wcctx._status)))
172 170
173 171 print('=== with "pattern match":')
174 172 print(
175 173 actx1.status(
176 174 other=wcctx, match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])
177 175 )
178 176 )
179 177 print('wcctx._status=%s' % (str(wcctx._status)))
180 178 print(
181 179 actx2.status(
182 180 other=wcctx, match=scmutil.matchfiles(repo, [b'bar-m', b'foo'])
183 181 )
184 182 )
185 183 print('wcctx._status=%s' % (str(wcctx._status)))
186 184
187 185 print('=== with "pattern match" and "listclean=True":')
188 186 print(
189 187 actx1.status(
190 188 other=wcctx,
191 189 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
192 190 listclean=True,
193 191 )
194 192 )
195 193 print('wcctx._status=%s' % (str(wcctx._status)))
196 194 print(
197 195 actx2.status(
198 196 other=wcctx,
199 197 match=scmutil.matchfiles(repo, [b'bar-r', b'foo']),
200 198 listclean=True,
201 199 )
202 200 )
203 201 print('wcctx._status=%s' % (str(wcctx._status)))
204 202
205 203 os.chdir('..')
206 204
207 205 # test manifestlog being changed
208 206 print('== commit with manifestlog invalidated')
209 207
210 208 repo = hg.repository(ui, b'test2', create=1)
211 209 os.chdir('test2')
212 210
213 211 # make some commits
214 212 for i in [b'1', b'2', b'3']:
215 213 with open(i, 'wb') as f:
216 214 f.write(i)
217 215 status = scmutil.status([], [i], [], [], [], [], [])
218 216 ctx = context.workingcommitctx(
219 217 repo, status, text=i, user=b'test@test.com', date=(0, 0)
220 218 )
221 219 ctx.p1().manifest() # side effect: cache manifestctx
222 220 n = repo.commitctx(ctx)
223 221 printb(b'commit %s: %s' % (i, hex(n)))
224 222
225 223 # touch 00manifest.i mtime so storecache could expire.
226 224 # repo.__dict__['manifestlog'] is deleted by transaction releasefn.
227 225 st = repo.svfs.stat(b'00manifest.i')
228 226 repo.svfs.utime(
229 227 b'00manifest.i', (st[stat.ST_MTIME] + 1, st[stat.ST_MTIME] + 1)
230 228 )
231 229
232 230 # read the file just committed
233 231 try:
234 232 if repo[n][i].data() != i:
235 233 print('data mismatch')
236 234 except Exception as ex:
237 235 print('cannot read data: %r' % ex)
238 236
239 237 with repo.wlock(), repo.lock(), repo.transaction(b'test'):
240 238 with open(b'4', 'wb') as f:
241 239 f.write(b'4')
242 240 repo.dirstate.set_tracked(b'4')
243 241 repo.commit(b'4')
244 242 revsbefore = len(repo.changelog)
245 243 repo.invalidate(clearfilecache=True)
246 244 revsafter = len(repo.changelog)
247 245 if revsbefore != revsafter:
248 246 print('changeset lost by repo.invalidate()')
General Comments 0
You need to be logged in to leave comments. Login now