Show More
@@ -0,0 +1,35 b'' | |||||
|
1 | #!/bin/sh +ex | |||
|
2 | ||||
|
3 | mkdir test1 | |||
|
4 | cd test1 | |||
|
5 | ||||
|
6 | hg init | |||
|
7 | touch a b | |||
|
8 | hg add a b | |||
|
9 | hg ci -t "added a b" -u test -d "0 0" | |||
|
10 | ||||
|
11 | cd .. | |||
|
12 | mkdir test2 | |||
|
13 | cd test2 | |||
|
14 | ||||
|
15 | hg init | |||
|
16 | hg merge ../test1 | |||
|
17 | hg co | |||
|
18 | chmod +x a | |||
|
19 | hg ci -t "chmod +x a" -u test -d "0 0" | |||
|
20 | ||||
|
21 | cd ../test1 | |||
|
22 | echo 123 >>a | |||
|
23 | hg ci -t "a updated" -u test -d "0 0" | |||
|
24 | ||||
|
25 | ls -l ../test[12]/a | |||
|
26 | ||||
|
27 | hg merge ../test2 | |||
|
28 | hg heads | |||
|
29 | hg history | |||
|
30 | ||||
|
31 | hg -dv co -m | |||
|
32 | ||||
|
33 | ls -l ../test[12]/a > foo | |||
|
34 | cut -b 0-10 < foo | |||
|
35 |
@@ -0,0 +1,53 b'' | |||||
|
1 | pulling from ../test1 | |||
|
2 | requesting all changes | |||
|
3 | adding changesets | |||
|
4 | adding manifests | |||
|
5 | adding file revisions | |||
|
6 | modified 2 files, added 1 changesets and 2 new revisions | |||
|
7 | (run 'hg update' to get a working copy) | |||
|
8 | -rw-r--r-- 1 oxymoron oxymoron 4 Jun 22 03:04 ../test1/a | |||
|
9 | -rwxr-xr-x 1 oxymoron oxymoron 0 Jun 22 03:04 ../test2/a | |||
|
10 | pulling from ../test2 | |||
|
11 | searching for changes | |||
|
12 | adding changesets | |||
|
13 | adding manifests | |||
|
14 | adding file revisions | |||
|
15 | modified 1 files, added 1 changesets and 1 new revisions | |||
|
16 | (run 'hg update' to get a working copy) | |||
|
17 | changeset: 2:3ef54330565526bebf37a0d9bf540c283fd133a1 | |||
|
18 | tag: tip | |||
|
19 | parent: 0:22a449e20da501ca558394c083ca470e9c81b9f7 | |||
|
20 | user: test | |||
|
21 | date: Thu Jan 1 00:00:00 1970 | |||
|
22 | summary: chmod +x a | |||
|
23 | ||||
|
24 | changeset: 1:c6ecefc45368ed556d965f1c1086c6561a8b2ac5 | |||
|
25 | user: test | |||
|
26 | date: Thu Jan 1 00:00:00 1970 | |||
|
27 | summary: a updated | |||
|
28 | ||||
|
29 | changeset: 2:3ef54330565526bebf37a0d9bf540c283fd133a1 | |||
|
30 | tag: tip | |||
|
31 | parent: 0:22a449e20da501ca558394c083ca470e9c81b9f7 | |||
|
32 | user: test | |||
|
33 | date: Thu Jan 1 00:00:00 1970 | |||
|
34 | summary: chmod +x a | |||
|
35 | ||||
|
36 | changeset: 1:c6ecefc45368ed556d965f1c1086c6561a8b2ac5 | |||
|
37 | user: test | |||
|
38 | date: Thu Jan 1 00:00:00 1970 | |||
|
39 | summary: a updated | |||
|
40 | ||||
|
41 | changeset: 0:22a449e20da501ca558394c083ca470e9c81b9f7 | |||
|
42 | user: test | |||
|
43 | date: Thu Jan 1 00:00:00 1970 | |||
|
44 | summary: added a b | |||
|
45 | ||||
|
46 | resolving manifests | |||
|
47 | ancestor f328b97f7c11 local e7f06daf1cdb remote 629f0b785e0e | |||
|
48 | a versions differ, resolve | |||
|
49 | merging a | |||
|
50 | resolving a | |||
|
51 | file a: other 37c42bd6cc03 ancestor b80de5d13875 | |||
|
52 | -rwxr-xr-x | |||
|
53 | -rwxr-xr-x |
@@ -1,1449 +1,1449 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(m |
|
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[f] = (m1.get(f, nullid), m2[f]) |
|
1065 | merge[f] = (m1.get(f, nullid), m2[f]) | |
1066 | # merge executable bits |
|
1066 | # merge executable bits | |
1067 | # "if we changed or they changed, change in merge" |
|
1067 | # "if we changed or they changed, change in merge" | |
1068 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] |
|
1068 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] | |
1069 | mode = ((a^b) | (a^c)) ^ a |
|
1069 | mode = ((a^b) | (a^c)) ^ a | |
1070 | merge[f] = (m1.get(f, nullid), m2[f], mode) |
|
1070 | merge[f] = (m1.get(f, nullid), m2[f], mode) | |
1071 | s = 1 |
|
1071 | s = 1 | |
1072 | # are we clobbering? |
|
1072 | # are we clobbering? | |
1073 | # is remote's version newer? |
|
1073 | # is remote's version newer? | |
1074 | # or are we going back in time? |
|
1074 | # or are we going back in time? | |
1075 | elif force or m2[f] != a or (p2 == pa and mw[f] == m1[f]): |
|
1075 | elif force or m2[f] != a or (p2 == pa and mw[f] == m1[f]): | |
1076 | self.ui.debug(" remote %s is newer, get\n" % f) |
|
1076 | self.ui.debug(" remote %s is newer, get\n" % f) | |
1077 | get[f] = m2[f] |
|
1077 | get[f] = m2[f] | |
1078 | s = 1 |
|
1078 | s = 1 | |
1079 | else: |
|
1079 | else: | |
1080 | mark[f] = 1 |
|
1080 | mark[f] = 1 | |
1081 |
|
1081 | |||
1082 | if not s and mfw[f] != mf2[f]: |
|
1082 | if not s and mfw[f] != mf2[f]: | |
1083 | if force: |
|
1083 | if force: | |
1084 | self.ui.debug(" updating permissions for %s\n" % f) |
|
1084 | self.ui.debug(" updating permissions for %s\n" % f) | |
1085 | set_exec(self.wjoin(f), mf2[f]) |
|
1085 | set_exec(self.wjoin(f), mf2[f]) | |
1086 | else: |
|
1086 | else: | |
1087 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] |
|
1087 | a, b, c = mfa.get(f, 0), mfw[f], mf2[f] | |
1088 | mode = ((a^b) | (a^c)) ^ a |
|
1088 | mode = ((a^b) | (a^c)) ^ a | |
1089 | if mode != b: |
|
1089 | if mode != b: | |
1090 | self.ui.debug(" updating permissions for %s\n" % f) |
|
1090 | self.ui.debug(" updating permissions for %s\n" % f) | |
1091 | set_exec(self.wjoin(f), mode) |
|
1091 | set_exec(self.wjoin(f), mode) | |
1092 | mark[f] = 1 |
|
1092 | mark[f] = 1 | |
1093 | del m2[f] |
|
1093 | del m2[f] | |
1094 | elif f in ma: |
|
1094 | elif f in ma: | |
1095 | if not force and n != ma[f]: |
|
1095 | if not force and n != ma[f]: | |
1096 | r = self.ui.prompt( |
|
1096 | r = self.ui.prompt( | |
1097 | (" local changed %s which remote deleted\n" % f) + |
|
1097 | (" local changed %s which remote deleted\n" % f) + | |
1098 | "(k)eep or (d)elete?", "[kd]", "k") |
|
1098 | "(k)eep or (d)elete?", "[kd]", "k") | |
1099 | if r == "d": |
|
1099 | if r == "d": | |
1100 | remove.append(f) |
|
1100 | remove.append(f) | |
1101 | else: |
|
1101 | else: | |
1102 | self.ui.debug("other deleted %s\n" % f) |
|
1102 | self.ui.debug("other deleted %s\n" % f) | |
1103 | remove.append(f) # other deleted it |
|
1103 | remove.append(f) # other deleted it | |
1104 | else: |
|
1104 | else: | |
1105 | if n == m1.get(f, nullid): # same as parent |
|
1105 | if n == m1.get(f, nullid): # same as parent | |
1106 | if p2 == pa: # going backwards? |
|
1106 | if p2 == pa: # going backwards? | |
1107 | self.ui.debug("remote deleted %s\n" % f) |
|
1107 | self.ui.debug("remote deleted %s\n" % f) | |
1108 | remove.append(f) |
|
1108 | remove.append(f) | |
1109 | else: |
|
1109 | else: | |
1110 | self.ui.debug("local created %s, keeping\n" % f) |
|
1110 | self.ui.debug("local created %s, keeping\n" % f) | |
1111 | else: |
|
1111 | else: | |
1112 | self.ui.debug("working dir created %s, keeping\n" % f) |
|
1112 | self.ui.debug("working dir created %s, keeping\n" % f) | |
1113 |
|
1113 | |||
1114 | for f, n in m2.iteritems(): |
|
1114 | for f, n in m2.iteritems(): | |
1115 | if f[0] == "/": continue |
|
1115 | if f[0] == "/": continue | |
1116 | if not force and f in ma and n != ma[f]: |
|
1116 | if not force and f in ma and n != ma[f]: | |
1117 | r = self.ui.prompt( |
|
1117 | r = self.ui.prompt( | |
1118 | ("remote changed %s which local deleted\n" % f) + |
|
1118 | ("remote changed %s which local deleted\n" % f) + | |
1119 | "(k)eep or (d)elete?", "[kd]", "k") |
|
1119 | "(k)eep or (d)elete?", "[kd]", "k") | |
1120 | if r == "d": remove.append(f) |
|
1120 | if r == "d": remove.append(f) | |
1121 | else: |
|
1121 | else: | |
1122 | self.ui.debug("remote created %s\n" % f) |
|
1122 | self.ui.debug("remote created %s\n" % f) | |
1123 | get[f] = n |
|
1123 | get[f] = n | |
1124 |
|
1124 | |||
1125 | del mw, m1, m2, ma |
|
1125 | del mw, m1, m2, ma | |
1126 |
|
1126 | |||
1127 | if force: |
|
1127 | if force: | |
1128 | for f in merge: |
|
1128 | for f in merge: | |
1129 | get[f] = merge[f][1] |
|
1129 | get[f] = merge[f][1] | |
1130 | merge = {} |
|
1130 | merge = {} | |
1131 |
|
1131 | |||
1132 | if linear_path: |
|
1132 | if linear_path: | |
1133 | # we don't need to do any magic, just jump to the new rev |
|
1133 | # we don't need to do any magic, just jump to the new rev | |
1134 | mode = 'n' |
|
1134 | mode = 'n' | |
1135 | p1, p2 = p2, nullid |
|
1135 | p1, p2 = p2, nullid | |
1136 | else: |
|
1136 | else: | |
1137 | if not allow: |
|
1137 | if not allow: | |
1138 | self.ui.status("this update spans a branch" + |
|
1138 | self.ui.status("this update spans a branch" + | |
1139 | " affecting the following files:\n") |
|
1139 | " affecting the following files:\n") | |
1140 | fl = merge.keys() + get.keys() |
|
1140 | fl = merge.keys() + get.keys() | |
1141 | fl.sort() |
|
1141 | fl.sort() | |
1142 | for f in fl: |
|
1142 | for f in fl: | |
1143 | cf = "" |
|
1143 | cf = "" | |
1144 | if f in merge: cf = " (resolve)" |
|
1144 | if f in merge: cf = " (resolve)" | |
1145 | self.ui.status(" %s%s\n" % (f, cf)) |
|
1145 | self.ui.status(" %s%s\n" % (f, cf)) | |
1146 | self.ui.warn("aborting update spanning branches!\n") |
|
1146 | self.ui.warn("aborting update spanning branches!\n") | |
1147 | self.ui.status("(use update -m to perform a branch merge)\n") |
|
1147 | self.ui.status("(use update -m to perform a branch merge)\n") | |
1148 | return 1 |
|
1148 | return 1 | |
1149 | # we have to remember what files we needed to get/change |
|
1149 | # we have to remember what files we needed to get/change | |
1150 | # because any file that's different from either one of its |
|
1150 | # because any file that's different from either one of its | |
1151 | # parents must be in the changeset |
|
1151 | # parents must be in the changeset | |
1152 | mode = 'm' |
|
1152 | mode = 'm' | |
1153 | self.dirstate.update(mark.keys(), "m") |
|
1153 | self.dirstate.update(mark.keys(), "m") | |
1154 |
|
1154 | |||
1155 | self.dirstate.setparents(p1, p2) |
|
1155 | self.dirstate.setparents(p1, p2) | |
1156 |
|
1156 | |||
1157 | # get the files we don't need to change |
|
1157 | # get the files we don't need to change | |
1158 | files = get.keys() |
|
1158 | files = get.keys() | |
1159 | files.sort() |
|
1159 | files.sort() | |
1160 | for f in files: |
|
1160 | for f in files: | |
1161 | if f[0] == "/": continue |
|
1161 | if f[0] == "/": continue | |
1162 | self.ui.note("getting %s\n" % f) |
|
1162 | self.ui.note("getting %s\n" % f) | |
1163 | t = self.file(f).read(get[f]) |
|
1163 | t = self.file(f).read(get[f]) | |
1164 | try: |
|
1164 | try: | |
1165 | self.wfile(f, "w").write(t) |
|
1165 | self.wfile(f, "w").write(t) | |
1166 | except IOError: |
|
1166 | except IOError: | |
1167 | os.makedirs(os.path.dirname(self.wjoin(f))) |
|
1167 | os.makedirs(os.path.dirname(self.wjoin(f))) | |
1168 | self.wfile(f, "w").write(t) |
|
1168 | self.wfile(f, "w").write(t) | |
1169 | set_exec(self.wjoin(f), mf2[f]) |
|
1169 | set_exec(self.wjoin(f), mf2[f]) | |
1170 | self.dirstate.update([f], mode) |
|
1170 | self.dirstate.update([f], mode) | |
1171 |
|
1171 | |||
1172 | # merge the tricky bits |
|
1172 | # merge the tricky bits | |
1173 | files = merge.keys() |
|
1173 | files = merge.keys() | |
1174 | files.sort() |
|
1174 | files.sort() | |
1175 | for f in files: |
|
1175 | for f in files: | |
1176 | self.ui.status("merging %s\n" % f) |
|
1176 | self.ui.status("merging %s\n" % f) | |
1177 | m, o, flag = merge[f] |
|
1177 | m, o, flag = merge[f] | |
1178 | self.merge3(f, m, o) |
|
1178 | self.merge3(f, m, o) | |
1179 | set_exec(self.wjoin(f), flag) |
|
1179 | set_exec(self.wjoin(f), flag) | |
1180 | self.dirstate.update([f], 'm') |
|
1180 | self.dirstate.update([f], 'm') | |
1181 |
|
1181 | |||
1182 | for f in remove: |
|
1182 | for f in remove: | |
1183 | self.ui.note("removing %s\n" % f) |
|
1183 | self.ui.note("removing %s\n" % f) | |
1184 | os.unlink(f) |
|
1184 | os.unlink(f) | |
1185 | if mode == 'n': |
|
1185 | if mode == 'n': | |
1186 | self.dirstate.forget(remove) |
|
1186 | self.dirstate.forget(remove) | |
1187 | else: |
|
1187 | else: | |
1188 | self.dirstate.update(remove, 'r') |
|
1188 | self.dirstate.update(remove, 'r') | |
1189 |
|
1189 | |||
1190 | def merge3(self, fn, my, other): |
|
1190 | def merge3(self, fn, my, other): | |
1191 | """perform a 3-way merge in the working directory""" |
|
1191 | """perform a 3-way merge in the working directory""" | |
1192 |
|
1192 | |||
1193 | def temp(prefix, node): |
|
1193 | def temp(prefix, node): | |
1194 | pre = "%s~%s." % (os.path.basename(fn), prefix) |
|
1194 | pre = "%s~%s." % (os.path.basename(fn), prefix) | |
1195 | (fd, name) = tempfile.mkstemp("", pre) |
|
1195 | (fd, name) = tempfile.mkstemp("", pre) | |
1196 | f = os.fdopen(fd, "w") |
|
1196 | f = os.fdopen(fd, "w") | |
1197 | f.write(fl.revision(node)) |
|
1197 | f.write(fl.revision(node)) | |
1198 | f.close() |
|
1198 | f.close() | |
1199 | return name |
|
1199 | return name | |
1200 |
|
1200 | |||
1201 | fl = self.file(fn) |
|
1201 | fl = self.file(fn) | |
1202 | base = fl.ancestor(my, other) |
|
1202 | base = fl.ancestor(my, other) | |
1203 | a = self.wjoin(fn) |
|
1203 | a = self.wjoin(fn) | |
1204 | b = temp("base", base) |
|
1204 | b = temp("base", base) | |
1205 | c = temp("other", other) |
|
1205 | c = temp("other", other) | |
1206 |
|
1206 | |||
1207 | self.ui.note("resolving %s\n" % fn) |
|
1207 | self.ui.note("resolving %s\n" % fn) | |
1208 | self.ui.debug("file %s: other %s ancestor %s\n" % |
|
1208 | self.ui.debug("file %s: other %s ancestor %s\n" % | |
1209 | (fn, short(other), short(base))) |
|
1209 | (fn, short(other), short(base))) | |
1210 |
|
1210 | |||
1211 | cmd = os.environ.get("HGMERGE", "hgmerge") |
|
1211 | cmd = os.environ.get("HGMERGE", "hgmerge") | |
1212 | r = os.system("%s %s %s %s" % (cmd, a, b, c)) |
|
1212 | r = os.system("%s %s %s %s" % (cmd, a, b, c)) | |
1213 | if r: |
|
1213 | if r: | |
1214 | self.ui.warn("merging %s failed!\n" % fn) |
|
1214 | self.ui.warn("merging %s failed!\n" % fn) | |
1215 |
|
1215 | |||
1216 | os.unlink(b) |
|
1216 | os.unlink(b) | |
1217 | os.unlink(c) |
|
1217 | os.unlink(c) | |
1218 |
|
1218 | |||
1219 | def verify(self): |
|
1219 | def verify(self): | |
1220 | filelinkrevs = {} |
|
1220 | filelinkrevs = {} | |
1221 | filenodes = {} |
|
1221 | filenodes = {} | |
1222 | changesets = revisions = files = 0 |
|
1222 | changesets = revisions = files = 0 | |
1223 | errors = 0 |
|
1223 | errors = 0 | |
1224 |
|
1224 | |||
1225 | seen = {} |
|
1225 | seen = {} | |
1226 | self.ui.status("checking changesets\n") |
|
1226 | self.ui.status("checking changesets\n") | |
1227 | for i in range(self.changelog.count()): |
|
1227 | for i in range(self.changelog.count()): | |
1228 | changesets += 1 |
|
1228 | changesets += 1 | |
1229 | n = self.changelog.node(i) |
|
1229 | n = self.changelog.node(i) | |
1230 | if n in seen: |
|
1230 | if n in seen: | |
1231 | self.ui.warn("duplicate changeset at revision %d\n" % i) |
|
1231 | self.ui.warn("duplicate changeset at revision %d\n" % i) | |
1232 | errors += 1 |
|
1232 | errors += 1 | |
1233 | seen[n] = 1 |
|
1233 | seen[n] = 1 | |
1234 |
|
1234 | |||
1235 | for p in self.changelog.parents(n): |
|
1235 | for p in self.changelog.parents(n): | |
1236 | if p not in self.changelog.nodemap: |
|
1236 | if p not in self.changelog.nodemap: | |
1237 | self.ui.warn("changeset %s has unknown parent %s\n" % |
|
1237 | self.ui.warn("changeset %s has unknown parent %s\n" % | |
1238 | (short(n), short(p))) |
|
1238 | (short(n), short(p))) | |
1239 | errors += 1 |
|
1239 | errors += 1 | |
1240 | try: |
|
1240 | try: | |
1241 | changes = self.changelog.read(n) |
|
1241 | changes = self.changelog.read(n) | |
1242 | except Exception, inst: |
|
1242 | except Exception, inst: | |
1243 | self.ui.warn("unpacking changeset %s: %s\n" % (short(n), inst)) |
|
1243 | self.ui.warn("unpacking changeset %s: %s\n" % (short(n), inst)) | |
1244 | errors += 1 |
|
1244 | errors += 1 | |
1245 |
|
1245 | |||
1246 | for f in changes[3]: |
|
1246 | for f in changes[3]: | |
1247 | filelinkrevs.setdefault(f, []).append(i) |
|
1247 | filelinkrevs.setdefault(f, []).append(i) | |
1248 |
|
1248 | |||
1249 | seen = {} |
|
1249 | seen = {} | |
1250 | self.ui.status("checking manifests\n") |
|
1250 | self.ui.status("checking manifests\n") | |
1251 | for i in range(self.manifest.count()): |
|
1251 | for i in range(self.manifest.count()): | |
1252 | n = self.manifest.node(i) |
|
1252 | n = self.manifest.node(i) | |
1253 | if n in seen: |
|
1253 | if n in seen: | |
1254 | self.ui.warn("duplicate manifest at revision %d\n" % i) |
|
1254 | self.ui.warn("duplicate manifest at revision %d\n" % i) | |
1255 | errors += 1 |
|
1255 | errors += 1 | |
1256 | seen[n] = 1 |
|
1256 | seen[n] = 1 | |
1257 |
|
1257 | |||
1258 | for p in self.manifest.parents(n): |
|
1258 | for p in self.manifest.parents(n): | |
1259 | if p not in self.manifest.nodemap: |
|
1259 | if p not in self.manifest.nodemap: | |
1260 | self.ui.warn("manifest %s has unknown parent %s\n" % |
|
1260 | self.ui.warn("manifest %s has unknown parent %s\n" % | |
1261 | (short(n), short(p))) |
|
1261 | (short(n), short(p))) | |
1262 | errors += 1 |
|
1262 | errors += 1 | |
1263 |
|
1263 | |||
1264 | try: |
|
1264 | try: | |
1265 | delta = mdiff.patchtext(self.manifest.delta(n)) |
|
1265 | delta = mdiff.patchtext(self.manifest.delta(n)) | |
1266 | except KeyboardInterrupt: |
|
1266 | except KeyboardInterrupt: | |
1267 | print "aborted" |
|
1267 | print "aborted" | |
1268 | sys.exit(0) |
|
1268 | sys.exit(0) | |
1269 | except Exception, inst: |
|
1269 | except Exception, inst: | |
1270 | self.ui.warn("unpacking manifest %s: %s\n" |
|
1270 | self.ui.warn("unpacking manifest %s: %s\n" | |
1271 | % (short(n), inst)) |
|
1271 | % (short(n), inst)) | |
1272 | errors += 1 |
|
1272 | errors += 1 | |
1273 |
|
1273 | |||
1274 | ff = [ l.split('\0') for l in delta.splitlines() ] |
|
1274 | ff = [ l.split('\0') for l in delta.splitlines() ] | |
1275 | for f, fn in ff: |
|
1275 | for f, fn in ff: | |
1276 | filenodes.setdefault(f, {})[bin(fn[:40])] = 1 |
|
1276 | filenodes.setdefault(f, {})[bin(fn[:40])] = 1 | |
1277 |
|
1277 | |||
1278 | self.ui.status("crosschecking files in changesets and manifests\n") |
|
1278 | self.ui.status("crosschecking files in changesets and manifests\n") | |
1279 | for f in filenodes: |
|
1279 | for f in filenodes: | |
1280 | if f not in filelinkrevs: |
|
1280 | if f not in filelinkrevs: | |
1281 | self.ui.warn("file %s in manifest but not in changesets\n" % f) |
|
1281 | self.ui.warn("file %s in manifest but not in changesets\n" % f) | |
1282 | errors += 1 |
|
1282 | errors += 1 | |
1283 |
|
1283 | |||
1284 | for f in filelinkrevs: |
|
1284 | for f in filelinkrevs: | |
1285 | if f not in filenodes: |
|
1285 | if f not in filenodes: | |
1286 | self.ui.warn("file %s in changeset but not in manifest\n" % f) |
|
1286 | self.ui.warn("file %s in changeset but not in manifest\n" % f) | |
1287 | errors += 1 |
|
1287 | errors += 1 | |
1288 |
|
1288 | |||
1289 | self.ui.status("checking files\n") |
|
1289 | self.ui.status("checking files\n") | |
1290 | ff = filenodes.keys() |
|
1290 | ff = filenodes.keys() | |
1291 | ff.sort() |
|
1291 | ff.sort() | |
1292 | for f in ff: |
|
1292 | for f in ff: | |
1293 | if f == "/dev/null": continue |
|
1293 | if f == "/dev/null": continue | |
1294 | files += 1 |
|
1294 | files += 1 | |
1295 | fl = self.file(f) |
|
1295 | fl = self.file(f) | |
1296 | nodes = { nullid: 1 } |
|
1296 | nodes = { nullid: 1 } | |
1297 | seen = {} |
|
1297 | seen = {} | |
1298 | for i in range(fl.count()): |
|
1298 | for i in range(fl.count()): | |
1299 | revisions += 1 |
|
1299 | revisions += 1 | |
1300 | n = fl.node(i) |
|
1300 | n = fl.node(i) | |
1301 |
|
1301 | |||
1302 | if n in seen: |
|
1302 | if n in seen: | |
1303 | self.ui.warn("%s: duplicate revision %d\n" % (f, i)) |
|
1303 | self.ui.warn("%s: duplicate revision %d\n" % (f, i)) | |
1304 | errors += 1 |
|
1304 | errors += 1 | |
1305 |
|
1305 | |||
1306 | if n not in filenodes[f]: |
|
1306 | if n not in filenodes[f]: | |
1307 | self.ui.warn("%s: %d:%s not in manifests\n" |
|
1307 | self.ui.warn("%s: %d:%s not in manifests\n" | |
1308 | % (f, i, short(n))) |
|
1308 | % (f, i, short(n))) | |
1309 | print len(filenodes[f].keys()), fl.count(), f |
|
1309 | print len(filenodes[f].keys()), fl.count(), f | |
1310 | errors += 1 |
|
1310 | errors += 1 | |
1311 | else: |
|
1311 | else: | |
1312 | del filenodes[f][n] |
|
1312 | del filenodes[f][n] | |
1313 |
|
1313 | |||
1314 | flr = fl.linkrev(n) |
|
1314 | flr = fl.linkrev(n) | |
1315 | if flr not in filelinkrevs[f]: |
|
1315 | if flr not in filelinkrevs[f]: | |
1316 | self.ui.warn("%s:%s points to unexpected changeset %d\n" |
|
1316 | self.ui.warn("%s:%s points to unexpected changeset %d\n" | |
1317 | % (f, short(n), fl.linkrev(n))) |
|
1317 | % (f, short(n), fl.linkrev(n))) | |
1318 | errors += 1 |
|
1318 | errors += 1 | |
1319 | else: |
|
1319 | else: | |
1320 | filelinkrevs[f].remove(flr) |
|
1320 | filelinkrevs[f].remove(flr) | |
1321 |
|
1321 | |||
1322 | # verify contents |
|
1322 | # verify contents | |
1323 | try: |
|
1323 | try: | |
1324 | t = fl.read(n) |
|
1324 | t = fl.read(n) | |
1325 | except Exception, inst: |
|
1325 | except Exception, inst: | |
1326 | self.ui.warn("unpacking file %s %s: %s\n" |
|
1326 | self.ui.warn("unpacking file %s %s: %s\n" | |
1327 | % (f, short(n), inst)) |
|
1327 | % (f, short(n), inst)) | |
1328 | errors += 1 |
|
1328 | errors += 1 | |
1329 |
|
1329 | |||
1330 | # verify parents |
|
1330 | # verify parents | |
1331 | (p1, p2) = fl.parents(n) |
|
1331 | (p1, p2) = fl.parents(n) | |
1332 | if p1 not in nodes: |
|
1332 | if p1 not in nodes: | |
1333 | self.ui.warn("file %s:%s unknown parent 1 %s" % |
|
1333 | self.ui.warn("file %s:%s unknown parent 1 %s" % | |
1334 | (f, short(n), short(p1))) |
|
1334 | (f, short(n), short(p1))) | |
1335 | errors += 1 |
|
1335 | errors += 1 | |
1336 | if p2 not in nodes: |
|
1336 | if p2 not in nodes: | |
1337 | self.ui.warn("file %s:%s unknown parent 2 %s" % |
|
1337 | self.ui.warn("file %s:%s unknown parent 2 %s" % | |
1338 | (f, short(n), short(p1))) |
|
1338 | (f, short(n), short(p1))) | |
1339 | errors += 1 |
|
1339 | errors += 1 | |
1340 | nodes[n] = 1 |
|
1340 | nodes[n] = 1 | |
1341 |
|
1341 | |||
1342 | # cross-check |
|
1342 | # cross-check | |
1343 | for node in filenodes[f]: |
|
1343 | for node in filenodes[f]: | |
1344 | self.ui.warn("node %s in manifests not in %s\n" |
|
1344 | self.ui.warn("node %s in manifests not in %s\n" | |
1345 | % (hex(n), f)) |
|
1345 | % (hex(n), f)) | |
1346 | errors += 1 |
|
1346 | errors += 1 | |
1347 |
|
1347 | |||
1348 | self.ui.status("%d files, %d changesets, %d total revisions\n" % |
|
1348 | self.ui.status("%d files, %d changesets, %d total revisions\n" % | |
1349 | (files, changesets, revisions)) |
|
1349 | (files, changesets, revisions)) | |
1350 |
|
1350 | |||
1351 | if errors: |
|
1351 | if errors: | |
1352 | self.ui.warn("%d integrity errors encountered!\n" % errors) |
|
1352 | self.ui.warn("%d integrity errors encountered!\n" % errors) | |
1353 | return 1 |
|
1353 | return 1 | |
1354 |
|
1354 | |||
1355 | class remoterepository: |
|
1355 | class remoterepository: | |
1356 | def __init__(self, ui, path): |
|
1356 | def __init__(self, ui, path): | |
1357 | self.url = path |
|
1357 | self.url = path | |
1358 | self.ui = ui |
|
1358 | self.ui = ui | |
1359 | no_list = [ "localhost", "127.0.0.1" ] |
|
1359 | no_list = [ "localhost", "127.0.0.1" ] | |
1360 | host = ui.config("http_proxy", "host") |
|
1360 | host = ui.config("http_proxy", "host") | |
1361 | user = ui.config("http_proxy", "user") |
|
1361 | user = ui.config("http_proxy", "user") | |
1362 | passwd = ui.config("http_proxy", "passwd") |
|
1362 | passwd = ui.config("http_proxy", "passwd") | |
1363 | no = ui.config("http_proxy", "no") |
|
1363 | no = ui.config("http_proxy", "no") | |
1364 | if no: |
|
1364 | if no: | |
1365 | no_list = no_list + no.split(",") |
|
1365 | no_list = no_list + no.split(",") | |
1366 |
|
1366 | |||
1367 | no_proxy = 0 |
|
1367 | no_proxy = 0 | |
1368 | for h in no_list: |
|
1368 | for h in no_list: | |
1369 | if (path.startswith("http://" + h + "/") or |
|
1369 | if (path.startswith("http://" + h + "/") or | |
1370 | path.startswith("http://" + h + ":") or |
|
1370 | path.startswith("http://" + h + ":") or | |
1371 | path == "http://" + h): |
|
1371 | path == "http://" + h): | |
1372 | no_proxy = 1 |
|
1372 | no_proxy = 1 | |
1373 |
|
1373 | |||
1374 | # Note: urllib2 takes proxy values from the environment and those will |
|
1374 | # Note: urllib2 takes proxy values from the environment and those will | |
1375 | # take precedence |
|
1375 | # take precedence | |
1376 |
|
1376 | |||
1377 | proxy_handler = urllib2.BaseHandler() |
|
1377 | proxy_handler = urllib2.BaseHandler() | |
1378 | if host and not no_proxy: |
|
1378 | if host and not no_proxy: | |
1379 | proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) |
|
1379 | proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) | |
1380 |
|
1380 | |||
1381 | authinfo = None |
|
1381 | authinfo = None | |
1382 | if user and passwd: |
|
1382 | if user and passwd: | |
1383 | passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() |
|
1383 | passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() | |
1384 | passmgr.add_password(None, host, user, passwd) |
|
1384 | passmgr.add_password(None, host, user, passwd) | |
1385 | authinfo = urllib2.ProxyBasicAuthHandler(passmgr) |
|
1385 | authinfo = urllib2.ProxyBasicAuthHandler(passmgr) | |
1386 |
|
1386 | |||
1387 | opener = urllib2.build_opener(proxy_handler, authinfo) |
|
1387 | opener = urllib2.build_opener(proxy_handler, authinfo) | |
1388 | urllib2.install_opener(opener) |
|
1388 | urllib2.install_opener(opener) | |
1389 |
|
1389 | |||
1390 | def do_cmd(self, cmd, **args): |
|
1390 | def do_cmd(self, cmd, **args): | |
1391 | self.ui.debug("sending %s command\n" % cmd) |
|
1391 | self.ui.debug("sending %s command\n" % cmd) | |
1392 | q = {"cmd": cmd} |
|
1392 | q = {"cmd": cmd} | |
1393 | q.update(args) |
|
1393 | q.update(args) | |
1394 | qs = urllib.urlencode(q) |
|
1394 | qs = urllib.urlencode(q) | |
1395 | cu = "%s?%s" % (self.url, qs) |
|
1395 | cu = "%s?%s" % (self.url, qs) | |
1396 | return urllib2.urlopen(cu) |
|
1396 | return urllib2.urlopen(cu) | |
1397 |
|
1397 | |||
1398 | def heads(self): |
|
1398 | def heads(self): | |
1399 | d = self.do_cmd("heads").read() |
|
1399 | d = self.do_cmd("heads").read() | |
1400 | try: |
|
1400 | try: | |
1401 | return map(bin, d[:-1].split(" ")) |
|
1401 | return map(bin, d[:-1].split(" ")) | |
1402 | except: |
|
1402 | except: | |
1403 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1403 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | |
1404 | raise |
|
1404 | raise | |
1405 |
|
1405 | |||
1406 | def branches(self, nodes): |
|
1406 | def branches(self, nodes): | |
1407 | n = " ".join(map(hex, nodes)) |
|
1407 | n = " ".join(map(hex, nodes)) | |
1408 | d = self.do_cmd("branches", nodes=n).read() |
|
1408 | d = self.do_cmd("branches", nodes=n).read() | |
1409 | try: |
|
1409 | try: | |
1410 | br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] |
|
1410 | br = [ tuple(map(bin, b.split(" "))) for b in d.splitlines() ] | |
1411 | return br |
|
1411 | return br | |
1412 | except: |
|
1412 | except: | |
1413 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1413 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | |
1414 | raise |
|
1414 | raise | |
1415 |
|
1415 | |||
1416 | def between(self, pairs): |
|
1416 | def between(self, pairs): | |
1417 | n = "\n".join(["-".join(map(hex, p)) for p in pairs]) |
|
1417 | n = "\n".join(["-".join(map(hex, p)) for p in pairs]) | |
1418 | d = self.do_cmd("between", pairs=n).read() |
|
1418 | d = self.do_cmd("between", pairs=n).read() | |
1419 | try: |
|
1419 | try: | |
1420 | p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] |
|
1420 | p = [ l and map(bin, l.split(" ")) or [] for l in d.splitlines() ] | |
1421 | return p |
|
1421 | return p | |
1422 | except: |
|
1422 | except: | |
1423 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") |
|
1423 | self.ui.warn("unexpected response:\n" + d[:400] + "\n...\n") | |
1424 | raise |
|
1424 | raise | |
1425 |
|
1425 | |||
1426 | def changegroup(self, nodes): |
|
1426 | def changegroup(self, nodes): | |
1427 | n = " ".join(map(hex, nodes)) |
|
1427 | n = " ".join(map(hex, nodes)) | |
1428 | zd = zlib.decompressobj() |
|
1428 | zd = zlib.decompressobj() | |
1429 | f = self.do_cmd("changegroup", roots=n) |
|
1429 | f = self.do_cmd("changegroup", roots=n) | |
1430 | bytes = 0 |
|
1430 | bytes = 0 | |
1431 | while 1: |
|
1431 | while 1: | |
1432 | d = f.read(4096) |
|
1432 | d = f.read(4096) | |
1433 | bytes += len(d) |
|
1433 | bytes += len(d) | |
1434 | if not d: |
|
1434 | if not d: | |
1435 | yield zd.flush() |
|
1435 | yield zd.flush() | |
1436 | break |
|
1436 | break | |
1437 | yield zd.decompress(d) |
|
1437 | yield zd.decompress(d) | |
1438 | self.ui.note("%d bytes of data transfered\n" % bytes) |
|
1438 | self.ui.note("%d bytes of data transfered\n" % bytes) | |
1439 |
|
1439 | |||
1440 | def repository(ui, path=None, create=0): |
|
1440 | def repository(ui, path=None, create=0): | |
1441 | if path and path[:7] == "http://": |
|
1441 | if path and path[:7] == "http://": | |
1442 | return remoterepository(ui, path) |
|
1442 | return remoterepository(ui, path) | |
1443 | if path and path[:5] == "hg://": |
|
1443 | if path and path[:5] == "hg://": | |
1444 | return remoterepository(ui, path.replace("hg://", "http://")) |
|
1444 | return remoterepository(ui, path.replace("hg://", "http://")) | |
1445 | if path and path[:11] == "old-http://": |
|
1445 | if path and path[:11] == "old-http://": | |
1446 | return localrepository(ui, path.replace("old-http://", "http://")) |
|
1446 | return localrepository(ui, path.replace("old-http://", "http://")) | |
1447 | else: |
|
1447 | else: | |
1448 | return localrepository(ui, path, create) |
|
1448 | return localrepository(ui, path, create) | |
1449 |
|
1449 |
General Comments 0
You need to be logged in to leave comments.
Login now