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