Show More
@@ -0,0 +1,21 b'' | |||||
|
1 | #!/bin/sh -x | |||
|
2 | ||||
|
3 | mkdir t | |||
|
4 | cd t | |||
|
5 | hg init | |||
|
6 | echo This is file a1 > a | |||
|
7 | echo This is file b1 > b | |||
|
8 | hg add a b | |||
|
9 | hg commit -t "commit #0" -d "0 0" -u user | |||
|
10 | echo This is file b22 > b | |||
|
11 | hg commit -t"comment #1" -d "0 0" -u user | |||
|
12 | hg update 0 | |||
|
13 | rm b | |||
|
14 | hg commit -A -t"comment #2" -d "0 0" -u user | |||
|
15 | # in theory, we shouldn't need the "yes k" below, but it prevents | |||
|
16 | # this test from hanging when "hg update" erroneously prompts the | |||
|
17 | # user for "keep or delete" | |||
|
18 | yes k | hg update 1 | |||
|
19 | # we exit with 0 to avoid the unavoidable SIGPIPE from above causing | |||
|
20 | # us to fail this test | |||
|
21 | exit 0 |
@@ -0,0 +1,18 b'' | |||||
|
1 | + mkdir t | |||
|
2 | + cd t | |||
|
3 | + hg init | |||
|
4 | + echo This is file a1 | |||
|
5 | + echo This is file b1 | |||
|
6 | + hg add a b | |||
|
7 | + hg commit -t 'commit #0' -d '0 0' -u user | |||
|
8 | + echo This is file b22 | |||
|
9 | + hg commit '-tcomment #1' -d '0 0' -u user | |||
|
10 | + hg update 0 | |||
|
11 | + rm b | |||
|
12 | + hg commit -A '-tcomment #2' -d '0 0' -u user | |||
|
13 | + yes k | |||
|
14 | + hg update 1 | |||
|
15 | this update spans a branch affecting the following files: | |||
|
16 | aborting update spanning branches! | |||
|
17 | (use update -m to perform a branch merge) | |||
|
18 | + exit 0 |
@@ -1,1448 +1,1452 b'' | |||||
1 | # hg.py - repository classes for mercurial |
|
1 | # hg.py - repository classes for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | import sys, struct, os |
|
8 | import sys, struct, os | |
9 | from revlog import * |
|
9 | from revlog import * | |
10 | from demandload import * |
|
10 | from demandload import * | |
11 | demandload(globals(), "re lock urllib urllib2 transaction time socket") |
|
11 | demandload(globals(), "re lock urllib urllib2 transaction time socket") | |
12 | demandload(globals(), "tempfile httprangereader difflib") |
|
12 | demandload(globals(), "tempfile httprangereader difflib") | |
13 |
|
13 | |||
14 | def is_exec(f): |
|
14 | def is_exec(f): | |
15 | return (os.stat(f).st_mode & 0100 != 0) |
|
15 | return (os.stat(f).st_mode & 0100 != 0) | |
16 |
|
16 | |||
17 | def set_exec(f, mode): |
|
17 | def set_exec(f, mode): | |
18 | s = os.stat(f).st_mode |
|
18 | s = os.stat(f).st_mode | |
19 | if (s & 0100 != 0) == mode: |
|
19 | if (s & 0100 != 0) == mode: | |
20 | return |
|
20 | return | |
21 | if mode: |
|
21 | if mode: | |
22 | # Turn on +x for every +r bit when making a file executable |
|
22 | # Turn on +x for every +r bit when making a file executable | |
23 | # and obey umask. |
|
23 | # and obey umask. | |
24 | umask = os.umask(0) |
|
24 | umask = os.umask(0) | |
25 | os.umask(umask) |
|
25 | os.umask(umask) | |
26 | os.chmod(f, s | (s & 0444) >> 2 & ~umask) |
|
26 | os.chmod(f, s | (s & 0444) >> 2 & ~umask) | |
27 | else: |
|
27 | else: | |
28 | os.chmod(f, s & 0666) |
|
28 | os.chmod(f, s & 0666) | |
29 |
|
29 | |||
30 | class filelog(revlog): |
|
30 | class filelog(revlog): | |
31 | def __init__(self, opener, path): |
|
31 | def __init__(self, opener, path): | |
32 | revlog.__init__(self, opener, |
|
32 | revlog.__init__(self, opener, | |
33 | os.path.join("data", path + ".i"), |
|
33 | os.path.join("data", path + ".i"), | |
34 | os.path.join("data", path + ".d")) |
|
34 | os.path.join("data", path + ".d")) | |
35 |
|
35 | |||
36 | def read(self, node): |
|
36 | def read(self, node): | |
37 | t = self.revision(node) |
|
37 | t = self.revision(node) | |
38 | if t[:2] != '\1\n': |
|
38 | if t[:2] != '\1\n': | |
39 | return t |
|
39 | return t | |
40 | s = t.find('\1\n', 2) |
|
40 | s = t.find('\1\n', 2) | |
41 | return t[s+2:] |
|
41 | return t[s+2:] | |
42 |
|
42 | |||
43 | def readmeta(self, node): |
|
43 | def readmeta(self, node): | |
44 | t = self.revision(node) |
|
44 | t = self.revision(node) | |
45 | if t[:2] != '\1\n': |
|
45 | if t[:2] != '\1\n': | |
46 | return t |
|
46 | return t | |
47 | s = t.find('\1\n', 2) |
|
47 | s = t.find('\1\n', 2) | |
48 | mt = t[2:s] |
|
48 | mt = t[2:s] | |
49 | for l in mt.splitlines(): |
|
49 | for l in mt.splitlines(): | |
50 | k, v = l.split(": ", 1) |
|
50 | k, v = l.split(": ", 1) | |
51 | m[k] = v |
|
51 | m[k] = v | |
52 | return m |
|
52 | return m | |
53 |
|
53 | |||
54 | def add(self, text, meta, transaction, link, p1=None, p2=None): |
|
54 | def add(self, text, meta, transaction, link, p1=None, p2=None): | |
55 | if meta or text[:2] == '\1\n': |
|
55 | if meta or text[:2] == '\1\n': | |
56 | mt = "" |
|
56 | mt = "" | |
57 | if meta: |
|
57 | if meta: | |
58 | mt = [ "%s: %s\n" % (k, v) for k,v in meta.items() ] |
|
58 | mt = [ "%s: %s\n" % (k, v) for k,v in meta.items() ] | |
59 | text = "\1\n" + "".join(mt) + "\1\n" + text |
|
59 | text = "\1\n" + "".join(mt) + "\1\n" + text | |
60 | return self.addrevision(text, transaction, link, p1, p2) |
|
60 | return self.addrevision(text, transaction, link, p1, p2) | |
61 |
|
61 | |||
62 | def annotate(self, node): |
|
62 | def annotate(self, node): | |
63 |
|
63 | |||
64 | def decorate(text, rev): |
|
64 | def decorate(text, rev): | |
65 | return [(rev, l) for l in text.splitlines(1)] |
|
65 | return [(rev, l) for l in text.splitlines(1)] | |
66 |
|
66 | |||
67 | def strip(annotation): |
|
67 | def strip(annotation): | |
68 | return [e[1] for e in annotation] |
|
68 | return [e[1] for e in annotation] | |
69 |
|
69 | |||
70 | def pair(parent, child): |
|
70 | def pair(parent, child): | |
71 | new = [] |
|
71 | new = [] | |
72 | sm = difflib.SequenceMatcher(None, strip(parent), strip(child)) |
|
72 | sm = difflib.SequenceMatcher(None, strip(parent), strip(child)) | |
73 | for o, m, n, s, t in sm.get_opcodes(): |
|
73 | for o, m, n, s, t in sm.get_opcodes(): | |
74 | if o == 'equal': |
|
74 | if o == 'equal': | |
75 | new += parent[m:n] |
|
75 | new += parent[m:n] | |
76 | else: |
|
76 | else: | |
77 | new += child[s:t] |
|
77 | new += child[s:t] | |
78 | return new |
|
78 | return new | |
79 |
|
79 | |||
80 | # find all ancestors |
|
80 | # find all ancestors | |
81 | needed = {node:1} |
|
81 | needed = {node:1} | |
82 | visit = [node] |
|
82 | visit = [node] | |
83 | while visit: |
|
83 | while visit: | |
84 | n = visit.pop(0) |
|
84 | n = visit.pop(0) | |
85 | for p in self.parents(n): |
|
85 | for p in self.parents(n): | |
86 | if p not in needed: |
|
86 | if p not in needed: | |
87 | needed[p] = 1 |
|
87 | needed[p] = 1 | |
88 | visit.append(p) |
|
88 | visit.append(p) | |
89 | else: |
|
89 | else: | |
90 | # count how many times we'll use this |
|
90 | # count how many times we'll use this | |
91 | needed[p] += 1 |
|
91 | needed[p] += 1 | |
92 |
|
92 | |||
93 | # sort by revision which is a topological order |
|
93 | # sort by revision which is a topological order | |
94 | visit = needed.keys() |
|
94 | visit = needed.keys() | |
95 | visit = [ (self.rev(n), n) for n in visit ] |
|
95 | visit = [ (self.rev(n), n) for n in visit ] | |
96 | visit.sort() |
|
96 | visit.sort() | |
97 | visit = [ p[1] for p in visit ] |
|
97 | visit = [ p[1] for p in visit ] | |
98 | hist = {} |
|
98 | hist = {} | |
99 |
|
99 | |||
100 | for n in visit: |
|
100 | for n in visit: | |
101 | curr = decorate(self.read(n), self.linkrev(n)) |
|
101 | curr = decorate(self.read(n), self.linkrev(n)) | |
102 | for p in self.parents(n): |
|
102 | for p in self.parents(n): | |
103 | if p != nullid: |
|
103 | if p != nullid: | |
104 | curr = pair(hist[p], curr) |
|
104 | curr = pair(hist[p], curr) | |
105 | # trim the history of unneeded revs |
|
105 | # trim the history of unneeded revs | |
106 | needed[p] -= 1 |
|
106 | needed[p] -= 1 | |
107 | if not needed[p]: |
|
107 | if not needed[p]: | |
108 | del hist[p] |
|
108 | del hist[p] | |
109 | hist[n] = curr |
|
109 | hist[n] = curr | |
110 |
|
110 | |||
111 | return hist[n] |
|
111 | return hist[n] | |
112 |
|
112 | |||
113 | class manifest(revlog): |
|
113 | class manifest(revlog): | |
114 | def __init__(self, opener): |
|
114 | def __init__(self, opener): | |
115 | self.mapcache = None |
|
115 | self.mapcache = None | |
116 | self.listcache = None |
|
116 | self.listcache = None | |
117 | self.addlist = None |
|
117 | self.addlist = None | |
118 | revlog.__init__(self, opener, "00manifest.i", "00manifest.d") |
|
118 | revlog.__init__(self, opener, "00manifest.i", "00manifest.d") | |
119 |
|
119 | |||
120 | def read(self, node): |
|
120 | def read(self, node): | |
121 | if node == nullid: return {} # don't upset local cache |
|
121 | if node == nullid: return {} # don't upset local cache | |
122 | if self.mapcache and self.mapcache[0] == node: |
|
122 | if self.mapcache and self.mapcache[0] == node: | |
123 | return self.mapcache[1].copy() |
|
123 | return self.mapcache[1].copy() | |
124 | text = self.revision(node) |
|
124 | text = self.revision(node) | |
125 | map = {} |
|
125 | map = {} | |
126 | flag = {} |
|
126 | flag = {} | |
127 | self.listcache = (text, text.splitlines(1)) |
|
127 | self.listcache = (text, text.splitlines(1)) | |
128 | for l in self.listcache[1]: |
|
128 | for l in self.listcache[1]: | |
129 | (f, n) = l.split('\0') |
|
129 | (f, n) = l.split('\0') | |
130 | map[f] = bin(n[:40]) |
|
130 | map[f] = bin(n[:40]) | |
131 | flag[f] = (n[40:-1] == "x") |
|
131 | flag[f] = (n[40:-1] == "x") | |
132 | self.mapcache = (node, map, flag) |
|
132 | self.mapcache = (node, map, flag) | |
133 | return map |
|
133 | return map | |
134 |
|
134 | |||
135 | def readflags(self, node): |
|
135 | def readflags(self, node): | |
136 | if node == nullid: return {} # don't upset local cache |
|
136 | if node == nullid: return {} # don't upset local cache | |
137 | if not self.mapcache or self.mapcache[0] != node: |
|
137 | if not self.mapcache or self.mapcache[0] != node: | |
138 | self.read(node) |
|
138 | self.read(node) | |
139 | return self.mapcache[2] |
|
139 | return self.mapcache[2] | |
140 |
|
140 | |||
141 | def diff(self, a, b): |
|
141 | def diff(self, a, b): | |
142 | # this is sneaky, as we're not actually using a and b |
|
142 | # this is sneaky, as we're not actually using a and b | |
143 | if self.listcache and self.addlist and self.listcache[0] == a: |
|
143 | if self.listcache and self.addlist and self.listcache[0] == a: | |
144 | d = mdiff.diff(self.listcache[1], self.addlist, 1) |
|
144 | d = mdiff.diff(self.listcache[1], self.addlist, 1) | |
145 | if mdiff.patch(a, d) != b: |
|
145 | if mdiff.patch(a, d) != b: | |
146 | sys.stderr.write("*** sortdiff failed, falling back ***\n") |
|
146 | sys.stderr.write("*** sortdiff failed, falling back ***\n") | |
147 | return mdiff.textdiff(a, b) |
|
147 | return mdiff.textdiff(a, b) | |
148 | return d |
|
148 | return d | |
149 | else: |
|
149 | else: | |
150 | return mdiff.textdiff(a, b) |
|
150 | return mdiff.textdiff(a, b) | |
151 |
|
151 | |||
152 | def add(self, map, flags, transaction, link, p1=None, p2=None): |
|
152 | def add(self, map, flags, transaction, link, p1=None, p2=None): | |
153 | files = map.keys() |
|
153 | files = map.keys() | |
154 | files.sort() |
|
154 | files.sort() | |
155 |
|
155 | |||
156 | self.addlist = ["%s\000%s%s\n" % |
|
156 | self.addlist = ["%s\000%s%s\n" % | |
157 | (f, hex(map[f]), flags[f] and "x" or '') |
|
157 | (f, hex(map[f]), flags[f] and "x" or '') | |
158 | for f in files] |
|
158 | for f in files] | |
159 | text = "".join(self.addlist) |
|
159 | text = "".join(self.addlist) | |
160 |
|
160 | |||
161 | n = self.addrevision(text, transaction, link, p1, p2) |
|
161 | n = self.addrevision(text, transaction, link, p1, p2) | |
162 | self.mapcache = (n, map, flags) |
|
162 | self.mapcache = (n, map, flags) | |
163 | self.listcache = (text, self.addlist) |
|
163 | self.listcache = (text, self.addlist) | |
164 | self.addlist = None |
|
164 | self.addlist = None | |
165 |
|
165 | |||
166 | return n |
|
166 | return n | |
167 |
|
167 | |||
168 | class changelog(revlog): |
|
168 | class changelog(revlog): | |
169 | def __init__(self, opener): |
|
169 | def __init__(self, opener): | |
170 | revlog.__init__(self, opener, "00changelog.i", "00changelog.d") |
|
170 | revlog.__init__(self, opener, "00changelog.i", "00changelog.d") | |
171 |
|
171 | |||
172 | def extract(self, text): |
|
172 | def extract(self, text): | |
173 | if not text: |
|
173 | if not text: | |
174 | return (nullid, "", "0", [], "") |
|
174 | return (nullid, "", "0", [], "") | |
175 | last = text.index("\n\n") |
|
175 | last = text.index("\n\n") | |
176 | desc = text[last + 2:] |
|
176 | desc = text[last + 2:] | |
177 | l = text[:last].splitlines() |
|
177 | l = text[:last].splitlines() | |
178 | manifest = bin(l[0]) |
|
178 | manifest = bin(l[0]) | |
179 | user = l[1] |
|
179 | user = l[1] | |
180 | date = l[2] |
|
180 | date = l[2] | |
181 | files = l[3:] |
|
181 | files = l[3:] | |
182 | return (manifest, user, date, files, desc) |
|
182 | return (manifest, user, date, files, desc) | |
183 |
|
183 | |||
184 | def read(self, node): |
|
184 | def read(self, node): | |
185 | return self.extract(self.revision(node)) |
|
185 | return self.extract(self.revision(node)) | |
186 |
|
186 | |||
187 | def add(self, manifest, list, desc, transaction, p1=None, p2=None, |
|
187 | def add(self, manifest, list, desc, transaction, p1=None, p2=None, | |
188 | user=None, date=None): |
|
188 | user=None, date=None): | |
189 | user = (user or |
|
189 | user = (user or | |
190 | os.environ.get("HGUSER") or |
|
190 | os.environ.get("HGUSER") or | |
191 | os.environ.get("EMAIL") or |
|
191 | os.environ.get("EMAIL") or | |
192 | os.environ.get("LOGNAME", "unknown") + '@' + socket.getfqdn()) |
|
192 | os.environ.get("LOGNAME", "unknown") + '@' + socket.getfqdn()) | |
193 | date = date or "%d %d" % (time.time(), time.timezone) |
|
193 | date = date or "%d %d" % (time.time(), time.timezone) | |
194 | list.sort() |
|
194 | list.sort() | |
195 | l = [hex(manifest), user, date] + list + ["", desc] |
|
195 | l = [hex(manifest), user, date] + list + ["", desc] | |
196 | text = "\n".join(l) |
|
196 | text = "\n".join(l) | |
197 | return self.addrevision(text, transaction, self.count(), p1, p2) |
|
197 | return self.addrevision(text, transaction, self.count(), p1, p2) | |
198 |
|
198 | |||
199 | class dirstate: |
|
199 | class dirstate: | |
200 | def __init__(self, opener, ui, root): |
|
200 | def __init__(self, opener, ui, root): | |
201 | self.opener = opener |
|
201 | self.opener = opener | |
202 | self.root = root |
|
202 | self.root = root | |
203 | self.dirty = 0 |
|
203 | self.dirty = 0 | |
204 | self.ui = ui |
|
204 | self.ui = ui | |
205 | self.map = None |
|
205 | self.map = None | |
206 | self.pl = None |
|
206 | self.pl = None | |
207 | self.copies = {} |
|
207 | self.copies = {} | |
208 |
|
208 | |||
209 | def __del__(self): |
|
209 | def __del__(self): | |
210 | if self.dirty: |
|
210 | if self.dirty: | |
211 | self.write() |
|
211 | self.write() | |
212 |
|
212 | |||
213 | def __getitem__(self, key): |
|
213 | def __getitem__(self, key): | |
214 | try: |
|
214 | try: | |
215 | return self.map[key] |
|
215 | return self.map[key] | |
216 | except TypeError: |
|
216 | except TypeError: | |
217 | self.read() |
|
217 | self.read() | |
218 | return self[key] |
|
218 | return self[key] | |
219 |
|
219 | |||
220 | def __contains__(self, key): |
|
220 | def __contains__(self, key): | |
221 | if not self.map: self.read() |
|
221 | if not self.map: self.read() | |
222 | return key in self.map |
|
222 | return key in self.map | |
223 |
|
223 | |||
224 | def parents(self): |
|
224 | def parents(self): | |
225 | if not self.pl: |
|
225 | if not self.pl: | |
226 | self.read() |
|
226 | self.read() | |
227 | return self.pl |
|
227 | return self.pl | |
228 |
|
228 | |||
229 | def setparents(self, p1, p2 = nullid): |
|
229 | def setparents(self, p1, p2 = nullid): | |
230 | self.dirty = 1 |
|
230 | self.dirty = 1 | |
231 | self.pl = p1, p2 |
|
231 | self.pl = p1, p2 | |
232 |
|
232 | |||
233 | def state(self, key): |
|
233 | def state(self, key): | |
234 | try: |
|
234 | try: | |
235 | return self[key][0] |
|
235 | return self[key][0] | |
236 | except KeyError: |
|
236 | except KeyError: | |
237 | return "?" |
|
237 | return "?" | |
238 |
|
238 | |||
239 | def read(self): |
|
239 | def read(self): | |
240 | if self.map is not None: return self.map |
|
240 | if self.map is not None: return self.map | |
241 |
|
241 | |||
242 | self.map = {} |
|
242 | self.map = {} | |
243 | self.pl = [nullid, nullid] |
|
243 | self.pl = [nullid, nullid] | |
244 | try: |
|
244 | try: | |
245 | st = self.opener("dirstate").read() |
|
245 | st = self.opener("dirstate").read() | |
246 | if not st: return |
|
246 | if not st: return | |
247 | except: return |
|
247 | except: return | |
248 |
|
248 | |||
249 | self.pl = [st[:20], st[20: 40]] |
|
249 | self.pl = [st[:20], st[20: 40]] | |
250 |
|
250 | |||
251 | pos = 40 |
|
251 | pos = 40 | |
252 | while pos < len(st): |
|
252 | while pos < len(st): | |
253 | e = struct.unpack(">cllll", st[pos:pos+17]) |
|
253 | e = struct.unpack(">cllll", st[pos:pos+17]) | |
254 | l = e[4] |
|
254 | l = e[4] | |
255 | pos += 17 |
|
255 | pos += 17 | |
256 | f = st[pos:pos + l] |
|
256 | f = st[pos:pos + l] | |
257 | if '\0' in f: |
|
257 | if '\0' in f: | |
258 | f, c = f.split('\0') |
|
258 | f, c = f.split('\0') | |
259 | self.copies[f] = c |
|
259 | self.copies[f] = c | |
260 | self.map[f] = e[:4] |
|
260 | self.map[f] = e[:4] | |
261 | pos += l |
|
261 | pos += l | |
262 |
|
262 | |||
263 | def copy(self, source, dest): |
|
263 | def copy(self, source, dest): | |
264 | self.read() |
|
264 | self.read() | |
265 | self.dirty = 1 |
|
265 | self.dirty = 1 | |
266 | self.copies[dest] = source |
|
266 | self.copies[dest] = source | |
267 |
|
267 | |||
268 | def copied(self, file): |
|
268 | def copied(self, file): | |
269 | return self.copies.get(file, None) |
|
269 | return self.copies.get(file, None) | |
270 |
|
270 | |||
271 | def update(self, files, state): |
|
271 | def update(self, files, state): | |
272 | ''' current states: |
|
272 | ''' current states: | |
273 | n normal |
|
273 | n normal | |
274 | m needs merging |
|
274 | m needs merging | |
275 | r marked for removal |
|
275 | r marked for removal | |
276 | a marked for addition''' |
|
276 | a marked for addition''' | |
277 |
|
277 | |||
278 | if not files: return |
|
278 | if not files: return | |
279 | self.read() |
|
279 | self.read() | |
280 | self.dirty = 1 |
|
280 | self.dirty = 1 | |
281 | for f in files: |
|
281 | for f in files: | |
282 | if state == "r": |
|
282 | if state == "r": | |
283 | self.map[f] = ('r', 0, 0, 0) |
|
283 | self.map[f] = ('r', 0, 0, 0) | |
284 | else: |
|
284 | else: | |
285 | s = os.stat(os.path.join(self.root, f)) |
|
285 | s = os.stat(os.path.join(self.root, f)) | |
286 | self.map[f] = (state, s.st_mode, s.st_size, s.st_mtime) |
|
286 | self.map[f] = (state, s.st_mode, s.st_size, s.st_mtime) | |
287 |
|
287 | |||
288 | def forget(self, files): |
|
288 | def forget(self, files): | |
289 | if not files: return |
|
289 | if not files: return | |
290 | self.read() |
|
290 | self.read() | |
291 | self.dirty = 1 |
|
291 | self.dirty = 1 | |
292 | for f in files: |
|
292 | for f in files: | |
293 | try: |
|
293 | try: | |
294 | del self.map[f] |
|
294 | del self.map[f] | |
295 | except KeyError: |
|
295 | except KeyError: | |
296 | self.ui.warn("not in dirstate: %s!\n" % f) |
|
296 | self.ui.warn("not in dirstate: %s!\n" % f) | |
297 | pass |
|
297 | pass | |
298 |
|
298 | |||
299 | def clear(self): |
|
299 | def clear(self): | |
300 | self.map = {} |
|
300 | self.map = {} | |
301 | self.dirty = 1 |
|
301 | self.dirty = 1 | |
302 |
|
302 | |||
303 | def write(self): |
|
303 | def write(self): | |
304 | st = self.opener("dirstate", "w") |
|
304 | st = self.opener("dirstate", "w") | |
305 | st.write("".join(self.pl)) |
|
305 | st.write("".join(self.pl)) | |
306 | for f, e in self.map.items(): |
|
306 | for f, e in self.map.items(): | |
307 | c = self.copied(f) |
|
307 | c = self.copied(f) | |
308 | if c: |
|
308 | if c: | |
309 | f = f + "\0" + c |
|
309 | f = f + "\0" + c | |
310 | e = struct.pack(">cllll", e[0], e[1], e[2], e[3], len(f)) |
|
310 | e = struct.pack(">cllll", e[0], e[1], e[2], e[3], len(f)) | |
311 | st.write(e + f) |
|
311 | st.write(e + f) | |
312 | self.dirty = 0 |
|
312 | self.dirty = 0 | |
313 |
|
313 | |||
314 | def dup(self): |
|
314 | def dup(self): | |
315 | self.read() |
|
315 | self.read() | |
316 | return self.map.copy() |
|
316 | return self.map.copy() | |
317 |
|
317 | |||
318 | # used to avoid circular references so destructors work |
|
318 | # used to avoid circular references so destructors work | |
319 | def opener(base): |
|
319 | def opener(base): | |
320 | p = base |
|
320 | p = base | |
321 | def o(path, mode="r"): |
|
321 | def o(path, mode="r"): | |
322 | if p[:7] == "http://": |
|
322 | if p[:7] == "http://": | |
323 | f = os.path.join(p, urllib.quote(path)) |
|
323 | f = os.path.join(p, urllib.quote(path)) | |
324 | return httprangereader.httprangereader(f) |
|
324 | return httprangereader.httprangereader(f) | |
325 |
|
325 | |||
326 | f = os.path.join(p, path) |
|
326 | f = os.path.join(p, path) | |
327 |
|
327 | |||
328 | mode += "b" # for that other OS |
|
328 | mode += "b" # for that other OS | |
329 |
|
329 | |||
330 | if mode[0] != "r": |
|
330 | if mode[0] != "r": | |
331 | try: |
|
331 | try: | |
332 | s = os.stat(f) |
|
332 | s = os.stat(f) | |
333 | except OSError: |
|
333 | except OSError: | |
334 | d = os.path.dirname(f) |
|
334 | d = os.path.dirname(f) | |
335 | if not os.path.isdir(d): |
|
335 | if not os.path.isdir(d): | |
336 | os.makedirs(d) |
|
336 | os.makedirs(d) | |
337 | else: |
|
337 | else: | |
338 | if s.st_nlink > 1: |
|
338 | if s.st_nlink > 1: | |
339 | file(f + ".tmp", "w").write(file(f).read()) |
|
339 | file(f + ".tmp", "w").write(file(f).read()) | |
340 | os.rename(f+".tmp", f) |
|
340 | os.rename(f+".tmp", f) | |
341 |
|
341 | |||
342 | return file(f, mode) |
|
342 | return file(f, mode) | |
343 |
|
343 | |||
344 | return o |
|
344 | return o | |
345 |
|
345 | |||
346 | class localrepository: |
|
346 | class localrepository: | |
347 | def __init__(self, ui, path=None, create=0): |
|
347 | def __init__(self, ui, path=None, create=0): | |
348 | self.remote = 0 |
|
348 | self.remote = 0 | |
349 | if path and path[:7] == "http://": |
|
349 | if path and path[:7] == "http://": | |
350 | self.remote = 1 |
|
350 | self.remote = 1 | |
351 | self.path = path |
|
351 | self.path = path | |
352 | else: |
|
352 | else: | |
353 | if not path: |
|
353 | if not path: | |
354 | p = os.getcwd() |
|
354 | p = os.getcwd() | |
355 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
355 | while not os.path.isdir(os.path.join(p, ".hg")): | |
356 | p = os.path.dirname(p) |
|
356 | p = os.path.dirname(p) | |
357 | if p == "/": raise "No repo found" |
|
357 | if p == "/": raise "No repo found" | |
358 | path = p |
|
358 | path = p | |
359 | self.path = os.path.join(path, ".hg") |
|
359 | self.path = os.path.join(path, ".hg") | |
360 |
|
360 | |||
361 | if not create and not os.path.isdir(self.path): |
|
361 | if not create and not os.path.isdir(self.path): | |
362 | raise "repository %s not found" % self.path |
|
362 | raise "repository %s not found" % self.path | |
363 |
|
363 | |||
364 | self.root = path |
|
364 | self.root = path | |
365 | self.ui = ui |
|
365 | self.ui = ui | |
366 |
|
366 | |||
367 | if create: |
|
367 | if create: | |
368 | os.mkdir(self.path) |
|
368 | os.mkdir(self.path) | |
369 | os.mkdir(self.join("data")) |
|
369 | os.mkdir(self.join("data")) | |
370 |
|
370 | |||
371 | self.opener = opener(self.path) |
|
371 | self.opener = opener(self.path) | |
372 | self.wopener = opener(self.root) |
|
372 | self.wopener = opener(self.root) | |
373 | self.manifest = manifest(self.opener) |
|
373 | self.manifest = manifest(self.opener) | |
374 | self.changelog = changelog(self.opener) |
|
374 | self.changelog = changelog(self.opener) | |
375 | self.ignorelist = None |
|
375 | self.ignorelist = None | |
376 | self.tagscache = None |
|
376 | self.tagscache = None | |
377 | self.nodetagscache = None |
|
377 | self.nodetagscache = None | |
378 |
|
378 | |||
379 | if not self.remote: |
|
379 | if not self.remote: | |
380 | self.dirstate = dirstate(self.opener, ui, self.root) |
|
380 | self.dirstate = dirstate(self.opener, ui, self.root) | |
381 | try: |
|
381 | try: | |
382 | self.ui.readconfig(self.opener("hgrc")) |
|
382 | self.ui.readconfig(self.opener("hgrc")) | |
383 | except IOError: pass |
|
383 | except IOError: pass | |
384 |
|
384 | |||
385 | def ignore(self, f): |
|
385 | def ignore(self, f): | |
386 | if self.ignorelist is None: |
|
386 | if self.ignorelist is None: | |
387 | self.ignorelist = [] |
|
387 | self.ignorelist = [] | |
388 | try: |
|
388 | try: | |
389 | l = self.wfile(".hgignore") |
|
389 | l = self.wfile(".hgignore") | |
390 | for pat in l: |
|
390 | for pat in l: | |
391 | if pat != "\n": |
|
391 | if pat != "\n": | |
392 | self.ignorelist.append(re.compile(pat[:-1])) |
|
392 | self.ignorelist.append(re.compile(pat[:-1])) | |
393 | except IOError: pass |
|
393 | except IOError: pass | |
394 | for pat in self.ignorelist: |
|
394 | for pat in self.ignorelist: | |
395 | if pat.search(f): return True |
|
395 | if pat.search(f): return True | |
396 | return False |
|
396 | return False | |
397 |
|
397 | |||
398 | def tags(self): |
|
398 | def tags(self): | |
399 | '''return a mapping of tag to node''' |
|
399 | '''return a mapping of tag to node''' | |
400 | if not self.tagscache: |
|
400 | if not self.tagscache: | |
401 | self.tagscache = {} |
|
401 | self.tagscache = {} | |
402 | try: |
|
402 | try: | |
403 | # read each head of the tags file, ending with the tip |
|
403 | # read each head of the tags file, ending with the tip | |
404 | # and add each tag found to the map, with "newer" ones |
|
404 | # and add each tag found to the map, with "newer" ones | |
405 | # taking precedence |
|
405 | # taking precedence | |
406 | fl = self.file(".hgtags") |
|
406 | fl = self.file(".hgtags") | |
407 | h = fl.heads() |
|
407 | h = fl.heads() | |
408 | h.reverse() |
|
408 | h.reverse() | |
409 | for r in h: |
|
409 | for r in h: | |
410 | for l in fl.revision(r).splitlines(): |
|
410 | for l in fl.revision(r).splitlines(): | |
411 | if l: |
|
411 | if l: | |
412 | n, k = l.split(" ", 1) |
|
412 | n, k = l.split(" ", 1) | |
413 | self.tagscache[k.strip()] = bin(n) |
|
413 | self.tagscache[k.strip()] = bin(n) | |
414 | except KeyError: pass |
|
414 | except KeyError: pass | |
415 | self.tagscache['tip'] = self.changelog.tip() |
|
415 | self.tagscache['tip'] = self.changelog.tip() | |
416 |
|
416 | |||
417 | return self.tagscache |
|
417 | return self.tagscache | |
418 |
|
418 | |||
419 | def tagslist(self): |
|
419 | def tagslist(self): | |
420 | '''return a list of tags ordered by revision''' |
|
420 | '''return a list of tags ordered by revision''' | |
421 | l = [] |
|
421 | l = [] | |
422 | for t,n in self.tags().items(): |
|
422 | for t,n in self.tags().items(): | |
423 | try: |
|
423 | try: | |
424 | r = self.changelog.rev(n) |
|
424 | r = self.changelog.rev(n) | |
425 | except: |
|
425 | except: | |
426 | r = -2 # sort to the beginning of the list if unknown |
|
426 | r = -2 # sort to the beginning of the list if unknown | |
427 | l.append((r,t,n)) |
|
427 | l.append((r,t,n)) | |
428 | l.sort() |
|
428 | l.sort() | |
429 | return [(t,n) for r,t,n in l] |
|
429 | return [(t,n) for r,t,n in l] | |
430 |
|
430 | |||
431 | def nodetags(self, node): |
|
431 | def nodetags(self, node): | |
432 | '''return the tags associated with a node''' |
|
432 | '''return the tags associated with a node''' | |
433 | if not self.nodetagscache: |
|
433 | if not self.nodetagscache: | |
434 | self.nodetagscache = {} |
|
434 | self.nodetagscache = {} | |
435 | for t,n in self.tags().items(): |
|
435 | for t,n in self.tags().items(): | |
436 | self.nodetagscache.setdefault(n,[]).append(t) |
|
436 | self.nodetagscache.setdefault(n,[]).append(t) | |
437 | return self.nodetagscache.get(node, []) |
|
437 | return self.nodetagscache.get(node, []) | |
438 |
|
438 | |||
439 | def lookup(self, key): |
|
439 | def lookup(self, key): | |
440 | try: |
|
440 | try: | |
441 | return self.tags()[key] |
|
441 | return self.tags()[key] | |
442 | except KeyError: |
|
442 | except KeyError: | |
443 | return self.changelog.lookup(key) |
|
443 | return self.changelog.lookup(key) | |
444 |
|
444 | |||
445 | def join(self, f): |
|
445 | def join(self, f): | |
446 | return os.path.join(self.path, f) |
|
446 | return os.path.join(self.path, f) | |
447 |
|
447 | |||
448 | def wjoin(self, f): |
|
448 | def wjoin(self, f): | |
449 | return os.path.join(self.root, f) |
|
449 | return os.path.join(self.root, f) | |
450 |
|
450 | |||
451 | def file(self, f): |
|
451 | def file(self, f): | |
452 | if f[0] == '/': f = f[1:] |
|
452 | if f[0] == '/': f = f[1:] | |
453 | return filelog(self.opener, f) |
|
453 | return filelog(self.opener, f) | |
454 |
|
454 | |||
455 | def wfile(self, f, mode='r'): |
|
455 | def wfile(self, f, mode='r'): | |
456 | return self.wopener(f, mode) |
|
456 | return self.wopener(f, mode) | |
457 |
|
457 | |||
458 | def transaction(self): |
|
458 | def transaction(self): | |
459 | # save dirstate for undo |
|
459 | # save dirstate for undo | |
460 | try: |
|
460 | try: | |
461 | ds = self.opener("dirstate").read() |
|
461 | ds = self.opener("dirstate").read() | |
462 | except IOError: |
|
462 | except IOError: | |
463 | ds = "" |
|
463 | ds = "" | |
464 | self.opener("undo.dirstate", "w").write(ds) |
|
464 | self.opener("undo.dirstate", "w").write(ds) | |
465 |
|
465 | |||
466 | return transaction.transaction(self.opener, self.join("journal"), |
|
466 | return transaction.transaction(self.opener, self.join("journal"), | |
467 | self.join("undo")) |
|
467 | self.join("undo")) | |
468 |
|
468 | |||
469 | def recover(self): |
|
469 | def recover(self): | |
470 | lock = self.lock() |
|
470 | lock = self.lock() | |
471 | if os.path.exists(self.join("recover")): |
|
471 | if os.path.exists(self.join("recover")): | |
472 | self.ui.status("attempting to rollback interrupted transaction\n") |
|
472 | self.ui.status("attempting to rollback interrupted transaction\n") | |
473 | return transaction.rollback(self.opener, self.join("recover")) |
|
473 | return transaction.rollback(self.opener, self.join("recover")) | |
474 | else: |
|
474 | else: | |
475 | self.ui.warn("no interrupted transaction available\n") |
|
475 | self.ui.warn("no interrupted transaction available\n") | |
476 |
|
476 | |||
477 | def undo(self): |
|
477 | def undo(self): | |
478 | lock = self.lock() |
|
478 | lock = self.lock() | |
479 | if os.path.exists(self.join("undo")): |
|
479 | if os.path.exists(self.join("undo")): | |
480 | self.ui.status("attempting to rollback last transaction\n") |
|
480 | self.ui.status("attempting to rollback last transaction\n") | |
481 | transaction.rollback(self.opener, self.join("undo")) |
|
481 | transaction.rollback(self.opener, self.join("undo")) | |
482 | self.dirstate = None |
|
482 | self.dirstate = None | |
483 | os.rename(self.join("undo.dirstate"), self.join("dirstate")) |
|
483 | os.rename(self.join("undo.dirstate"), self.join("dirstate")) | |
484 | self.dirstate = dirstate(self.opener, self.ui, self.root) |
|
484 | self.dirstate = dirstate(self.opener, self.ui, self.root) | |
485 | else: |
|
485 | else: | |
486 | self.ui.warn("no undo information available\n") |
|
486 | self.ui.warn("no undo information available\n") | |
487 |
|
487 | |||
488 | def lock(self, wait = 1): |
|
488 | def lock(self, wait = 1): | |
489 | try: |
|
489 | try: | |
490 | return lock.lock(self.join("lock"), 0) |
|
490 | return lock.lock(self.join("lock"), 0) | |
491 | except lock.LockHeld, inst: |
|
491 | except lock.LockHeld, inst: | |
492 | if wait: |
|
492 | if wait: | |
493 | self.ui.warn("waiting for lock held by %s\n" % inst.args[0]) |
|
493 | self.ui.warn("waiting for lock held by %s\n" % inst.args[0]) | |
494 | return lock.lock(self.join("lock"), wait) |
|
494 | return lock.lock(self.join("lock"), wait) | |
495 | raise inst |
|
495 | raise inst | |
496 |
|
496 | |||
497 | def rawcommit(self, files, text, user, date, p1=None, p2=None): |
|
497 | def rawcommit(self, files, text, user, date, p1=None, p2=None): | |
498 | p1 = p1 or self.dirstate.parents()[0] or nullid |
|
498 | p1 = p1 or self.dirstate.parents()[0] or nullid | |
499 | p2 = p2 or self.dirstate.parents()[1] or nullid |
|
499 | p2 = p2 or self.dirstate.parents()[1] or nullid | |
500 | c1 = self.changelog.read(p1) |
|
500 | c1 = self.changelog.read(p1) | |
501 | c2 = self.changelog.read(p2) |
|
501 | c2 = self.changelog.read(p2) | |
502 | m1 = self.manifest.read(c1[0]) |
|
502 | m1 = self.manifest.read(c1[0]) | |
503 | mf1 = self.manifest.readflags(c1[0]) |
|
503 | mf1 = self.manifest.readflags(c1[0]) | |
504 | m2 = self.manifest.read(c2[0]) |
|
504 | m2 = self.manifest.read(c2[0]) | |
505 |
|
505 | |||
506 | tr = self.transaction() |
|
506 | tr = self.transaction() | |
507 | mm = m1.copy() |
|
507 | mm = m1.copy() | |
508 | mfm = mf1.copy() |
|
508 | mfm = mf1.copy() | |
509 | linkrev = self.changelog.count() |
|
509 | linkrev = self.changelog.count() | |
510 | self.dirstate.setparents(p1, p2) |
|
510 | self.dirstate.setparents(p1, p2) | |
511 | for f in files: |
|
511 | for f in files: | |
512 | try: |
|
512 | try: | |
513 | t = self.wfile(f).read() |
|
513 | t = self.wfile(f).read() | |
514 | tm = is_exec(self.wjoin(f)) |
|
514 | tm = is_exec(self.wjoin(f)) | |
515 | r = self.file(f) |
|
515 | r = self.file(f) | |
516 | mfm[f] = tm |
|
516 | mfm[f] = tm | |
517 | mm[f] = r.add(t, {}, tr, linkrev, |
|
517 | mm[f] = r.add(t, {}, tr, linkrev, | |
518 | m1.get(f, nullid), m2.get(f, nullid)) |
|
518 | m1.get(f, nullid), m2.get(f, nullid)) | |
519 | self.dirstate.update([f], "n") |
|
519 | self.dirstate.update([f], "n") | |
520 | except IOError: |
|
520 | except IOError: | |
521 | try: |
|
521 | try: | |
522 | del mm[f] |
|
522 | del mm[f] | |
523 | del mfm[f] |
|
523 | del mfm[f] | |
524 | self.dirstate.forget([f]) |
|
524 | self.dirstate.forget([f]) | |
525 | except: |
|
525 | except: | |
526 | # deleted from p2? |
|
526 | # deleted from p2? | |
527 | pass |
|
527 | pass | |
528 |
|
528 | |||
529 | mnode = self.manifest.add(mm, mfm, tr, linkrev, c1[0], c2[0]) |
|
529 | mnode = self.manifest.add(mm, mfm, tr, linkrev, c1[0], c2[0]) | |
530 | n = self.changelog.add(mnode, files, text, tr, p1, p2, user, date) |
|
530 | n = self.changelog.add(mnode, files, text, tr, p1, p2, user, date) | |
531 | tr.close() |
|
531 | tr.close() | |
532 |
|
532 | |||
533 | def commit(self, files = None, text = "", user = None, date = None): |
|
533 | def commit(self, files = None, text = "", user = None, date = None): | |
534 | commit = [] |
|
534 | commit = [] | |
535 | remove = [] |
|
535 | remove = [] | |
536 | if files: |
|
536 | if files: | |
537 | for f in files: |
|
537 | for f in files: | |
538 | s = self.dirstate.state(f) |
|
538 | s = self.dirstate.state(f) | |
539 | if s in 'nmai': |
|
539 | if s in 'nmai': | |
540 | commit.append(f) |
|
540 | commit.append(f) | |
541 | elif s == 'r': |
|
541 | elif s == 'r': | |
542 | remove.append(f) |
|
542 | remove.append(f) | |
543 | else: |
|
543 | else: | |
544 | self.ui.warn("%s not tracked!\n" % f) |
|
544 | self.ui.warn("%s not tracked!\n" % f) | |
545 | else: |
|
545 | else: | |
546 | (c, a, d, u) = self.diffdir(self.root) |
|
546 | (c, a, d, u) = self.diffdir(self.root) | |
547 | commit = c + a |
|
547 | commit = c + a | |
548 | remove = d |
|
548 | remove = d | |
549 |
|
549 | |||
550 | if not commit and not remove: |
|
550 | if not commit and not remove: | |
551 | self.ui.status("nothing changed\n") |
|
551 | self.ui.status("nothing changed\n") | |
552 | return |
|
552 | return | |
553 |
|
553 | |||
554 | p1, p2 = self.dirstate.parents() |
|
554 | p1, p2 = self.dirstate.parents() | |
555 | c1 = self.changelog.read(p1) |
|
555 | c1 = self.changelog.read(p1) | |
556 | c2 = self.changelog.read(p2) |
|
556 | c2 = self.changelog.read(p2) | |
557 | m1 = self.manifest.read(c1[0]) |
|
557 | m1 = self.manifest.read(c1[0]) | |
558 | mf1 = self.manifest.readflags(c1[0]) |
|
558 | mf1 = self.manifest.readflags(c1[0]) | |
559 | m2 = self.manifest.read(c2[0]) |
|
559 | m2 = self.manifest.read(c2[0]) | |
560 | lock = self.lock() |
|
560 | lock = self.lock() | |
561 | tr = self.transaction() |
|
561 | tr = self.transaction() | |
562 |
|
562 | |||
563 | # check in files |
|
563 | # check in files | |
564 | new = {} |
|
564 | new = {} | |
565 | linkrev = self.changelog.count() |
|
565 | linkrev = self.changelog.count() | |
566 | commit.sort() |
|
566 | commit.sort() | |
567 | for f in commit: |
|
567 | for f in commit: | |
568 | self.ui.note(f + "\n") |
|
568 | self.ui.note(f + "\n") | |
569 | try: |
|
569 | try: | |
570 | fp = self.wjoin(f) |
|
570 | fp = self.wjoin(f) | |
571 | mf1[f] = is_exec(fp) |
|
571 | mf1[f] = is_exec(fp) | |
572 | t = file(fp).read() |
|
572 | t = file(fp).read() | |
573 | except IOError: |
|
573 | except IOError: | |
574 | self.warn("trouble committing %s!\n" % f) |
|
574 | self.warn("trouble committing %s!\n" % f) | |
575 | raise |
|
575 | raise | |
576 |
|
576 | |||
577 | meta = {} |
|
577 | meta = {} | |
578 | cp = self.dirstate.copied(f) |
|
578 | cp = self.dirstate.copied(f) | |
579 | if cp: |
|
579 | if cp: | |
580 | meta["copy"] = cp |
|
580 | meta["copy"] = cp | |
581 | meta["copyrev"] = hex(m1.get(cp, m2.get(cp, nullid))) |
|
581 | meta["copyrev"] = hex(m1.get(cp, m2.get(cp, nullid))) | |
582 | self.ui.debug(" %s: copy %s:%s\n" % (f, cp, meta["copyrev"])) |
|
582 | self.ui.debug(" %s: copy %s:%s\n" % (f, cp, meta["copyrev"])) | |
583 |
|
583 | |||
584 | r = self.file(f) |
|
584 | r = self.file(f) | |
585 | fp1 = m1.get(f, nullid) |
|
585 | fp1 = m1.get(f, nullid) | |
586 | fp2 = m2.get(f, nullid) |
|
586 | fp2 = m2.get(f, nullid) | |
587 | new[f] = r.add(t, meta, tr, linkrev, fp1, fp2) |
|
587 | new[f] = r.add(t, meta, tr, linkrev, fp1, fp2) | |
588 |
|
588 | |||
589 | # update manifest |
|
589 | # update manifest | |
590 | m1.update(new) |
|
590 | m1.update(new) | |
591 | for f in remove: del m1[f] |
|
591 | for f in remove: del m1[f] | |
592 | mn = self.manifest.add(m1, mf1, tr, linkrev, c1[0], c2[0]) |
|
592 | mn = self.manifest.add(m1, mf1, tr, linkrev, c1[0], c2[0]) | |
593 |
|
593 | |||
594 | # add changeset |
|
594 | # add changeset | |
595 | new = new.keys() |
|
595 | new = new.keys() | |
596 | new.sort() |
|
596 | new.sort() | |
597 |
|
597 | |||
598 | if not text: |
|
598 | if not text: | |
599 | edittext = "\n" + "HG: manifest hash %s\n" % hex(mn) |
|
599 | edittext = "\n" + "HG: manifest hash %s\n" % hex(mn) | |
600 | edittext += "".join(["HG: changed %s\n" % f for f in new]) |
|
600 | edittext += "".join(["HG: changed %s\n" % f for f in new]) | |
601 | edittext += "".join(["HG: removed %s\n" % f for f in remove]) |
|
601 | edittext += "".join(["HG: removed %s\n" % f for f in remove]) | |
602 | edittext = self.ui.edit(edittext) |
|
602 | edittext = self.ui.edit(edittext) | |
603 | if not edittext.rstrip(): |
|
603 | if not edittext.rstrip(): | |
604 | return 1 |
|
604 | return 1 | |
605 | text = edittext |
|
605 | text = edittext | |
606 |
|
606 | |||
607 | n = self.changelog.add(mn, new, text, tr, p1, p2, user, date) |
|
607 | n = self.changelog.add(mn, new, text, tr, p1, p2, user, date) | |
608 | tr.close() |
|
608 | tr.close() | |
609 |
|
609 | |||
610 | self.dirstate.setparents(n) |
|
610 | self.dirstate.setparents(n) | |
611 | self.dirstate.update(new, "n") |
|
611 | self.dirstate.update(new, "n") | |
612 | self.dirstate.forget(remove) |
|
612 | self.dirstate.forget(remove) | |
613 |
|
613 | |||
614 | def diffdir(self, path, changeset = None): |
|
614 | def diffdir(self, path, changeset = None): | |
615 | changed = [] |
|
615 | changed = [] | |
616 | added = [] |
|
616 | added = [] | |
617 | unknown = [] |
|
617 | unknown = [] | |
618 | mf = {} |
|
618 | mf = {} | |
619 |
|
619 | |||
620 | if changeset: |
|
620 | if changeset: | |
621 | change = self.changelog.read(changeset) |
|
621 | change = self.changelog.read(changeset) | |
622 | mf = self.manifest.read(change[0]) |
|
622 | mf = self.manifest.read(change[0]) | |
623 | dc = dict.fromkeys(mf) |
|
623 | dc = dict.fromkeys(mf) | |
624 | else: |
|
624 | else: | |
625 | changeset = self.dirstate.parents()[0] |
|
625 | changeset = self.dirstate.parents()[0] | |
626 | change = self.changelog.read(changeset) |
|
626 | change = self.changelog.read(changeset) | |
627 | mf = self.manifest.read(change[0]) |
|
627 | mf = self.manifest.read(change[0]) | |
628 | dc = self.dirstate.dup() |
|
628 | dc = self.dirstate.dup() | |
629 |
|
629 | |||
630 | def fcmp(fn): |
|
630 | def fcmp(fn): | |
631 | t1 = self.wfile(fn).read() |
|
631 | t1 = self.wfile(fn).read() | |
632 | t2 = self.file(fn).revision(mf[fn]) |
|
632 | t2 = self.file(fn).revision(mf[fn]) | |
633 | return cmp(t1, t2) |
|
633 | return cmp(t1, t2) | |
634 |
|
634 | |||
635 | for dir, subdirs, files in os.walk(path): |
|
635 | for dir, subdirs, files in os.walk(path): | |
636 | d = dir[len(self.root)+1:] |
|
636 | d = dir[len(self.root)+1:] | |
637 | if ".hg" in subdirs: subdirs.remove(".hg") |
|
637 | if ".hg" in subdirs: subdirs.remove(".hg") | |
638 |
|
638 | |||
639 | for f in files: |
|
639 | for f in files: | |
640 | fn = os.path.join(d, f) |
|
640 | fn = os.path.join(d, f) | |
641 | try: s = os.stat(os.path.join(self.root, fn)) |
|
641 | try: s = os.stat(os.path.join(self.root, fn)) | |
642 | except: continue |
|
642 | except: continue | |
643 | if fn in dc: |
|
643 | if fn in dc: | |
644 | c = dc[fn] |
|
644 | c = dc[fn] | |
645 | del dc[fn] |
|
645 | del dc[fn] | |
646 | if not c: |
|
646 | if not c: | |
647 | if fcmp(fn): |
|
647 | if fcmp(fn): | |
648 | changed.append(fn) |
|
648 | changed.append(fn) | |
649 | elif c[0] == 'm': |
|
649 | elif c[0] == 'm': | |
650 | changed.append(fn) |
|
650 | changed.append(fn) | |
651 | elif c[0] == 'a': |
|
651 | elif c[0] == 'a': | |
652 | added.append(fn) |
|
652 | added.append(fn) | |
653 | elif c[0] == 'r': |
|
653 | elif c[0] == 'r': | |
654 | unknown.append(fn) |
|
654 | unknown.append(fn) | |
655 | elif c[2] != s.st_size or (c[1] ^ s.st_mode) & 0100: |
|
655 | elif c[2] != s.st_size or (c[1] ^ s.st_mode) & 0100: | |
656 | changed.append(fn) |
|
656 | changed.append(fn) | |
657 | elif c[1] != s.st_mode or c[3] != s.st_mtime: |
|
657 | elif c[1] != s.st_mode or c[3] != s.st_mtime: | |
658 | if fcmp(fn): |
|
658 | if fcmp(fn): | |
659 | changed.append(fn) |
|
659 | changed.append(fn) | |
660 | else: |
|
660 | else: | |
661 | if self.ignore(fn): continue |
|
661 | if self.ignore(fn): continue | |
662 | unknown.append(fn) |
|
662 | unknown.append(fn) | |
663 |
|
663 | |||
664 | deleted = dc.keys() |
|
664 | deleted = dc.keys() | |
665 | deleted.sort() |
|
665 | deleted.sort() | |
666 |
|
666 | |||
667 | return (changed, added, deleted, unknown) |
|
667 | return (changed, added, deleted, unknown) | |
668 |
|
668 | |||
669 | def diffrevs(self, node1, node2): |
|
669 | def diffrevs(self, node1, node2): | |
670 | changed, added = [], [] |
|
670 | changed, added = [], [] | |
671 |
|
671 | |||
672 | change = self.changelog.read(node1) |
|
672 | change = self.changelog.read(node1) | |
673 | mf1 = self.manifest.read(change[0]) |
|
673 | mf1 = self.manifest.read(change[0]) | |
674 | change = self.changelog.read(node2) |
|
674 | change = self.changelog.read(node2) | |
675 | mf2 = self.manifest.read(change[0]) |
|
675 | mf2 = self.manifest.read(change[0]) | |
676 |
|
676 | |||
677 | for fn in mf2: |
|
677 | for fn in mf2: | |
678 | if mf1.has_key(fn): |
|
678 | if mf1.has_key(fn): | |
679 | if mf1[fn] != mf2[fn]: |
|
679 | if mf1[fn] != mf2[fn]: | |
680 | changed.append(fn) |
|
680 | changed.append(fn) | |
681 | del mf1[fn] |
|
681 | del mf1[fn] | |
682 | else: |
|
682 | else: | |
683 | added.append(fn) |
|
683 | added.append(fn) | |
684 |
|
684 | |||
685 | deleted = mf1.keys() |
|
685 | deleted = mf1.keys() | |
686 | deleted.sort() |
|
686 | deleted.sort() | |
687 |
|
687 | |||
688 | return (changed, added, deleted) |
|
688 | return (changed, added, deleted) | |
689 |
|
689 | |||
690 | def add(self, list): |
|
690 | def add(self, list): | |
691 | for f in list: |
|
691 | for f in list: | |
692 | p = self.wjoin(f) |
|
692 | p = self.wjoin(f) | |
693 | if not os.path.isfile(p): |
|
693 | if not os.path.isfile(p): | |
694 | self.ui.warn("%s does not exist!\n" % f) |
|
694 | self.ui.warn("%s does not exist!\n" % f) | |
695 | elif self.dirstate.state(f) == 'n': |
|
695 | elif self.dirstate.state(f) == 'n': | |
696 | self.ui.warn("%s already tracked!\n" % f) |
|
696 | self.ui.warn("%s already tracked!\n" % f) | |
697 | else: |
|
697 | else: | |
698 | self.dirstate.update([f], "a") |
|
698 | self.dirstate.update([f], "a") | |
699 |
|
699 | |||
700 | def forget(self, list): |
|
700 | def forget(self, list): | |
701 | for f in list: |
|
701 | for f in list: | |
702 | if self.dirstate.state(f) not in 'ai': |
|
702 | if self.dirstate.state(f) not in 'ai': | |
703 | self.ui.warn("%s not added!\n" % f) |
|
703 | self.ui.warn("%s not added!\n" % f) | |
704 | else: |
|
704 | else: | |
705 | self.dirstate.forget([f]) |
|
705 | self.dirstate.forget([f]) | |
706 |
|
706 | |||
707 | def remove(self, list): |
|
707 | def remove(self, list): | |
708 | for f in list: |
|
708 | for f in list: | |
709 | p = self.wjoin(f) |
|
709 | p = self.wjoin(f) | |
710 | if os.path.isfile(p): |
|
710 | if os.path.isfile(p): | |
711 | self.ui.warn("%s still exists!\n" % f) |
|
711 | self.ui.warn("%s still exists!\n" % f) | |
712 | elif self.dirstate.state(f) == 'a': |
|
712 | elif self.dirstate.state(f) == 'a': | |
713 | self.ui.warn("%s never committed!\n" % f) |
|
713 | self.ui.warn("%s never committed!\n" % f) | |
714 | self.dirstate.forget(f) |
|
714 | self.dirstate.forget(f) | |
715 | elif f not in self.dirstate: |
|
715 | elif f not in self.dirstate: | |
716 | self.ui.warn("%s not tracked!\n" % f) |
|
716 | self.ui.warn("%s not tracked!\n" % f) | |
717 | else: |
|
717 | else: | |
718 | self.dirstate.update([f], "r") |
|
718 | self.dirstate.update([f], "r") | |
719 |
|
719 | |||
720 | def copy(self, source, dest): |
|
720 | def copy(self, source, dest): | |
721 | p = self.wjoin(dest) |
|
721 | p = self.wjoin(dest) | |
722 | if not os.path.isfile(dest): |
|
722 | if not os.path.isfile(dest): | |
723 | self.ui.warn("%s does not exist!\n" % dest) |
|
723 | self.ui.warn("%s does not exist!\n" % dest) | |
724 | else: |
|
724 | else: | |
725 | if self.dirstate.state(dest) == '?': |
|
725 | if self.dirstate.state(dest) == '?': | |
726 | self.dirstate.update([dest], "a") |
|
726 | self.dirstate.update([dest], "a") | |
727 | self.dirstate.copy(source, dest) |
|
727 | self.dirstate.copy(source, dest) | |
728 |
|
728 | |||
729 | def heads(self): |
|
729 | def heads(self): | |
730 | return self.changelog.heads() |
|
730 | return self.changelog.heads() | |
731 |
|
731 | |||
732 | def branches(self, nodes): |
|
732 | def branches(self, nodes): | |
733 | if not nodes: nodes = [self.changelog.tip()] |
|
733 | if not nodes: nodes = [self.changelog.tip()] | |
734 | b = [] |
|
734 | b = [] | |
735 | for n in nodes: |
|
735 | for n in nodes: | |
736 | t = n |
|
736 | t = n | |
737 | while n: |
|
737 | while n: | |
738 | p = self.changelog.parents(n) |
|
738 | p = self.changelog.parents(n) | |
739 | if p[1] != nullid or p[0] == nullid: |
|
739 | if p[1] != nullid or p[0] == nullid: | |
740 | b.append((t, n, p[0], p[1])) |
|
740 | b.append((t, n, p[0], p[1])) | |
741 | break |
|
741 | break | |
742 | n = p[0] |
|
742 | n = p[0] | |
743 | return b |
|
743 | return b | |
744 |
|
744 | |||
745 | def between(self, pairs): |
|
745 | def between(self, pairs): | |
746 | r = [] |
|
746 | r = [] | |
747 |
|
747 | |||
748 | for top, bottom in pairs: |
|
748 | for top, bottom in pairs: | |
749 | n, l, i = top, [], 0 |
|
749 | n, l, i = top, [], 0 | |
750 | f = 1 |
|
750 | f = 1 | |
751 |
|
751 | |||
752 | while n != bottom: |
|
752 | while n != bottom: | |
753 | p = self.changelog.parents(n)[0] |
|
753 | p = self.changelog.parents(n)[0] | |
754 | if i == f: |
|
754 | if i == f: | |
755 | l.append(n) |
|
755 | l.append(n) | |
756 | f = f * 2 |
|
756 | f = f * 2 | |
757 | n = p |
|
757 | n = p | |
758 | i += 1 |
|
758 | i += 1 | |
759 |
|
759 | |||
760 | r.append(l) |
|
760 | r.append(l) | |
761 |
|
761 | |||
762 | return r |
|
762 | return r | |
763 |
|
763 | |||
764 | def newer(self, nodes): |
|
764 | def newer(self, nodes): | |
765 | m = {} |
|
765 | m = {} | |
766 | nl = [] |
|
766 | nl = [] | |
767 | pm = {} |
|
767 | pm = {} | |
768 | cl = self.changelog |
|
768 | cl = self.changelog | |
769 | t = l = cl.count() |
|
769 | t = l = cl.count() | |
770 |
|
770 | |||
771 | # find the lowest numbered node |
|
771 | # find the lowest numbered node | |
772 | for n in nodes: |
|
772 | for n in nodes: | |
773 | l = min(l, cl.rev(n)) |
|
773 | l = min(l, cl.rev(n)) | |
774 | m[n] = 1 |
|
774 | m[n] = 1 | |
775 |
|
775 | |||
776 | for i in xrange(l, t): |
|
776 | for i in xrange(l, t): | |
777 | n = cl.node(i) |
|
777 | n = cl.node(i) | |
778 | if n in m: # explicitly listed |
|
778 | if n in m: # explicitly listed | |
779 | pm[n] = 1 |
|
779 | pm[n] = 1 | |
780 | nl.append(n) |
|
780 | nl.append(n) | |
781 | continue |
|
781 | continue | |
782 | for p in cl.parents(n): |
|
782 | for p in cl.parents(n): | |
783 | if p in pm: # parent listed |
|
783 | if p in pm: # parent listed | |
784 | pm[n] = 1 |
|
784 | pm[n] = 1 | |
785 | nl.append(n) |
|
785 | nl.append(n) | |
786 | break |
|
786 | break | |
787 |
|
787 | |||
788 | return nl |
|
788 | return nl | |
789 |
|
789 | |||
790 | def getchangegroup(self, remote): |
|
790 | def getchangegroup(self, remote): | |
791 | m = self.changelog.nodemap |
|
791 | m = self.changelog.nodemap | |
792 | search = [] |
|
792 | search = [] | |
793 | fetch = [] |
|
793 | fetch = [] | |
794 | seen = {} |
|
794 | seen = {} | |
795 | seenbranch = {} |
|
795 | seenbranch = {} | |
796 |
|
796 | |||
797 | # if we have an empty repo, fetch everything |
|
797 | # if we have an empty repo, fetch everything | |
798 | if self.changelog.tip() == nullid: |
|
798 | if self.changelog.tip() == nullid: | |
799 | self.ui.status("requesting all changes\n") |
|
799 | self.ui.status("requesting all changes\n") | |
800 | return remote.changegroup([nullid]) |
|
800 | return remote.changegroup([nullid]) | |
801 |
|
801 | |||
802 | # otherwise, assume we're closer to the tip than the root |
|
802 | # otherwise, assume we're closer to the tip than the root | |
803 | self.ui.status("searching for changes\n") |
|
803 | self.ui.status("searching for changes\n") | |
804 | heads = remote.heads() |
|
804 | heads = remote.heads() | |
805 | unknown = [] |
|
805 | unknown = [] | |
806 | for h in heads: |
|
806 | for h in heads: | |
807 | if h not in m: |
|
807 | if h not in m: | |
808 | unknown.append(h) |
|
808 | unknown.append(h) | |
809 |
|
809 | |||
810 | if not unknown: |
|
810 | if not unknown: | |
811 | self.ui.status("nothing to do!\n") |
|
811 | self.ui.status("nothing to do!\n") | |
812 | return None |
|
812 | return None | |
813 |
|
813 | |||
814 | rep = {} |
|
814 | rep = {} | |
815 | reqcnt = 0 |
|
815 | reqcnt = 0 | |
816 |
|
816 | |||
817 | unknown = remote.branches(unknown) |
|
817 | unknown = remote.branches(unknown) | |
818 | while unknown: |
|
818 | while unknown: | |
819 | r = [] |
|
819 | r = [] | |
820 | while unknown: |
|
820 | while unknown: | |
821 | n = unknown.pop(0) |
|
821 | n = unknown.pop(0) | |
822 | if n[0] in seen: |
|
822 | if n[0] in seen: | |
823 | continue |
|
823 | continue | |
824 |
|
824 | |||
825 | self.ui.debug("examining %s:%s\n" % (short(n[0]), short(n[1]))) |
|
825 | self.ui.debug("examining %s:%s\n" % (short(n[0]), short(n[1]))) | |
826 | if n[0] == nullid: |
|
826 | if n[0] == nullid: | |
827 | break |
|
827 | break | |
828 | if n in seenbranch: |
|
828 | if n in seenbranch: | |
829 | self.ui.debug("branch already found\n") |
|
829 | self.ui.debug("branch already found\n") | |
830 | continue |
|
830 | continue | |
831 | if n[1] and n[1] in m: # do we know the base? |
|
831 | if n[1] and n[1] in m: # do we know the base? | |
832 | self.ui.debug("found incomplete branch %s:%s\n" |
|
832 | self.ui.debug("found incomplete branch %s:%s\n" | |
833 | % (short(n[0]), short(n[1]))) |
|
833 | % (short(n[0]), short(n[1]))) | |
834 | search.append(n) # schedule branch range for scanning |
|
834 | search.append(n) # schedule branch range for scanning | |
835 | seenbranch[n] = 1 |
|
835 | seenbranch[n] = 1 | |
836 | else: |
|
836 | else: | |
837 | if n[1] not in seen and n[1] not in fetch: |
|
837 | if n[1] not in seen and n[1] not in fetch: | |
838 | if n[2] in m and n[3] in m: |
|
838 | if n[2] in m and n[3] in m: | |
839 | self.ui.debug("found new changeset %s\n" % |
|
839 | self.ui.debug("found new changeset %s\n" % | |
840 | short(n[1])) |
|
840 | short(n[1])) | |
841 | fetch.append(n[1]) # earliest unknown |
|
841 | fetch.append(n[1]) # earliest unknown | |
842 | continue |
|
842 | continue | |
843 |
|
843 | |||
844 | for a in n[2:4]: |
|
844 | for a in n[2:4]: | |
845 | if a not in rep: |
|
845 | if a not in rep: | |
846 | r.append(a) |
|
846 | r.append(a) | |
847 | rep[a] = 1 |
|
847 | rep[a] = 1 | |
848 |
|
848 | |||
849 | seen[n[0]] = 1 |
|
849 | seen[n[0]] = 1 | |
850 |
|
850 | |||
851 | if r: |
|
851 | if r: | |
852 | reqcnt += 1 |
|
852 | reqcnt += 1 | |
853 | self.ui.debug("request %d: %s\n" % |
|
853 | self.ui.debug("request %d: %s\n" % | |
854 | (reqcnt, " ".join(map(short, r)))) |
|
854 | (reqcnt, " ".join(map(short, r)))) | |
855 | for p in range(0, len(r), 10): |
|
855 | for p in range(0, len(r), 10): | |
856 | for b in remote.branches(r[p:p+10]): |
|
856 | for b in remote.branches(r[p:p+10]): | |
857 | self.ui.debug("received %s:%s\n" % |
|
857 | self.ui.debug("received %s:%s\n" % | |
858 | (short(b[0]), short(b[1]))) |
|
858 | (short(b[0]), short(b[1]))) | |
859 | if b[0] not in m and b[0] not in seen: |
|
859 | if b[0] not in m and b[0] not in seen: | |
860 | unknown.append(b) |
|
860 | unknown.append(b) | |
861 |
|
861 | |||
862 | while search: |
|
862 | while search: | |
863 | n = search.pop(0) |
|
863 | n = search.pop(0) | |
864 | reqcnt += 1 |
|
864 | reqcnt += 1 | |
865 | l = remote.between([(n[0], n[1])])[0] |
|
865 | l = remote.between([(n[0], n[1])])[0] | |
866 | l.append(n[1]) |
|
866 | l.append(n[1]) | |
867 | p = n[0] |
|
867 | p = n[0] | |
868 | f = 1 |
|
868 | f = 1 | |
869 | for i in l: |
|
869 | for i in l: | |
870 | self.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) |
|
870 | self.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) | |
871 | if i in m: |
|
871 | if i in m: | |
872 | if f <= 2: |
|
872 | if f <= 2: | |
873 | self.ui.debug("found new branch changeset %s\n" % |
|
873 | self.ui.debug("found new branch changeset %s\n" % | |
874 | short(p)) |
|
874 | short(p)) | |
875 | fetch.append(p) |
|
875 | fetch.append(p) | |
876 | else: |
|
876 | else: | |
877 | self.ui.debug("narrowed branch search to %s:%s\n" |
|
877 | self.ui.debug("narrowed branch search to %s:%s\n" | |
878 | % (short(p), short(i))) |
|
878 | % (short(p), short(i))) | |
879 | search.append((p, i)) |
|
879 | search.append((p, i)) | |
880 | break |
|
880 | break | |
881 | p, f = i, f * 2 |
|
881 | p, f = i, f * 2 | |
882 |
|
882 | |||
883 | for f in fetch: |
|
883 | for f in fetch: | |
884 | if f in m: |
|
884 | if f in m: | |
885 | raise "already have", short(f[:4]) |
|
885 | raise "already have", short(f[:4]) | |
886 |
|
886 | |||
887 | self.ui.note("adding new changesets starting at " + |
|
887 | self.ui.note("adding new changesets starting at " + | |
888 | " ".join([short(f) for f in fetch]) + "\n") |
|
888 | " ".join([short(f) for f in fetch]) + "\n") | |
889 |
|
889 | |||
890 | self.ui.debug("%d total queries\n" % reqcnt) |
|
890 | self.ui.debug("%d total queries\n" % reqcnt) | |
891 |
|
891 | |||
892 | return remote.changegroup(fetch) |
|
892 | return remote.changegroup(fetch) | |
893 |
|
893 | |||
894 | def changegroup(self, basenodes): |
|
894 | def changegroup(self, basenodes): | |
895 | nodes = self.newer(basenodes) |
|
895 | nodes = self.newer(basenodes) | |
896 |
|
896 | |||
897 | # construct the link map |
|
897 | # construct the link map | |
898 | linkmap = {} |
|
898 | linkmap = {} | |
899 | for n in nodes: |
|
899 | for n in nodes: | |
900 | linkmap[self.changelog.rev(n)] = n |
|
900 | linkmap[self.changelog.rev(n)] = n | |
901 |
|
901 | |||
902 | # construct a list of all changed files |
|
902 | # construct a list of all changed files | |
903 | changed = {} |
|
903 | changed = {} | |
904 | for n in nodes: |
|
904 | for n in nodes: | |
905 | c = self.changelog.read(n) |
|
905 | c = self.changelog.read(n) | |
906 | for f in c[3]: |
|
906 | for f in c[3]: | |
907 | changed[f] = 1 |
|
907 | changed[f] = 1 | |
908 | changed = changed.keys() |
|
908 | changed = changed.keys() | |
909 | changed.sort() |
|
909 | changed.sort() | |
910 |
|
910 | |||
911 | # the changegroup is changesets + manifests + all file revs |
|
911 | # the changegroup is changesets + manifests + all file revs | |
912 | revs = [ self.changelog.rev(n) for n in nodes ] |
|
912 | revs = [ self.changelog.rev(n) for n in nodes ] | |
913 |
|
913 | |||
914 | for y in self.changelog.group(linkmap): yield y |
|
914 | for y in self.changelog.group(linkmap): yield y | |
915 | for y in self.manifest.group(linkmap): yield y |
|
915 | for y in self.manifest.group(linkmap): yield y | |
916 | for f in changed: |
|
916 | for f in changed: | |
917 | yield struct.pack(">l", len(f) + 4) + f |
|
917 | yield struct.pack(">l", len(f) + 4) + f | |
918 | g = self.file(f).group(linkmap) |
|
918 | g = self.file(f).group(linkmap) | |
919 | for y in g: |
|
919 | for y in g: | |
920 | yield y |
|
920 | yield y | |
921 |
|
921 | |||
922 | def addchangegroup(self, generator): |
|
922 | def addchangegroup(self, generator): | |
923 |
|
923 | |||
924 | class genread: |
|
924 | class genread: | |
925 | def __init__(self, generator): |
|
925 | def __init__(self, generator): | |
926 | self.g = generator |
|
926 | self.g = generator | |
927 | self.buf = "" |
|
927 | self.buf = "" | |
928 | def read(self, l): |
|
928 | def read(self, l): | |
929 | while l > len(self.buf): |
|
929 | while l > len(self.buf): | |
930 | try: |
|
930 | try: | |
931 | self.buf += self.g.next() |
|
931 | self.buf += self.g.next() | |
932 | except StopIteration: |
|
932 | except StopIteration: | |
933 | break |
|
933 | break | |
934 | d, self.buf = self.buf[:l], self.buf[l:] |
|
934 | d, self.buf = self.buf[:l], self.buf[l:] | |
935 | return d |
|
935 | return d | |
936 |
|
936 | |||
937 | def getchunk(): |
|
937 | def getchunk(): | |
938 | d = source.read(4) |
|
938 | d = source.read(4) | |
939 | if not d: return "" |
|
939 | if not d: return "" | |
940 | l = struct.unpack(">l", d)[0] |
|
940 | l = struct.unpack(">l", d)[0] | |
941 | if l <= 4: return "" |
|
941 | if l <= 4: return "" | |
942 | return source.read(l - 4) |
|
942 | return source.read(l - 4) | |
943 |
|
943 | |||
944 | def getgroup(): |
|
944 | def getgroup(): | |
945 | while 1: |
|
945 | while 1: | |
946 | c = getchunk() |
|
946 | c = getchunk() | |
947 | if not c: break |
|
947 | if not c: break | |
948 | yield c |
|
948 | yield c | |
949 |
|
949 | |||
950 | def csmap(x): |
|
950 | def csmap(x): | |
951 | self.ui.debug("add changeset %s\n" % short(x)) |
|
951 | self.ui.debug("add changeset %s\n" % short(x)) | |
952 | return self.changelog.count() |
|
952 | return self.changelog.count() | |
953 |
|
953 | |||
954 | def revmap(x): |
|
954 | def revmap(x): | |
955 | return self.changelog.rev(x) |
|
955 | return self.changelog.rev(x) | |
956 |
|
956 | |||
957 | if not generator: return |
|
957 | if not generator: return | |
958 | changesets = files = revisions = 0 |
|
958 | changesets = files = revisions = 0 | |
959 |
|
959 | |||
960 | source = genread(generator) |
|
960 | source = genread(generator) | |
961 | lock = self.lock() |
|
961 | lock = self.lock() | |
962 | tr = self.transaction() |
|
962 | tr = self.transaction() | |
963 |
|
963 | |||
964 | # pull off the changeset group |
|
964 | # pull off the changeset group | |
965 | self.ui.status("adding changesets\n") |
|
965 | self.ui.status("adding changesets\n") | |
966 | co = self.changelog.tip() |
|
966 | co = self.changelog.tip() | |
967 | cn = self.changelog.addgroup(getgroup(), csmap, tr, 1) # unique |
|
967 | cn = self.changelog.addgroup(getgroup(), csmap, tr, 1) # unique | |
968 | changesets = self.changelog.rev(cn) - self.changelog.rev(co) |
|
968 | changesets = self.changelog.rev(cn) - self.changelog.rev(co) | |
969 |
|
969 | |||
970 | # pull off the manifest group |
|
970 | # pull off the manifest group | |
971 | self.ui.status("adding manifests\n") |
|
971 | self.ui.status("adding manifests\n") | |
972 | mm = self.manifest.tip() |
|
972 | mm = self.manifest.tip() | |
973 | mo = self.manifest.addgroup(getgroup(), revmap, tr) |
|
973 | mo = self.manifest.addgroup(getgroup(), revmap, tr) | |
974 |
|
974 | |||
975 | # process the files |
|
975 | # process the files | |
976 | self.ui.status("adding file revisions\n") |
|
976 | self.ui.status("adding file revisions\n") | |
977 | while 1: |
|
977 | while 1: | |
978 | f = getchunk() |
|
978 | f = getchunk() | |
979 | if not f: break |
|
979 | if not f: break | |
980 | self.ui.debug("adding %s revisions\n" % f) |
|
980 | self.ui.debug("adding %s revisions\n" % f) | |
981 | fl = self.file(f) |
|
981 | fl = self.file(f) | |
982 | o = fl.tip() |
|
982 | o = fl.tip() | |
983 | n = fl.addgroup(getgroup(), revmap, tr) |
|
983 | n = fl.addgroup(getgroup(), revmap, tr) | |
984 | revisions += fl.rev(n) - fl.rev(o) |
|
984 | revisions += fl.rev(n) - fl.rev(o) | |
985 | files += 1 |
|
985 | files += 1 | |
986 |
|
986 | |||
987 | self.ui.status(("modified %d files, added %d changesets" + |
|
987 | self.ui.status(("modified %d files, added %d changesets" + | |
988 | " and %d new revisions\n") |
|
988 | " and %d new revisions\n") | |
989 | % (files, changesets, revisions)) |
|
989 | % (files, changesets, revisions)) | |
990 |
|
990 | |||
991 | tr.close() |
|
991 | tr.close() | |
992 | return |
|
992 | return | |
993 |
|
993 | |||
994 | def update(self, node, allow=False, force=False): |
|
994 | def update(self, node, allow=False, force=False): | |
995 | pl = self.dirstate.parents() |
|
995 | pl = self.dirstate.parents() | |
996 | if not force and pl[1] != nullid: |
|
996 | if not force and pl[1] != nullid: | |
997 | self.ui.warn("aborting: outstanding uncommitted merges\n") |
|
997 | self.ui.warn("aborting: outstanding uncommitted merges\n") | |
998 | return |
|
998 | return | |
999 |
|
999 | |||
1000 | p1, p2 = pl[0], node |
|
1000 | p1, p2 = pl[0], node | |
1001 | pa = self.changelog.ancestor(p1, p2) |
|
1001 | pa = self.changelog.ancestor(p1, p2) | |
1002 | m1n = self.changelog.read(p1)[0] |
|
1002 | m1n = self.changelog.read(p1)[0] | |
1003 | m2n = self.changelog.read(p2)[0] |
|
1003 | m2n = self.changelog.read(p2)[0] | |
1004 | man = self.manifest.ancestor(m1n, m2n) |
|
1004 | man = self.manifest.ancestor(m1n, m2n) | |
1005 | m1 = self.manifest.read(m1n) |
|
1005 | m1 = self.manifest.read(m1n) | |
1006 | mf1 = self.manifest.readflags(m1n) |
|
1006 | mf1 = self.manifest.readflags(m1n) | |
1007 | m2 = self.manifest.read(m2n) |
|
1007 | m2 = self.manifest.read(m2n) | |
1008 | mf2 = self.manifest.readflags(m2n) |
|
1008 | mf2 = self.manifest.readflags(m2n) | |
1009 | ma = self.manifest.read(man) |
|
1009 | ma = self.manifest.read(man) | |
1010 | mfa = self.manifest.readflags(man) |
|
1010 | mfa = self.manifest.readflags(man) | |
1011 |
|
1011 | |||
1012 | (c, a, d, u) = self.diffdir(self.root) |
|
1012 | (c, a, d, u) = self.diffdir(self.root) | |
1013 |
|
1013 | |||
1014 | # is this a jump, or a merge? i.e. is there a linear path |
|
1014 | # is this a jump, or a merge? i.e. is there a linear path | |
1015 | # from p1 to p2? |
|
1015 | # from p1 to p2? | |
1016 | linear_path = (pa == p1 or pa == p2) |
|
1016 | linear_path = (pa == p1 or pa == p2) | |
1017 |
|
1017 | |||
1018 | # resolve the manifest to determine which files |
|
1018 | # resolve the manifest to determine which files | |
1019 | # we care about merging |
|
1019 | # we care about merging | |
1020 | self.ui.note("resolving manifests\n") |
|
1020 | self.ui.note("resolving manifests\n") | |
1021 | self.ui.debug(" ancestor %s local %s remote %s\n" % |
|
1021 | self.ui.debug(" ancestor %s local %s remote %s\n" % | |
1022 | (short(man), short(m1n), short(m2n))) |
|
1022 | (short(man), short(m1n), short(m2n))) | |
1023 |
|
1023 | |||
1024 | merge = {} |
|
1024 | merge = {} | |
1025 | get = {} |
|
1025 | get = {} | |
1026 | remove = [] |
|
1026 | remove = [] | |
1027 | mark = {} |
|
1027 | mark = {} | |
1028 |
|
1028 | |||
1029 | # construct a working dir manifest |
|
1029 | # construct a working dir manifest | |
1030 | mw = m1.copy() |
|
1030 | mw = m1.copy() | |
1031 | mfw = mf1.copy() |
|
1031 | mfw = mf1.copy() | |
1032 | for f in a + c + u: |
|
1032 | for f in a + c + u: | |
1033 | mw[f] = "" |
|
1033 | mw[f] = "" | |
1034 | mfw[f] = is_exec(self.wjoin(f)) |
|
1034 | mfw[f] = is_exec(self.wjoin(f)) | |
1035 | for f in d: |
|
1035 | for f in d: | |
1036 | if f in mw: del mw[f] |
|
1036 | if f in mw: del mw[f] | |
1037 |
|
1037 | |||
1038 | # If we're jumping between revisions (as opposed to merging), |
|
1038 | # If we're jumping between revisions (as opposed to merging), | |
1039 | # and if neither the working directory nor the target rev has |
|
1039 | # and if neither the working directory nor the target rev has | |
1040 | # the file, then we need to remove it from the dirstate, to |
|
1040 | # the file, then we need to remove it from the dirstate, to | |
1041 | # prevent the dirstate from listing the file when it is no |
|
1041 | # prevent the dirstate from listing the file when it is no | |
1042 | # longer in the manifest. |
|
1042 | # longer in the manifest. | |
1043 | if linear_path and f not in m2: |
|
1043 | if linear_path and f not in m2: | |
1044 | self.dirstate.forget((f,)) |
|
1044 | self.dirstate.forget((f,)) | |
1045 |
|
1045 | |||
1046 | for f, n in mw.iteritems(): |
|
1046 | for f, n in mw.iteritems(): | |
1047 | if f in m2: |
|
1047 | if f in m2: | |
1048 | s = 0 |
|
1048 | s = 0 | |
1049 |
|
1049 | |||
1050 | # is the wfile new since m1, and match m2? |
|
1050 | # is the wfile new since m1, and match m2? | |
1051 | if n not in m1: |
|
1051 | if n not in m1: | |
1052 | t1 = self.wfile(f).read() |
|
1052 | t1 = self.wfile(f).read() | |
1053 | t2 = self.file(f).revision(m2[f]) |
|
1053 | t2 = self.file(f).revision(m2[f]) | |
1054 | if cmp(t1, t2) == 0: |
|
1054 | if cmp(t1, t2) == 0: | |
1055 | mark[f] = 1 |
|
1055 | mark[f] = 1 | |
1056 | n = m2[f] |
|
1056 | n = m2[f] | |
1057 | del t1, t2 |
|
1057 | del t1, t2 | |
1058 |
|
1058 | |||
1059 | # are files different? |
|
1059 | # are files different? | |
1060 | if n != m2[f]: |
|
1060 | if n != m2[f]: | |
1061 | a = ma.get(f, nullid) |
|
1061 | a = ma.get(f, nullid) | |
1062 | # are both different from the ancestor? |
|
1062 | # are both different from the ancestor? | |
1063 | if n != a and m2[f] != a: |
|
1063 | if n != a and m2[f] != a: | |
1064 | self.ui.debug(" %s versions differ, resolve\n" % f) |
|
1064 | self.ui.debug(" %s versions differ, resolve\n" % f) | |
1065 | # merge executable bits |
|
1065 | # merge executable bits | |
1066 | # "if we changed or they changed, change in merge" |
|
1066 | # "if we changed or they changed, change in merge" | |
1067 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] |
|
1067 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] | |
1068 | mode = ((a^b) | (a^c)) ^ a |
|
1068 | mode = ((a^b) | (a^c)) ^ a | |
1069 | merge[f] = (m1.get(f, nullid), m2[f], mode) |
|
1069 | merge[f] = (m1.get(f, nullid), m2[f], mode) | |
1070 | s = 1 |
|
1070 | s = 1 | |
1071 | # are we clobbering? |
|
1071 | # are we clobbering? | |
1072 | # is remote's version newer? |
|
1072 | # is remote's version newer? | |
1073 | # or are we going back in time? |
|
1073 | # or are we going back in time? | |
1074 | elif force or m2[f] != a or (p2 == pa and mw[f] == m1[f]): |
|
1074 | elif force or m2[f] != a or (p2 == pa and mw[f] == m1[f]): | |
1075 | self.ui.debug(" remote %s is newer, get\n" % f) |
|
1075 | self.ui.debug(" remote %s is newer, get\n" % f) | |
1076 | get[f] = m2[f] |
|
1076 | get[f] = m2[f] | |
1077 | s = 1 |
|
1077 | s = 1 | |
1078 | else: |
|
1078 | else: | |
1079 | mark[f] = 1 |
|
1079 | mark[f] = 1 | |
1080 |
|
1080 | |||
1081 | if not s and mfw[f] != mf2[f]: |
|
1081 | if not s and mfw[f] != mf2[f]: | |
1082 | if force: |
|
1082 | if force: | |
1083 | self.ui.debug(" updating permissions for %s\n" % f) |
|
1083 | self.ui.debug(" updating permissions for %s\n" % f) | |
1084 | set_exec(self.wjoin(f), mf2[f]) |
|
1084 | set_exec(self.wjoin(f), mf2[f]) | |
1085 | else: |
|
1085 | else: | |
1086 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] |
|
1086 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] | |
1087 | mode = ((a^b) | (a^c)) ^ a |
|
1087 | mode = ((a^b) | (a^c)) ^ a | |
1088 | if mode != b: |
|
1088 | if mode != b: | |
1089 | self.ui.debug(" updating permissions for %s\n" % f) |
|
1089 | self.ui.debug(" updating permissions for %s\n" % f) | |
1090 | set_exec(self.wjoin(f), mode) |
|
1090 | set_exec(self.wjoin(f), mode) | |
1091 | mark[f] = 1 |
|
1091 | mark[f] = 1 | |
1092 | del m2[f] |
|
1092 | del m2[f] | |
1093 | elif f in ma: |
|
1093 | elif f in ma: | |
1094 | if not force and n != ma[f]: |
|
1094 | if not force and n != ma[f]: | |
|
1095 | r = "" | |||
|
1096 | if linear_path or allow: | |||
1095 | r = self.ui.prompt( |
|
1097 | r = self.ui.prompt( | |
1096 | (" local changed %s which remote deleted\n" % f) + |
|
1098 | (" local changed %s which remote deleted\n" % f) + | |
1097 | "(k)eep or (d)elete?", "[kd]", "k") |
|
1099 | "(k)eep or (d)elete?", "[kd]", "k") | |
1098 | if r == "d": |
|
1100 | if r == "d": | |
1099 | remove.append(f) |
|
1101 | remove.append(f) | |
1100 | else: |
|
1102 | else: | |
1101 | self.ui.debug("other deleted %s\n" % f) |
|
1103 | self.ui.debug("other deleted %s\n" % f) | |
1102 | remove.append(f) # other deleted it |
|
1104 | remove.append(f) # other deleted it | |
1103 | else: |
|
1105 | else: | |
1104 | if n == m1.get(f, nullid): # same as parent |
|
1106 | if n == m1.get(f, nullid): # same as parent | |
1105 | if p2 == pa: # going backwards? |
|
1107 | if p2 == pa: # going backwards? | |
1106 | self.ui.debug("remote deleted %s\n" % f) |
|
1108 | self.ui.debug("remote deleted %s\n" % f) | |
1107 | remove.append(f) |
|
1109 | remove.append(f) | |
1108 | else: |
|
1110 | else: | |
1109 | self.ui.debug("local created %s, keeping\n" % f) |
|
1111 | self.ui.debug("local created %s, keeping\n" % f) | |
1110 | else: |
|
1112 | else: | |
1111 | self.ui.debug("working dir created %s, keeping\n" % f) |
|
1113 | self.ui.debug("working dir created %s, keeping\n" % f) | |
1112 |
|
1114 | |||
1113 | for f, n in m2.iteritems(): |
|
1115 | for f, n in m2.iteritems(): | |
1114 | if f[0] == "/": continue |
|
1116 | if f[0] == "/": continue | |
1115 | if not force and f in ma and n != ma[f]: |
|
1117 | if not force and f in ma and n != ma[f]: | |
|
1118 | r = "" | |||
|
1119 | if linear_path or allow: | |||
1116 | r = self.ui.prompt( |
|
1120 | r = self.ui.prompt( | |
1117 | ("remote changed %s which local deleted\n" % f) + |
|
1121 | ("remote changed %s which local deleted\n" % f) + | |
1118 | "(k)eep or (d)elete?", "[kd]", "k") |
|
1122 | "(k)eep or (d)elete?", "[kd]", "k") | |
1119 | if r == "d": remove.append(f) |
|
1123 | if r == "d": remove.append(f) | |
1120 | else: |
|
1124 | else: | |
1121 | self.ui.debug("remote created %s\n" % f) |
|
1125 | self.ui.debug("remote created %s\n" % f) | |
1122 | get[f] = n |
|
1126 | get[f] = n | |
1123 |
|
1127 | |||
1124 | del mw, m1, m2, ma |
|
1128 | del mw, m1, m2, ma | |
1125 |
|
1129 | |||
1126 | if force: |
|
1130 | if force: | |
1127 | for f in merge: |
|
1131 | for f in merge: | |
1128 | get[f] = merge[f][1] |
|
1132 | get[f] = merge[f][1] | |
1129 | merge = {} |
|
1133 | merge = {} | |
1130 |
|
1134 | |||
1131 | if linear_path: |
|
1135 | if linear_path: | |
1132 | # we don't need to do any magic, just jump to the new rev |
|
1136 | # we don't need to do any magic, just jump to the new rev | |
1133 | mode = 'n' |
|
1137 | mode = 'n' | |
1134 | p1, p2 = p2, nullid |
|
1138 | p1, p2 = p2, nullid | |
1135 | else: |
|
1139 | else: | |
1136 | if not allow: |
|
1140 | if not allow: | |
1137 | self.ui.status("this update spans a branch" + |
|
1141 | self.ui.status("this update spans a branch" + | |
1138 | " affecting the following files:\n") |
|
1142 | " affecting the following files:\n") | |
1139 | fl = merge.keys() + get.keys() |
|
1143 | fl = merge.keys() + get.keys() | |
1140 | fl.sort() |
|
1144 | fl.sort() | |
1141 | for f in fl: |
|
1145 | for f in fl: | |
1142 | cf = "" |
|
1146 | cf = "" | |
1143 | if f in merge: cf = " (resolve)" |
|
1147 | if f in merge: cf = " (resolve)" | |
1144 | self.ui.status(" %s%s\n" % (f, cf)) |
|
1148 | self.ui.status(" %s%s\n" % (f, cf)) | |
1145 | self.ui.warn("aborting update spanning branches!\n") |
|
1149 | self.ui.warn("aborting update spanning branches!\n") | |
1146 | self.ui.status("(use update -m to perform a branch merge)\n") |
|
1150 | self.ui.status("(use update -m to perform a branch merge)\n") | |
1147 | return 1 |
|
1151 | return 1 | |
1148 | # we have to remember what files we needed to get/change |
|
1152 | # we have to remember what files we needed to get/change | |
1149 | # because any file that's different from either one of its |
|
1153 | # because any file that's different from either one of its | |
1150 | # parents must be in the changeset |
|
1154 | # parents must be in the changeset | |
1151 | mode = 'm' |
|
1155 | mode = 'm' | |
1152 | self.dirstate.update(mark.keys(), "m") |
|
1156 | self.dirstate.update(mark.keys(), "m") | |
1153 |
|
1157 | |||
1154 | self.dirstate.setparents(p1, p2) |
|
1158 | self.dirstate.setparents(p1, p2) | |
1155 |
|
1159 | |||
1156 | # get the files we don't need to change |
|
1160 | # get the files we don't need to change | |
1157 | files = get.keys() |
|
1161 | files = get.keys() | |
1158 | files.sort() |
|
1162 | files.sort() | |
1159 | for f in files: |
|
1163 | for f in files: | |
1160 | if f[0] == "/": continue |
|
1164 | if f[0] == "/": continue | |
1161 | self.ui.note("getting %s\n" % f) |
|
1165 | self.ui.note("getting %s\n" % f) | |
1162 | t = self.file(f).read(get[f]) |
|
1166 | t = self.file(f).read(get[f]) | |
1163 | try: |
|
1167 | try: | |
1164 | self.wfile(f, "w").write(t) |
|
1168 | self.wfile(f, "w").write(t) | |
1165 | except IOError: |
|
1169 | except IOError: | |
1166 | os.makedirs(os.path.dirname(self.wjoin(f))) |
|
1170 | os.makedirs(os.path.dirname(self.wjoin(f))) | |
1167 | self.wfile(f, "w").write(t) |
|
1171 | self.wfile(f, "w").write(t) | |
1168 | set_exec(self.wjoin(f), mf2[f]) |
|
1172 | set_exec(self.wjoin(f), mf2[f]) | |
1169 | self.dirstate.update([f], mode) |
|
1173 | self.dirstate.update([f], mode) | |
1170 |
|
1174 | |||
1171 | # merge the tricky bits |
|
1175 | # merge the tricky bits | |
1172 | files = merge.keys() |
|
1176 | files = merge.keys() | |
1173 | files.sort() |
|
1177 | files.sort() | |
1174 | for f in files: |
|
1178 | for f in files: | |
1175 | self.ui.status("merging %s\n" % f) |
|
1179 | self.ui.status("merging %s\n" % f) | |
1176 | m, o, flag = merge[f] |
|
1180 | m, o, flag = merge[f] | |
1177 | self.merge3(f, m, o) |
|
1181 | self.merge3(f, m, o) | |
1178 | set_exec(self.wjoin(f), flag) |
|
1182 | set_exec(self.wjoin(f), flag) | |
1179 | self.dirstate.update([f], 'm') |
|
1183 | self.dirstate.update([f], 'm') | |
1180 |
|
1184 | |||
1181 | for f in remove: |
|
1185 | for f in remove: | |
1182 | self.ui.note("removing %s\n" % f) |
|
1186 | self.ui.note("removing %s\n" % f) | |
1183 | os.unlink(f) |
|
1187 | os.unlink(f) | |
1184 | if mode == 'n': |
|
1188 | if mode == 'n': | |
1185 | self.dirstate.forget(remove) |
|
1189 | self.dirstate.forget(remove) | |
1186 | else: |
|
1190 | else: | |
1187 | self.dirstate.update(remove, 'r') |
|
1191 | self.dirstate.update(remove, 'r') | |
1188 |
|
1192 | |||
1189 | def merge3(self, fn, my, other): |
|
1193 | def merge3(self, fn, my, other): | |
1190 | """perform a 3-way merge in the working directory""" |
|
1194 | """perform a 3-way merge in the working directory""" | |
1191 |
|
1195 | |||
1192 | def temp(prefix, node): |
|
1196 | def temp(prefix, node): | |
1193 | pre = "%s~%s." % (os.path.basename(fn), prefix) |
|
1197 | pre = "%s~%s." % (os.path.basename(fn), prefix) | |
1194 | (fd, name) = tempfile.mkstemp("", pre) |
|
1198 | (fd, name) = tempfile.mkstemp("", pre) | |
1195 | f = os.fdopen(fd, "w") |
|
1199 | f = os.fdopen(fd, "w") | |
1196 | f.write(fl.revision(node)) |
|
1200 | f.write(fl.revision(node)) | |
1197 | f.close() |
|
1201 | f.close() | |
1198 | return name |
|
1202 | return name | |
1199 |
|
1203 | |||
1200 | fl = self.file(fn) |
|
1204 | fl = self.file(fn) | |
1201 | base = fl.ancestor(my, other) |
|
1205 | base = fl.ancestor(my, other) | |
1202 | a = self.wjoin(fn) |
|
1206 | a = self.wjoin(fn) | |
1203 | b = temp("base", base) |
|
1207 | b = temp("base", base) | |
1204 | c = temp("other", other) |
|
1208 | c = temp("other", other) | |
1205 |
|
1209 | |||
1206 | self.ui.note("resolving %s\n" % fn) |
|
1210 | self.ui.note("resolving %s\n" % fn) | |
1207 | self.ui.debug("file %s: other %s ancestor %s\n" % |
|
1211 | self.ui.debug("file %s: other %s ancestor %s\n" % | |
1208 | (fn, short(other), short(base))) |
|
1212 | (fn, short(other), short(base))) | |
1209 |
|
1213 | |||
1210 | cmd = os.environ.get("HGMERGE", "hgmerge") |
|
1214 | cmd = os.environ.get("HGMERGE", "hgmerge") | |
1211 | r = os.system("%s %s %s %s" % (cmd, a, b, c)) |
|
1215 | r = os.system("%s %s %s %s" % (cmd, a, b, c)) | |
1212 | if r: |
|
1216 | if r: | |
1213 | self.ui.warn("merging %s failed!\n" % fn) |
|
1217 | self.ui.warn("merging %s failed!\n" % fn) | |
1214 |
|
1218 | |||
1215 | os.unlink(b) |
|
1219 | os.unlink(b) | |
1216 | os.unlink(c) |
|
1220 | os.unlink(c) | |
1217 |
|
1221 | |||
1218 | def verify(self): |
|
1222 | def verify(self): | |
1219 | filelinkrevs = {} |
|
1223 | filelinkrevs = {} | |
1220 | filenodes = {} |
|
1224 | filenodes = {} | |
1221 | changesets = revisions = files = 0 |
|
1225 | changesets = revisions = files = 0 | |
1222 | errors = 0 |
|
1226 | errors = 0 | |
1223 |
|
1227 | |||
1224 | seen = {} |
|
1228 | seen = {} | |
1225 | self.ui.status("checking changesets\n") |
|
1229 | self.ui.status("checking changesets\n") | |
1226 | for i in range(self.changelog.count()): |
|
1230 | for i in range(self.changelog.count()): | |
1227 | changesets += 1 |
|
1231 | changesets += 1 | |
1228 | n = self.changelog.node(i) |
|
1232 | n = self.changelog.node(i) | |
1229 | if n in seen: |
|
1233 | if n in seen: | |
1230 | self.ui.warn("duplicate changeset at revision %d\n" % i) |
|
1234 | self.ui.warn("duplicate changeset at revision %d\n" % i) | |
1231 | errors += 1 |
|
1235 | errors += 1 | |
1232 | seen[n] = 1 |
|
1236 | seen[n] = 1 | |
1233 |
|
1237 | |||
1234 | for p in self.changelog.parents(n): |
|
1238 | for p in self.changelog.parents(n): | |
1235 | if p not in self.changelog.nodemap: |
|
1239 | if p not in self.changelog.nodemap: | |
1236 | self.ui.warn("changeset %s has unknown parent %s\n" % |
|
1240 | self.ui.warn("changeset %s has unknown parent %s\n" % | |
1237 | (short(n), short(p))) |
|
1241 | (short(n), short(p))) | |
1238 | errors += 1 |
|
1242 | errors += 1 | |
1239 | try: |
|
1243 | try: | |
1240 | changes = self.changelog.read(n) |
|
1244 | changes = self.changelog.read(n) | |
1241 | except Exception, inst: |
|
1245 | except Exception, inst: | |
1242 | self.ui.warn("unpacking changeset %s: %s\n" % (short(n), inst)) |
|
1246 | self.ui.warn("unpacking changeset %s: %s\n" % (short(n), inst)) | |
1243 | errors += 1 |
|
1247 | errors += 1 | |
1244 |
|
1248 | |||
1245 | for f in changes[3]: |
|
1249 | for f in changes[3]: | |
1246 | filelinkrevs.setdefault(f, []).append(i) |
|
1250 | filelinkrevs.setdefault(f, []).append(i) | |
1247 |
|
1251 | |||
1248 | seen = {} |
|
1252 | seen = {} | |
1249 | self.ui.status("checking manifests\n") |
|
1253 | self.ui.status("checking manifests\n") | |
1250 | for i in range(self.manifest.count()): |
|
1254 | for i in range(self.manifest.count()): | |
1251 | n = self.manifest.node(i) |
|
1255 | n = self.manifest.node(i) | |
1252 | if n in seen: |
|
1256 | if n in seen: | |
1253 | self.ui.warn("duplicate manifest at revision %d\n" % i) |
|
1257 | self.ui.warn("duplicate manifest at revision %d\n" % i) | |
1254 | errors += 1 |
|
1258 | errors += 1 | |
1255 | seen[n] = 1 |
|
1259 | seen[n] = 1 | |
1256 |
|
1260 | |||
1257 | for p in self.manifest.parents(n): |
|
1261 | for p in self.manifest.parents(n): | |
1258 | if p not in self.manifest.nodemap: |
|
1262 | if p not in self.manifest.nodemap: | |
1259 | self.ui.warn("manifest %s has unknown parent %s\n" % |
|
1263 | self.ui.warn("manifest %s has unknown parent %s\n" % | |
1260 | (short(n), short(p))) |
|
1264 | (short(n), short(p))) | |
1261 | errors += 1 |
|
1265 | errors += 1 | |
1262 |
|
1266 | |||
1263 | try: |
|
1267 | try: | |
1264 | delta = mdiff.patchtext(self.manifest.delta(n)) |
|
1268 | delta = mdiff.patchtext(self.manifest.delta(n)) | |
1265 | except KeyboardInterrupt: |
|
1269 | except KeyboardInterrupt: | |
1266 | print "aborted" |
|
1270 | print "aborted" | |
1267 | sys.exit(0) |
|
1271 | sys.exit(0) | |
1268 | except Exception, inst: |
|
1272 | except Exception, inst: | |
1269 | self.ui.warn("unpacking manifest %s: %s\n" |
|
1273 | self.ui.warn("unpacking manifest %s: %s\n" | |
1270 | % (short(n), inst)) |
|
1274 | % (short(n), inst)) | |
1271 | errors += 1 |
|
1275 | errors += 1 | |
1272 |
|
1276 | |||
1273 | ff = [ l.split('\0') for l in delta.splitlines() ] |
|
1277 | ff = [ l.split('\0') for l in delta.splitlines() ] | |
1274 | for f, fn in ff: |
|
1278 | for f, fn in ff: | |
1275 | filenodes.setdefault(f, {})[bin(fn[:40])] = 1 |
|
1279 | filenodes.setdefault(f, {})[bin(fn[:40])] = 1 | |
1276 |
|
1280 | |||
1277 | self.ui.status("crosschecking files in changesets and manifests\n") |
|
1281 | self.ui.status("crosschecking files in changesets and manifests\n") | |
1278 | for f in filenodes: |
|
1282 | for f in filenodes: | |
1279 | if f not in filelinkrevs: |
|
1283 | if f not in filelinkrevs: | |
1280 | self.ui.warn("file %s in manifest but not in changesets\n" % f) |
|
1284 | self.ui.warn("file %s in manifest but not in changesets\n" % f) | |
1281 | errors += 1 |
|
1285 | errors += 1 | |
1282 |
|
1286 | |||
1283 | for f in filelinkrevs: |
|
1287 | for f in filelinkrevs: | |
1284 | if f not in filenodes: |
|
1288 | if f not in filenodes: | |
1285 | self.ui.warn("file %s in changeset but not in manifest\n" % f) |
|
1289 | self.ui.warn("file %s in changeset but not in manifest\n" % f) | |
1286 | errors += 1 |
|
1290 | errors += 1 | |
1287 |
|
1291 | |||
1288 | self.ui.status("checking files\n") |
|
1292 | self.ui.status("checking files\n") | |
1289 | ff = filenodes.keys() |
|
1293 | ff = filenodes.keys() | |
1290 | ff.sort() |
|
1294 | ff.sort() | |
1291 | for f in ff: |
|
1295 | for f in ff: | |
1292 | if f == "/dev/null": continue |
|
1296 | if f == "/dev/null": continue | |
1293 | files += 1 |
|
1297 | files += 1 | |
1294 | fl = self.file(f) |
|
1298 | fl = self.file(f) | |
1295 | nodes = { nullid: 1 } |
|
1299 | nodes = { nullid: 1 } | |
1296 | seen = {} |
|
1300 | seen = {} | |
1297 | for i in range(fl.count()): |
|
1301 | for i in range(fl.count()): | |
1298 | revisions += 1 |
|
1302 | revisions += 1 | |
1299 | n = fl.node(i) |
|
1303 | n = fl.node(i) | |
1300 |
|
1304 | |||
1301 | if n in seen: |
|
1305 | if n in seen: | |
1302 | self.ui.warn("%s: duplicate revision %d\n" % (f, i)) |
|
1306 | self.ui.warn("%s: duplicate revision %d\n" % (f, i)) | |
1303 | errors += 1 |
|
1307 | errors += 1 | |
1304 |
|
1308 | |||
1305 | if n not in filenodes[f]: |
|
1309 | if n not in filenodes[f]: | |
1306 | self.ui.warn("%s: %d:%s not in manifests\n" |
|
1310 | self.ui.warn("%s: %d:%s not in manifests\n" | |
1307 | % (f, i, short(n))) |
|
1311 | % (f, i, short(n))) | |
1308 | print len(filenodes[f].keys()), fl.count(), f |
|
1312 | print len(filenodes[f].keys()), fl.count(), f | |
1309 | errors += 1 |
|
1313 | errors += 1 | |
1310 | else: |
|
1314 | else: | |
1311 | del filenodes[f][n] |
|
1315 | del filenodes[f][n] | |
1312 |
|
1316 | |||
1313 | flr = fl.linkrev(n) |
|
1317 | flr = fl.linkrev(n) | |
1314 | if flr not in filelinkrevs[f]: |
|
1318 | if flr not in filelinkrevs[f]: | |
1315 | self.ui.warn("%s:%s points to unexpected changeset %d\n" |
|
1319 | self.ui.warn("%s:%s points to unexpected changeset %d\n" | |
1316 | % (f, short(n), fl.linkrev(n))) |
|
1320 | % (f, short(n), fl.linkrev(n))) | |
1317 | errors += 1 |
|
1321 | errors += 1 | |
1318 | else: |
|
1322 | else: | |
1319 | filelinkrevs[f].remove(flr) |
|
1323 | filelinkrevs[f].remove(flr) | |
1320 |
|
1324 | |||
1321 | # verify contents |
|
1325 | # verify contents | |
1322 | try: |
|
1326 | try: | |
1323 | t = fl.read(n) |
|
1327 | t = fl.read(n) | |
1324 | except Exception, inst: |
|
1328 | except Exception, inst: | |
1325 | self.ui.warn("unpacking file %s %s: %s\n" |
|
1329 | self.ui.warn("unpacking file %s %s: %s\n" | |
1326 | % (f, short(n), inst)) |
|
1330 | % (f, short(n), inst)) | |
1327 | errors += 1 |
|
1331 | errors += 1 | |
1328 |
|
1332 | |||
1329 | # verify parents |
|
1333 | # verify parents | |
1330 | (p1, p2) = fl.parents(n) |
|
1334 | (p1, p2) = fl.parents(n) | |
1331 | if p1 not in nodes: |
|
1335 | if p1 not in nodes: | |
1332 | self.ui.warn("file %s:%s unknown parent 1 %s" % |
|
1336 | self.ui.warn("file %s:%s unknown parent 1 %s" % | |
1333 | (f, short(n), short(p1))) |
|
1337 | (f, short(n), short(p1))) | |
1334 | errors += 1 |
|
1338 | errors += 1 | |
1335 | if p2 not in nodes: |
|
1339 | if p2 not in nodes: | |
1336 | self.ui.warn("file %s:%s unknown parent 2 %s" % |
|
1340 | self.ui.warn("file %s:%s unknown parent 2 %s" % | |
1337 | (f, short(n), short(p1))) |
|
1341 | (f, short(n), short(p1))) | |
1338 | errors += 1 |
|
1342 | errors += 1 | |
1339 | nodes[n] = 1 |
|
1343 | nodes[n] = 1 | |
1340 |
|
1344 | |||
1341 | # cross-check |
|
1345 | # cross-check | |
1342 | for node in filenodes[f]: |
|
1346 | for node in filenodes[f]: | |
1343 | self.ui.warn("node %s in manifests not in %s\n" |
|
1347 | self.ui.warn("node %s in manifests not in %s\n" | |
1344 | % (hex(n), f)) |
|
1348 | % (hex(n), f)) | |
1345 | errors += 1 |
|
1349 | errors += 1 | |
1346 |
|
1350 | |||
1347 | self.ui.status("%d files, %d changesets, %d total revisions\n" % |
|
1351 | self.ui.status("%d files, %d changesets, %d total revisions\n" % | |
1348 | (files, changesets, revisions)) |
|
1352 | (files, changesets, revisions)) | |
1349 |
|
1353 | |||
1350 | if errors: |
|
1354 | if errors: | |
1351 | self.ui.warn("%d integrity errors encountered!\n" % errors) |
|
1355 | self.ui.warn("%d integrity errors encountered!\n" % errors) | |
1352 | return 1 |
|
1356 | return 1 | |
1353 |
|
1357 | |||
1354 | class remoterepository: |
|
1358 | class remoterepository: | |
1355 | def __init__(self, ui, path): |
|
1359 | def __init__(self, ui, path): | |
1356 | self.url = path |
|
1360 | self.url = path | |
1357 | self.ui = ui |
|
1361 | self.ui = ui | |
1358 | no_list = [ "localhost", "127.0.0.1" ] |
|
1362 | no_list = [ "localhost", "127.0.0.1" ] | |
1359 | host = ui.config("http_proxy", "host") |
|
1363 | host = ui.config("http_proxy", "host") | |
1360 | user = ui.config("http_proxy", "user") |
|
1364 | user = ui.config("http_proxy", "user") | |
1361 | passwd = ui.config("http_proxy", "passwd") |
|
1365 | passwd = ui.config("http_proxy", "passwd") | |
1362 | no = ui.config("http_proxy", "no") |
|
1366 | no = ui.config("http_proxy", "no") | |
1363 | if no: |
|
1367 | if no: | |
1364 | no_list = no_list + no.split(",") |
|
1368 | no_list = no_list + no.split(",") | |
1365 |
|
1369 | |||
1366 | no_proxy = 0 |
|
1370 | no_proxy = 0 | |
1367 | for h in no_list: |
|
1371 | for h in no_list: | |
1368 | if (path.startswith("http://" + h + "/") or |
|
1372 | if (path.startswith("http://" + h + "/") or | |
1369 | path.startswith("http://" + h + ":") or |
|
1373 | path.startswith("http://" + h + ":") or | |
1370 | path == "http://" + h): |
|
1374 | path == "http://" + h): | |
1371 | no_proxy = 1 |
|
1375 | no_proxy = 1 | |
1372 |
|
1376 | |||
1373 | # Note: urllib2 takes proxy values from the environment and those will |
|
1377 | # Note: urllib2 takes proxy values from the environment and those will | |
1374 | # take precedence |
|
1378 | # take precedence | |
1375 |
|
1379 | |||
1376 | proxy_handler = urllib2.BaseHandler() |
|
1380 | proxy_handler = urllib2.BaseHandler() | |
1377 | if host and not no_proxy: |
|
1381 | if host and not no_proxy: | |
1378 | proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) |
|
1382 | proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) | |
1379 |
|
1383 | |||
1380 | authinfo = None |
|
1384 | authinfo = None | |
1381 | if user and passwd: |
|
1385 | if user and passwd: | |
1382 | passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() |
|
1386 | passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | |
1383 | passmgr.add_password(None, host, user, passwd) |
|
1387 | passmgr.add_password(None, host, user, passwd) | |
1384 | authinfo = urllib2.ProxyBasicAuthHandler(passmgr) |
|
1388 | authinfo = urllib2.ProxyBasicAuthHandler(passmgr) | |
1385 |
|
1389 | |||
1386 | opener = urllib2.build_opener(proxy_handler, authinfo) |
|
1390 | opener = urllib2.build_opener(proxy_handler, authinfo) | |
1387 | urllib2.install_opener(opener) |
|
1391 | urllib2.install_opener(opener) | |
1388 |
|
1392 | |||
1389 | def do_cmd(self, cmd, **args): |
|
1393 | def do_cmd(self, cmd, **args): | |
1390 | self.ui.debug("sending %s command\n" % cmd) |
|
1394 | self.ui.debug("sending %s command\n" % cmd) | |
1391 | q = {"cmd": cmd} |
|
1395 | q = {"cmd": cmd} | |
1392 | q.update(args) |
|
1396 | q.update(args) | |
1393 | qs = urllib.urlencode(q) |
|
1397 | qs = urllib.urlencode(q) | |
1394 | cu = "%s?%s" % (self.url, qs) |
|
1398 | cu = "%s?%s" % (self.url, qs) | |
1395 | return urllib2.urlopen(cu) |
|
1399 | return urllib2.urlopen(cu) | |
1396 |
|
1400 | |||
1397 | def heads(self): |
|
1401 | def heads(self): | |
1398 | d = self.do_cmd("heads").read() |
|
1402 | d = self.do_cmd("heads").read() | |
1399 | try: |
|
1403 | try: | |
1400 | return map(bin, d[:-1].split(" ")) |
|
1404 | return map(bin, d[:-1].split(" ")) | |
1401 | except: |
|
1405 | except: | |
1402 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1406 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | |
1403 | raise |
|
1407 | raise | |
1404 |
|
1408 | |||
1405 | def branches(self, nodes): |
|
1409 | def branches(self, nodes): | |
1406 | n = " ".join(map(hex, nodes)) |
|
1410 | n = " ".join(map(hex, nodes)) | |
1407 | d = self.do_cmd("branches", nodes=n).read() |
|
1411 | d = self.do_cmd("branches", nodes=n).read() | |
1408 | try: |
|
1412 | try: | |
1409 | br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] |
|
1413 | br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] | |
1410 | return br |
|
1414 | return br | |
1411 | except: |
|
1415 | except: | |
1412 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1416 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | |
1413 | raise |
|
1417 | raise | |
1414 |
|
1418 | |||
1415 | def between(self, pairs): |
|
1419 | def between(self, pairs): | |
1416 | n = "\n".join(["-".join(map(hex, p)) for p in pairs]) |
|
1420 | n = "\n".join(["-".join(map(hex, p)) for p in pairs]) | |
1417 | d = self.do_cmd("between", pairs=n).read() |
|
1421 | d = self.do_cmd("between", pairs=n).read() | |
1418 | try: |
|
1422 | try: | |
1419 | p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] |
|
1423 | p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] | |
1420 | return p |
|
1424 | return p | |
1421 | except: |
|
1425 | except: | |
1422 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1426 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | |
1423 | raise |
|
1427 | raise | |
1424 |
|
1428 | |||
1425 | def changegroup(self, nodes): |
|
1429 | def changegroup(self, nodes): | |
1426 | n = " ".join(map(hex, nodes)) |
|
1430 | n = " ".join(map(hex, nodes)) | |
1427 | zd = zlib.decompressobj() |
|
1431 | zd = zlib.decompressobj() | |
1428 | f = self.do_cmd("changegroup", roots=n) |
|
1432 | f = self.do_cmd("changegroup", roots=n) | |
1429 | bytes = 0 |
|
1433 | bytes = 0 | |
1430 | while 1: |
|
1434 | while 1: | |
1431 | d = f.read(4096) |
|
1435 | d = f.read(4096) | |
1432 | bytes += len(d) |
|
1436 | bytes += len(d) | |
1433 | if not d: |
|
1437 | if not d: | |
1434 | yield zd.flush() |
|
1438 | yield zd.flush() | |
1435 | break |
|
1439 | break | |
1436 | yield zd.decompress(d) |
|
1440 | yield zd.decompress(d) | |
1437 | self.ui.note("%d bytes of data transfered\n" % bytes) |
|
1441 | self.ui.note("%d bytes of data transfered\n" % bytes) | |
1438 |
|
1442 | |||
1439 | def repository(ui, path=None, create=0): |
|
1443 | def repository(ui, path=None, create=0): | |
1440 | if path and path[:7] == "http://": |
|
1444 | if path and path[:7] == "http://": | |
1441 | return remoterepository(ui, path) |
|
1445 | return remoterepository(ui, path) | |
1442 | if path and path[:5] == "hg://": |
|
1446 | if path and path[:5] == "hg://": | |
1443 | return remoterepository(ui, path.replace("hg://", "http://")) |
|
1447 | return remoterepository(ui, path.replace("hg://", "http://")) | |
1444 | if path and path[:11] == "old-http://": |
|
1448 | if path and path[:11] == "old-http://": | |
1445 | return localrepository(ui, path.replace("old-http://", "http://")) |
|
1449 | return localrepository(ui, path.replace("old-http://", "http://")) | |
1446 | else: |
|
1450 | else: | |
1447 | return localrepository(ui, path, create) |
|
1451 | return localrepository(ui, path, create) | |
1448 |
|
1452 |
General Comments 0
You need to be logged in to leave comments.
Login now