Show More
@@ -1,573 +1,574 b'' | |||
|
1 | 1 | # hg.py - repository classes for mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms |
|
6 | 6 | # of the GNU General Public License, incorporated herein by reference. |
|
7 | 7 | |
|
8 | 8 | import sys, struct, sha, socket, os, time, base64, re, urllib2, binascii |
|
9 | 9 | from mercurial import byterange |
|
10 | 10 | from mercurial.transaction import * |
|
11 | 11 | from mercurial.revlog import * |
|
12 | 12 | |
|
13 | 13 | def hex(node): return binascii.hexlify(node) |
|
14 | 14 | def bin(node): return binascii.unhexlify(node) |
|
15 | 15 | |
|
16 | 16 | class filelog(revlog): |
|
17 | 17 | def __init__(self, opener, path): |
|
18 | 18 | s = self.encodepath(path) |
|
19 | 19 | revlog.__init__(self, opener, os.path.join("data", s + "i"), |
|
20 | 20 | os.path.join("data", s)) |
|
21 | 21 | |
|
22 | 22 | def encodepath(self, path): |
|
23 | 23 | s = sha.sha(path).digest() |
|
24 | 24 | s = base64.encodestring(s)[:-3] |
|
25 | 25 | s = re.sub("\+", "%", s) |
|
26 | 26 | s = re.sub("/", "_", s) |
|
27 | 27 | return s |
|
28 | 28 | |
|
29 | 29 | def read(self, node): |
|
30 | 30 | return self.revision(node) |
|
31 | 31 | def add(self, text, transaction, link, p1=None, p2=None): |
|
32 | 32 | return self.addrevision(text, transaction, link, p1, p2) |
|
33 | 33 | |
|
34 | 34 | def resolvedag(self, old, new, transaction, link): |
|
35 | 35 | """resolve unmerged heads in our DAG""" |
|
36 | 36 | if old == new: return None |
|
37 | 37 | a = self.ancestor(old, new) |
|
38 | 38 | if old == a: return new |
|
39 | 39 | return self.merge3(old, new, a, transaction, link) |
|
40 | 40 | |
|
41 | 41 | def merge3(self, my, other, base, transaction, link): |
|
42 | 42 | """perform a 3-way merge and append the result""" |
|
43 | 43 | def temp(prefix, node): |
|
44 | 44 | (fd, name) = tempfile.mkstemp(prefix) |
|
45 | 45 | f = os.fdopen(fd, "w") |
|
46 | 46 | f.write(self.revision(node)) |
|
47 | 47 | f.close() |
|
48 | 48 | return name |
|
49 | 49 | |
|
50 | 50 | a = temp("local", my) |
|
51 | 51 | b = temp("remote", other) |
|
52 | 52 | c = temp("parent", base) |
|
53 | 53 | |
|
54 | 54 | cmd = os.environ["HGMERGE"] |
|
55 | 55 | r = os.system("%s %s %s %s" % (cmd, a, b, c)) |
|
56 | 56 | if r: |
|
57 | 57 | raise "Merge failed, implement rollback!" |
|
58 | 58 | |
|
59 | 59 | t = open(a).read() |
|
60 | 60 | os.unlink(a) |
|
61 | 61 | os.unlink(b) |
|
62 | 62 | os.unlink(c) |
|
63 | 63 | return self.addrevision(t, transaction, link, my, other) |
|
64 | 64 | |
|
65 | 65 | def merge(self, other, transaction, linkseq, link): |
|
66 | 66 | """perform a merge and resolve resulting heads""" |
|
67 | 67 | (o, n) = self.mergedag(other, transaction, linkseq) |
|
68 | 68 | return self.resolvedag(o, n, transaction, link) |
|
69 | 69 | |
|
70 | 70 | class manifest(revlog): |
|
71 | 71 | def __init__(self, opener): |
|
72 | 72 | self.mapcache = None |
|
73 | 73 | self.listcache = None |
|
74 | 74 | self.addlist = None |
|
75 | 75 | revlog.__init__(self, opener, "00manifest.i", "00manifest.d") |
|
76 | 76 | |
|
77 | 77 | def read(self, node): |
|
78 | 78 | if self.mapcache and self.mapcache[0] == node: |
|
79 | 79 | return self.mapcache[1] |
|
80 | 80 | text = self.revision(node) |
|
81 | 81 | map = {} |
|
82 | 82 | self.listcache = text.splitlines(1) |
|
83 | 83 | for l in self.listcache: |
|
84 | 84 | (f, n) = l.split('\0') |
|
85 | 85 | map[f] = bin(n[:40]) |
|
86 | 86 | self.mapcache = (node, map) |
|
87 | 87 | return map |
|
88 | 88 | |
|
89 | 89 | def diff(self, a, b): |
|
90 | 90 | # this is sneaky, as we're not actually using a and b |
|
91 | 91 | if self.listcache: |
|
92 | 92 | return mdiff.diff(self.listcache, self.addlist, 1) |
|
93 | 93 | else: |
|
94 | 94 | return mdiff.diff(a, b) |
|
95 | 95 | |
|
96 | 96 | def add(self, map, transaction, link, p1=None, p2=None): |
|
97 | 97 | files = map.keys() |
|
98 | 98 | files.sort() |
|
99 | 99 | |
|
100 | 100 | self.addlist = ["%s\000%s\n" % (f, hex(map[f])) for f in files] |
|
101 | 101 | text = "".join(self.addlist) |
|
102 | 102 | |
|
103 | 103 | n = self.addrevision(text, transaction, link, p1, p2) |
|
104 | 104 | self.mapcache = (n, map) |
|
105 | 105 | self.listcache = self.addlist |
|
106 | 106 | |
|
107 | 107 | return n |
|
108 | 108 | |
|
109 | 109 | class changelog(revlog): |
|
110 | 110 | def __init__(self, opener): |
|
111 | 111 | revlog.__init__(self, opener, "00changelog.i", "00changelog.d") |
|
112 | 112 | |
|
113 | 113 | def extract(self, text): |
|
114 | 114 | last = text.index("\n\n") |
|
115 | 115 | desc = text[last + 2:] |
|
116 | 116 | l = text[:last].splitlines() |
|
117 | 117 | manifest = bin(l[0]) |
|
118 | 118 | user = l[1] |
|
119 | 119 | date = l[2] |
|
120 | 120 | files = l[3:] |
|
121 | 121 | return (manifest, user, date, files, desc) |
|
122 | 122 | |
|
123 | 123 | def read(self, node): |
|
124 | 124 | return self.extract(self.revision(node)) |
|
125 | 125 | |
|
126 | 126 | def add(self, manifest, list, desc, transaction, p1=None, p2=None): |
|
127 | 127 | try: user = os.environ["HGUSER"] |
|
128 | 128 | except: user = os.environ["LOGNAME"] + '@' + socket.getfqdn() |
|
129 | 129 | date = "%d %d" % (time.time(), time.timezone) |
|
130 | 130 | list.sort() |
|
131 | 131 | l = [hex(manifest), user, date] + list + ["", desc] |
|
132 | 132 | text = "\n".join(l) |
|
133 | 133 | return self.addrevision(text, transaction, self.count(), p1, p2) |
|
134 | 134 | |
|
135 | 135 | def merge3(self, my, other, base): |
|
136 | 136 | pass |
|
137 | 137 | |
|
138 | 138 | class dircache: |
|
139 | 139 | def __init__(self, opener): |
|
140 | 140 | self.opener = opener |
|
141 | 141 | self.dirty = 0 |
|
142 | 142 | self.map = None |
|
143 | 143 | def __del__(self): |
|
144 | 144 | if self.dirty: self.write() |
|
145 | 145 | def __getitem__(self, key): |
|
146 | 146 | try: |
|
147 | 147 | return self.map[key] |
|
148 | 148 | except TypeError: |
|
149 | 149 | self.read() |
|
150 | 150 | return self[key] |
|
151 | 151 | |
|
152 | 152 | def read(self): |
|
153 | 153 | if self.map is not None: return self.map |
|
154 | 154 | |
|
155 | 155 | self.map = {} |
|
156 | 156 | try: |
|
157 | 157 | st = self.opener("dircache").read() |
|
158 | 158 | except: return |
|
159 | 159 | |
|
160 | 160 | pos = 0 |
|
161 | 161 | while pos < len(st): |
|
162 | 162 | e = struct.unpack(">llll", st[pos:pos+16]) |
|
163 | 163 | l = e[3] |
|
164 | 164 | pos += 16 |
|
165 | 165 | f = st[pos:pos + l] |
|
166 | 166 | self.map[f] = e[:3] |
|
167 | 167 | pos += l |
|
168 | 168 | |
|
169 | 169 | def update(self, files): |
|
170 | 170 | if not files: return |
|
171 | 171 | self.read() |
|
172 | 172 | self.dirty = 1 |
|
173 | 173 | for f in files: |
|
174 | 174 | try: |
|
175 | 175 | s = os.stat(f) |
|
176 | 176 | self.map[f] = (s.st_mode, s.st_size, s.st_mtime) |
|
177 | 177 | except IOError: |
|
178 | 178 | self.remove(f) |
|
179 | 179 | |
|
180 | 180 | def taint(self, files): |
|
181 | 181 | if not files: return |
|
182 | 182 | self.read() |
|
183 | 183 | self.dirty = 1 |
|
184 | 184 | for f in files: |
|
185 | 185 | self.map[f] = (0, -1, 0) |
|
186 | 186 | |
|
187 | 187 | def remove(self, files): |
|
188 | 188 | if not files: return |
|
189 | 189 | self.read() |
|
190 | 190 | self.dirty = 1 |
|
191 | 191 | for f in files: |
|
192 | 192 | try: del self[f] |
|
193 | 193 | except: pass |
|
194 | 194 | |
|
195 | 195 | def clear(self): |
|
196 | 196 | self.map = {} |
|
197 | 197 | self.dirty = 1 |
|
198 | 198 | |
|
199 | 199 | def write(self): |
|
200 | 200 | st = self.opener("dircache", "w") |
|
201 | 201 | for f, e in self.map.items(): |
|
202 | 202 | e = struct.pack(">llll", e[0], e[1], e[2], len(f)) |
|
203 | 203 | st.write(e + f) |
|
204 | 204 | self.dirty = 0 |
|
205 | 205 | |
|
206 | 206 | def copy(self): |
|
207 | 207 | self.read() |
|
208 | 208 | return self.map.copy() |
|
209 | 209 | |
|
210 | 210 | # used to avoid circular references so destructors work |
|
211 | 211 | def opener(base): |
|
212 | 212 | p = base |
|
213 | 213 | def o(path, mode="r"): |
|
214 | 214 | f = os.path.join(p, path) |
|
215 | 215 | if p[:7] == "http://": |
|
216 | 216 | return httprangereader(f) |
|
217 | 217 | |
|
218 | 218 | if mode != "r" and os.path.isfile(f): |
|
219 | 219 | s = os.stat(f) |
|
220 | 220 | if s.st_nlink > 1: |
|
221 | 221 | file(f + ".tmp", "w").write(file(f).read()) |
|
222 | 222 | os.rename(f+".tmp", f) |
|
223 | 223 | |
|
224 | 224 | return file(f, mode) |
|
225 | 225 | |
|
226 | 226 | return o |
|
227 | 227 | |
|
228 | 228 | class repository: |
|
229 | 229 | def __init__(self, ui, path=None, create=0): |
|
230 | 230 | self.remote = 0 |
|
231 | 231 | if path and path[:7] == "http://": |
|
232 | 232 | self.remote = 1 |
|
233 | 233 | self.path = path |
|
234 | 234 | else: |
|
235 | 235 | if not path: |
|
236 | 236 | p = os.getcwd() |
|
237 | 237 | while not os.path.isdir(os.path.join(p, ".hg")): |
|
238 | 238 | p = os.path.dirname(p) |
|
239 | 239 | if p == "/": raise "No repo found" |
|
240 | 240 | path = p |
|
241 | 241 | self.path = os.path.join(path, ".hg") |
|
242 | 242 | |
|
243 | 243 | self.root = path |
|
244 | 244 | self.ui = ui |
|
245 | 245 | |
|
246 | 246 | if create: |
|
247 | 247 | os.mkdir(self.path) |
|
248 | 248 | os.mkdir(self.join("data")) |
|
249 | 249 | |
|
250 | 250 | self.opener = opener(self.path) |
|
251 | 251 | self.manifest = manifest(self.opener) |
|
252 | 252 | self.changelog = changelog(self.opener) |
|
253 | 253 | self.ignorelist = None |
|
254 | 254 | |
|
255 | 255 | if not self.remote: |
|
256 | 256 | self.dircache = dircache(self.opener) |
|
257 | 257 | try: |
|
258 | 258 | self.current = bin(self.opener("current").read()) |
|
259 | 259 | except IOError: |
|
260 | 260 | self.current = None |
|
261 | 261 | |
|
262 | 262 | def setcurrent(self, node): |
|
263 | 263 | self.current = node |
|
264 | 264 | self.opener("current", "w").write(hex(node)) |
|
265 | 265 | |
|
266 | 266 | def ignore(self, f): |
|
267 | 267 | if self.ignorelist is None: |
|
268 | 268 | self.ignorelist = [] |
|
269 | 269 | try: |
|
270 | 270 | l = open(os.path.join(self.root, ".hgignore")).readlines() |
|
271 | 271 | for pat in l: |
|
272 | self.ignorelist.append(re.compile(pat[:-1])) | |
|
272 | if pat != "\n": | |
|
273 | self.ignorelist.append(re.compile(pat[:-1])) | |
|
273 | 274 | except IOError: pass |
|
274 | 275 | for pat in self.ignorelist: |
|
275 | 276 | if pat.search(f): return True |
|
276 | 277 | return False |
|
277 | 278 | |
|
278 | 279 | def join(self, f): |
|
279 | 280 | return os.path.join(self.path, f) |
|
280 | 281 | |
|
281 | 282 | def file(self, f): |
|
282 | 283 | return filelog(self.opener, f) |
|
283 | 284 | |
|
284 | 285 | def transaction(self): |
|
285 | 286 | return transaction(self.opener, self.join("journal")) |
|
286 | 287 | |
|
287 | 288 | def merge(self, other): |
|
288 | 289 | tr = self.transaction() |
|
289 | 290 | changed = {} |
|
290 | 291 | new = {} |
|
291 | 292 | nextrev = seqrev = self.changelog.count() |
|
292 | 293 | |
|
293 | 294 | # helpers for back-linking file revisions to local changeset |
|
294 | 295 | # revisions so we can immediately get to changeset from annotate |
|
295 | 296 | def accumulate(text): |
|
296 | 297 | n = nextrev |
|
297 | 298 | # track which files are added in which changeset and the |
|
298 | 299 | # corresponding _local_ changeset revision |
|
299 | 300 | files = self.changelog.extract(text)[3] |
|
300 | 301 | for f in files: |
|
301 | 302 | changed.setdefault(f, []).append(n) |
|
302 | 303 | n += 1 |
|
303 | 304 | |
|
304 | 305 | def seq(start): |
|
305 | 306 | while 1: |
|
306 | 307 | yield start |
|
307 | 308 | start += 1 |
|
308 | 309 | |
|
309 | 310 | def lseq(l): |
|
310 | 311 | for r in l: |
|
311 | 312 | yield r |
|
312 | 313 | |
|
313 | 314 | # begin the import/merge of changesets |
|
314 | 315 | self.ui.status("merging new changesets\n") |
|
315 | 316 | (co, cn) = self.changelog.mergedag(other.changelog, tr, |
|
316 | 317 | seq(seqrev), accumulate) |
|
317 | 318 | resolverev = self.changelog.count() |
|
318 | 319 | |
|
319 | 320 | # is there anything to do? |
|
320 | 321 | if co == cn: |
|
321 | 322 | tr.close() |
|
322 | 323 | return |
|
323 | 324 | |
|
324 | 325 | # do we need to resolve? |
|
325 | 326 | simple = (co == self.changelog.ancestor(co, cn)) |
|
326 | 327 | |
|
327 | 328 | # merge all files changed by the changesets, |
|
328 | 329 | # keeping track of the new tips |
|
329 | 330 | changelist = changed.keys() |
|
330 | 331 | changelist.sort() |
|
331 | 332 | for f in changelist: |
|
332 | 333 | sys.stdout.write(".") |
|
333 | 334 | sys.stdout.flush() |
|
334 | 335 | r = self.file(f) |
|
335 | 336 | node = r.merge(other.file(f), tr, lseq(changed[f]), resolverev) |
|
336 | 337 | if node: |
|
337 | 338 | new[f] = node |
|
338 | 339 | sys.stdout.write("\n") |
|
339 | 340 | |
|
340 | 341 | # begin the merge of the manifest |
|
341 | 342 | self.ui.status("merging manifests\n") |
|
342 | 343 | (mm, mo) = self.manifest.mergedag(other.manifest, tr, seq(seqrev)) |
|
343 | 344 | |
|
344 | 345 | # For simple merges, we don't need to resolve manifests or changesets |
|
345 | 346 | if simple: |
|
346 | 347 | tr.close() |
|
347 | 348 | return |
|
348 | 349 | |
|
349 | 350 | ma = self.manifest.ancestor(mm, mo) |
|
350 | 351 | |
|
351 | 352 | # resolve the manifest to point to all the merged files |
|
352 | 353 | self.ui.status("resolving manifests\n") |
|
353 | 354 | mmap = self.manifest.read(mm) # mine |
|
354 | 355 | omap = self.manifest.read(mo) # other |
|
355 | 356 | amap = self.manifest.read(ma) # ancestor |
|
356 | 357 | nmap = {} |
|
357 | 358 | |
|
358 | 359 | for f, mid in mmap.iteritems(): |
|
359 | 360 | if f in omap: |
|
360 | 361 | if mid != omap[f]: |
|
361 | 362 | nmap[f] = new.get(f, mid) # use merged version |
|
362 | 363 | else: |
|
363 | 364 | nmap[f] = new.get(f, mid) # they're the same |
|
364 | 365 | del omap[f] |
|
365 | 366 | elif f in amap: |
|
366 | 367 | if mid != amap[f]: |
|
367 | 368 | pass # we should prompt here |
|
368 | 369 | else: |
|
369 | 370 | pass # other deleted it |
|
370 | 371 | else: |
|
371 | 372 | nmap[f] = new.get(f, mid) # we created it |
|
372 | 373 | |
|
373 | 374 | del mmap |
|
374 | 375 | |
|
375 | 376 | for f, oid in omap.iteritems(): |
|
376 | 377 | if f in amap: |
|
377 | 378 | if oid != amap[f]: |
|
378 | 379 | pass # this is the nasty case, we should prompt |
|
379 | 380 | else: |
|
380 | 381 | pass # probably safe |
|
381 | 382 | else: |
|
382 | 383 | nmap[f] = new.get(f, oid) # remote created it |
|
383 | 384 | |
|
384 | 385 | del omap |
|
385 | 386 | del amap |
|
386 | 387 | |
|
387 | 388 | node = self.manifest.add(nmap, tr, resolverev, mm, mo) |
|
388 | 389 | |
|
389 | 390 | # Now all files and manifests are merged, we add the changed files |
|
390 | 391 | # and manifest id to the changelog |
|
391 | 392 | self.ui.status("committing merge changeset\n") |
|
392 | 393 | new = new.keys() |
|
393 | 394 | new.sort() |
|
394 | 395 | if co == cn: cn = -1 |
|
395 | 396 | |
|
396 | 397 | edittext = "\n"+"".join(["HG: changed %s\n" % f for f in new]) |
|
397 | 398 | edittext = self.ui.edit(edittext) |
|
398 | 399 | n = self.changelog.add(node, new, edittext, tr, co, cn) |
|
399 | 400 | |
|
400 | 401 | tr.close() |
|
401 | 402 | |
|
402 | 403 | def commit(self, update = None, text = ""): |
|
403 | 404 | tr = self.transaction() |
|
404 | 405 | |
|
405 | 406 | try: |
|
406 | 407 | remove = [ l[:-1] for l in self.opener("to-remove") ] |
|
407 | 408 | os.unlink(self.join("to-remove")) |
|
408 | 409 | |
|
409 | 410 | except IOError: |
|
410 | 411 | remove = [] |
|
411 | 412 | |
|
412 | 413 | if update == None: |
|
413 | 414 | update = self.diffdir(self.root)[0] |
|
414 | 415 | |
|
415 | 416 | # check in files |
|
416 | 417 | new = {} |
|
417 | 418 | linkrev = self.changelog.count() |
|
418 | 419 | for f in update: |
|
419 | 420 | try: |
|
420 | 421 | t = file(f).read() |
|
421 | 422 | except IOError: |
|
422 | 423 | remove.append(f) |
|
423 | 424 | continue |
|
424 | 425 | r = self.file(f) |
|
425 | 426 | new[f] = r.add(t, tr, linkrev) |
|
426 | 427 | |
|
427 | 428 | # update manifest |
|
428 | 429 | mmap = self.manifest.read(self.manifest.tip()) |
|
429 | 430 | mmap.update(new) |
|
430 | 431 | for f in remove: |
|
431 | 432 | del mmap[f] |
|
432 | 433 | mnode = self.manifest.add(mmap, tr, linkrev) |
|
433 | 434 | |
|
434 | 435 | # add changeset |
|
435 | 436 | new = new.keys() |
|
436 | 437 | new.sort() |
|
437 | 438 | |
|
438 | 439 | edittext = text + "\n"+"".join(["HG: changed %s\n" % f for f in new]) |
|
439 | 440 | edittext = self.ui.edit(edittext) |
|
440 | 441 | |
|
441 | 442 | n = self.changelog.add(mnode, new, edittext, tr) |
|
442 | 443 | tr.close() |
|
443 | 444 | |
|
444 | 445 | self.setcurrent(n) |
|
445 | 446 | self.dircache.update(new) |
|
446 | 447 | self.dircache.remove(remove) |
|
447 | 448 | |
|
448 | 449 | def checkdir(self, path): |
|
449 | 450 | d = os.path.dirname(path) |
|
450 | 451 | if not d: return |
|
451 | 452 | if not os.path.isdir(d): |
|
452 | 453 | self.checkdir(d) |
|
453 | 454 | os.mkdir(d) |
|
454 | 455 | |
|
455 | 456 | def checkout(self, node): |
|
456 | 457 | # checkout is really dumb at the moment |
|
457 | 458 | # it ought to basically merge |
|
458 | 459 | change = self.changelog.read(node) |
|
459 | 460 | mmap = self.manifest.read(change[0]) |
|
460 | 461 | |
|
461 | 462 | l = mmap.keys() |
|
462 | 463 | l.sort() |
|
463 | 464 | stats = [] |
|
464 | 465 | for f in l: |
|
465 | 466 | r = self.file(f) |
|
466 | 467 | t = r.revision(mmap[f]) |
|
467 | 468 | try: |
|
468 | 469 | file(f, "w").write(t) |
|
469 | 470 | except: |
|
470 | 471 | self.checkdir(f) |
|
471 | 472 | file(f, "w").write(t) |
|
472 | 473 | |
|
473 | 474 | self.setcurrent(node) |
|
474 | 475 | self.dircache.clear() |
|
475 | 476 | self.dircache.update(l) |
|
476 | 477 | |
|
477 | 478 | def diffdir(self, path): |
|
478 | 479 | dc = self.dircache.copy() |
|
479 | 480 | changed = [] |
|
480 | 481 | mf = {} |
|
481 | 482 | added = [] |
|
482 | 483 | |
|
483 | 484 | if self.current: |
|
484 | 485 | change = self.changelog.read(self.current) |
|
485 | 486 | mf = self.manifest.read(change[0]) |
|
486 | 487 | |
|
487 | 488 | for dir, subdirs, files in os.walk(self.root): |
|
488 | 489 | d = dir[len(self.root)+1:] |
|
489 | 490 | if ".hg" in subdirs: subdirs.remove(".hg") |
|
490 | 491 | |
|
491 | 492 | for f in files: |
|
492 | 493 | fn = os.path.join(d, f) |
|
493 | 494 | try: s = os.stat(fn) |
|
494 | 495 | except: continue |
|
495 | 496 | if fn in dc: |
|
496 | 497 | c = dc[fn] |
|
497 | 498 | del dc[fn] |
|
498 | 499 | if c[1] != s.st_size: |
|
499 | 500 | changed.append(fn) |
|
500 | 501 | elif c[0] != s.st_mode or c[2] != s.st_mtime: |
|
501 | 502 | t1 = file(fn).read() |
|
502 | 503 | t2 = self.file(fn).revision(mf[fn]) |
|
503 | 504 | if t1 != t2: |
|
504 | 505 | changed.append(fn) |
|
505 | 506 | else: |
|
506 | 507 | if self.ignore(fn): continue |
|
507 | 508 | added.append(fn) |
|
508 | 509 | |
|
509 | 510 | deleted = dc.keys() |
|
510 | 511 | deleted.sort() |
|
511 | 512 | |
|
512 | 513 | return (changed, added, deleted) |
|
513 | 514 | |
|
514 | 515 | def add(self, list): |
|
515 | 516 | self.dircache.taint(list) |
|
516 | 517 | |
|
517 | 518 | def remove(self, list): |
|
518 | 519 | dl = self.opener("to-remove", "a") |
|
519 | 520 | for f in list: |
|
520 | 521 | dl.write(f + "\n") |
|
521 | 522 | |
|
522 | 523 | class ui: |
|
523 | 524 | def __init__(self, verbose=False, debug=False): |
|
524 | 525 | self.verbose = verbose |
|
525 | 526 | def write(self, *args): |
|
526 | 527 | for a in args: |
|
527 | 528 | sys.stdout.write(str(a)) |
|
528 | 529 | def prompt(self, msg, pat): |
|
529 | 530 | while 1: |
|
530 | 531 | sys.stdout.write(msg) |
|
531 | 532 | r = sys.stdin.readline()[:-1] |
|
532 | 533 | if re.match(pat, r): |
|
533 | 534 | return r |
|
534 | 535 | def status(self, *msg): |
|
535 | 536 | self.write(*msg) |
|
536 | 537 | def warn(self, msg): |
|
537 | 538 | self.write(*msg) |
|
538 | 539 | def note(self, msg): |
|
539 | 540 | if self.verbose: self.write(*msg) |
|
540 | 541 | def debug(self, msg): |
|
541 | 542 | if self.debug: self.write(*msg) |
|
542 | 543 | def edit(self, text): |
|
543 | 544 | (fd, name) = tempfile.mkstemp("hg") |
|
544 | 545 | f = os.fdopen(fd, "w") |
|
545 | 546 | f.write(text) |
|
546 | 547 | f.close() |
|
547 | 548 | |
|
548 | 549 | editor = os.environ.get("EDITOR", "vi") |
|
549 | 550 | r = os.system("%s %s" % (editor, name)) |
|
550 | 551 | if r: |
|
551 | 552 | raise "Edit failed!" |
|
552 | 553 | |
|
553 | 554 | t = open(name).read() |
|
554 | 555 | t = re.sub("(?m)^HG:.*\n", "", t) |
|
555 | 556 | |
|
556 | 557 | return t |
|
557 | 558 | |
|
558 | 559 | |
|
559 | 560 | class httprangereader: |
|
560 | 561 | def __init__(self, url): |
|
561 | 562 | self.url = url |
|
562 | 563 | self.pos = 0 |
|
563 | 564 | def seek(self, pos): |
|
564 | 565 | self.pos = pos |
|
565 | 566 | def read(self, bytes=None): |
|
566 | 567 | opener = urllib2.build_opener(byterange.HTTPRangeHandler()) |
|
567 | 568 | urllib2.install_opener(opener) |
|
568 | 569 | req = urllib2.Request(self.url) |
|
569 | 570 | end = '' |
|
570 | 571 | if bytes: end = self.pos + bytes |
|
571 | 572 | req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) |
|
572 | 573 | f = urllib2.urlopen(req) |
|
573 | 574 | return f.read() |
General Comments 0
You need to be logged in to leave comments.
Login now