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