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