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