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