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