Show More
@@ -1,148 +1,148 b'' | |||
|
1 | 1 | from __future__ import absolute_import, print_function |
|
2 | 2 | import os |
|
3 | 3 | from mercurial import ( |
|
4 | 4 | context, |
|
5 | 5 | encoding, |
|
6 | 6 | hg, |
|
7 | ui, | |
|
7 | ui as uimod, | |
|
8 | 8 | ) |
|
9 | 9 | |
|
10 | u = ui.ui() | |
|
10 | u = uimod.ui() | |
|
11 | 11 | |
|
12 | 12 | repo = hg.repository(u, 'test1', create=1) |
|
13 | 13 | os.chdir('test1') |
|
14 | 14 | |
|
15 | 15 | # create 'foo' with fixed time stamp |
|
16 | 16 | f = open('foo', 'wb') |
|
17 | 17 | f.write('foo\n') |
|
18 | 18 | f.close() |
|
19 | 19 | os.utime('foo', (1000, 1000)) |
|
20 | 20 | |
|
21 | 21 | # add+commit 'foo' |
|
22 | 22 | repo[None].add(['foo']) |
|
23 | 23 | repo.commit(text='commit1', date="0 0") |
|
24 | 24 | |
|
25 | 25 | if os.name == 'nt': |
|
26 | 26 | d = repo[None]['foo'].date() |
|
27 | 27 | print("workingfilectx.date = (%d, %d)" % (d[0], d[1])) |
|
28 | 28 | else: |
|
29 | 29 | print("workingfilectx.date =", repo[None]['foo'].date()) |
|
30 | 30 | |
|
31 | 31 | # test memctx with non-ASCII commit message |
|
32 | 32 | |
|
33 | 33 | def filectxfn(repo, memctx, path): |
|
34 | 34 | return context.memfilectx(repo, "foo", "") |
|
35 | 35 | |
|
36 | 36 | ctx = context.memctx(repo, ['tip', None], |
|
37 | 37 | encoding.tolocal("Gr\xc3\xbcezi!"), |
|
38 | 38 | ["foo"], filectxfn) |
|
39 | 39 | ctx.commit() |
|
40 | 40 | for enc in "ASCII", "Latin-1", "UTF-8": |
|
41 | 41 | encoding.encoding = enc |
|
42 | 42 | print("%-8s: %s" % (enc, repo["tip"].description())) |
|
43 | 43 | |
|
44 | 44 | # test performing a status |
|
45 | 45 | |
|
46 | 46 | def getfilectx(repo, memctx, f): |
|
47 | 47 | fctx = memctx.parents()[0][f] |
|
48 | 48 | data, flags = fctx.data(), fctx.flags() |
|
49 | 49 | if f == 'foo': |
|
50 | 50 | data += 'bar\n' |
|
51 | 51 | return context.memfilectx(repo, f, data, 'l' in flags, 'x' in flags) |
|
52 | 52 | |
|
53 | 53 | ctxa = repo.changectx(0) |
|
54 | 54 | ctxb = context.memctx(repo, [ctxa.node(), None], "test diff", ["foo"], |
|
55 | 55 | getfilectx, ctxa.user(), ctxa.date()) |
|
56 | 56 | |
|
57 | 57 | print(ctxb.status(ctxa)) |
|
58 | 58 | |
|
59 | 59 | # test performing a diff on a memctx |
|
60 | 60 | |
|
61 | 61 | for d in ctxb.diff(ctxa, git=True): |
|
62 | 62 | print(d) |
|
63 | 63 | |
|
64 | 64 | # test safeness and correctness of "ctx.status()" |
|
65 | 65 | print('= checking context.status():') |
|
66 | 66 | |
|
67 | 67 | # ancestor "wcctx ~ 2" |
|
68 | 68 | actx2 = repo['.'] |
|
69 | 69 | |
|
70 | 70 | repo.wwrite('bar-m', 'bar-m\n', '') |
|
71 | 71 | repo.wwrite('bar-r', 'bar-r\n', '') |
|
72 | 72 | repo[None].add(['bar-m', 'bar-r']) |
|
73 | 73 | repo.commit(text='add bar-m, bar-r', date="0 0") |
|
74 | 74 | |
|
75 | 75 | # ancestor "wcctx ~ 1" |
|
76 | 76 | actx1 = repo['.'] |
|
77 | 77 | |
|
78 | 78 | repo.wwrite('bar-m', 'bar-m bar-m\n', '') |
|
79 | 79 | repo.wwrite('bar-a', 'bar-a\n', '') |
|
80 | 80 | repo[None].add(['bar-a']) |
|
81 | 81 | repo[None].forget(['bar-r']) |
|
82 | 82 | |
|
83 | 83 | # status at this point: |
|
84 | 84 | # M bar-m |
|
85 | 85 | # A bar-a |
|
86 | 86 | # R bar-r |
|
87 | 87 | # C foo |
|
88 | 88 | |
|
89 | 89 | from mercurial import scmutil |
|
90 | 90 | |
|
91 | 91 | print('== checking workingctx.status:') |
|
92 | 92 | |
|
93 | 93 | wctx = repo[None] |
|
94 | 94 | print('wctx._status=%s' % (str(wctx._status))) |
|
95 | 95 | |
|
96 | 96 | print('=== with "pattern match":') |
|
97 | 97 | print(actx1.status(other=wctx, |
|
98 | 98 | match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) |
|
99 | 99 | print('wctx._status=%s' % (str(wctx._status))) |
|
100 | 100 | print(actx2.status(other=wctx, |
|
101 | 101 | match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) |
|
102 | 102 | print('wctx._status=%s' % (str(wctx._status))) |
|
103 | 103 | |
|
104 | 104 | print('=== with "always match" and "listclean=True":') |
|
105 | 105 | print(actx1.status(other=wctx, listclean=True)) |
|
106 | 106 | print('wctx._status=%s' % (str(wctx._status))) |
|
107 | 107 | print(actx2.status(other=wctx, listclean=True)) |
|
108 | 108 | print('wctx._status=%s' % (str(wctx._status))) |
|
109 | 109 | |
|
110 | 110 | print("== checking workingcommitctx.status:") |
|
111 | 111 | |
|
112 | 112 | wcctx = context.workingcommitctx(repo, |
|
113 | 113 | scmutil.status(['bar-m'], |
|
114 | 114 | ['bar-a'], |
|
115 | 115 | [], |
|
116 | 116 | [], [], [], []), |
|
117 | 117 | text='', date='0 0') |
|
118 | 118 | print('wcctx._status=%s' % (str(wcctx._status))) |
|
119 | 119 | |
|
120 | 120 | print('=== with "always match":') |
|
121 | 121 | print(actx1.status(other=wcctx)) |
|
122 | 122 | print('wcctx._status=%s' % (str(wcctx._status))) |
|
123 | 123 | print(actx2.status(other=wcctx)) |
|
124 | 124 | print('wcctx._status=%s' % (str(wcctx._status))) |
|
125 | 125 | |
|
126 | 126 | print('=== with "always match" and "listclean=True":') |
|
127 | 127 | print(actx1.status(other=wcctx, listclean=True)) |
|
128 | 128 | print('wcctx._status=%s' % (str(wcctx._status))) |
|
129 | 129 | print(actx2.status(other=wcctx, listclean=True)) |
|
130 | 130 | print('wcctx._status=%s' % (str(wcctx._status))) |
|
131 | 131 | |
|
132 | 132 | print('=== with "pattern match":') |
|
133 | 133 | print(actx1.status(other=wcctx, |
|
134 | 134 | match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) |
|
135 | 135 | print('wcctx._status=%s' % (str(wcctx._status))) |
|
136 | 136 | print(actx2.status(other=wcctx, |
|
137 | 137 | match=scmutil.matchfiles(repo, ['bar-m', 'foo']))) |
|
138 | 138 | print('wcctx._status=%s' % (str(wcctx._status))) |
|
139 | 139 | |
|
140 | 140 | print('=== with "pattern match" and "listclean=True":') |
|
141 | 141 | print(actx1.status(other=wcctx, |
|
142 | 142 | match=scmutil.matchfiles(repo, ['bar-r', 'foo']), |
|
143 | 143 | listclean=True)) |
|
144 | 144 | print('wcctx._status=%s' % (str(wcctx._status))) |
|
145 | 145 | print(actx2.status(other=wcctx, |
|
146 | 146 | match=scmutil.matchfiles(repo, ['bar-r', 'foo']), |
|
147 | 147 | listclean=True)) |
|
148 | 148 | print('wcctx._status=%s' % (str(wcctx._status))) |
General Comments 0
You need to be logged in to leave comments.
Login now