##// END OF EJS Templates
introduce fncache repository layout...
Adrian Buehlmann -
r7229:7946503e default
parent child Browse files
Show More
@@ -1,2105 +1,2106 b''
1 1 # localrepo.py - read/write repository class for mercurial
2 2 #
3 3 # Copyright 2005-2007 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 from node import bin, hex, nullid, nullrev, short
9 9 from i18n import _
10 10 import repo, changegroup
11 11 import changelog, dirstate, filelog, manifest, context, weakref
12 12 import lock, transaction, stat, errno, ui, store
13 13 import os, revlog, time, util, extensions, hook, inspect
14 14 import match as match_
15 15 import merge as merge_
16 16
17 17 class localrepository(repo.repository):
18 18 capabilities = util.set(('lookup', 'changegroupsubset'))
19 supported = ('revlogv1', 'store')
19 supported = ('revlogv1', 'store', 'fncache')
20 20
21 21 def __init__(self, parentui, path=None, create=0):
22 22 repo.repository.__init__(self)
23 23 self.root = os.path.realpath(path)
24 24 self.path = os.path.join(self.root, ".hg")
25 25 self.origroot = path
26 26 self.opener = util.opener(self.path)
27 27 self.wopener = util.opener(self.root)
28 28
29 29 if not os.path.isdir(self.path):
30 30 if create:
31 31 if not os.path.exists(path):
32 32 os.mkdir(path)
33 33 os.mkdir(self.path)
34 34 requirements = ["revlogv1"]
35 35 if parentui.configbool('format', 'usestore', True):
36 36 os.mkdir(os.path.join(self.path, "store"))
37 37 requirements.append("store")
38 requirements.append("fncache")
38 39 # create an invalid changelog
39 40 self.opener("00changelog.i", "a").write(
40 41 '\0\0\0\2' # represents revlogv2
41 42 ' dummy changelog to prevent using the old repo layout'
42 43 )
43 44 reqfile = self.opener("requires", "w")
44 45 for r in requirements:
45 46 reqfile.write("%s\n" % r)
46 47 reqfile.close()
47 48 else:
48 49 raise repo.RepoError(_("repository %s not found") % path)
49 50 elif create:
50 51 raise repo.RepoError(_("repository %s already exists") % path)
51 52 else:
52 53 # find requirements
53 54 requirements = []
54 55 try:
55 56 requirements = self.opener("requires").read().splitlines()
56 57 for r in requirements:
57 58 if r not in self.supported:
58 59 raise repo.RepoError(_("requirement '%s' not supported") % r)
59 60 except IOError, inst:
60 61 if inst.errno != errno.ENOENT:
61 62 raise
62 63
63 64 self.store = store.store(requirements, self.path, util.opener)
64 65 self.spath = self.store.path
65 66 self.sopener = self.store.opener
66 67 self.sjoin = self.store.join
67 68 self.opener.createmode = self.store.createmode
68 69
69 70 self.ui = ui.ui(parentui=parentui)
70 71 try:
71 72 self.ui.readconfig(self.join("hgrc"), self.root)
72 73 extensions.loadall(self.ui)
73 74 except IOError:
74 75 pass
75 76
76 77 self.tagscache = None
77 78 self._tagstypecache = None
78 79 self.branchcache = None
79 80 self._ubranchcache = None # UTF-8 version of branchcache
80 81 self._branchcachetip = None
81 82 self.nodetagscache = None
82 83 self.filterpats = {}
83 84 self._datafilters = {}
84 85 self._transref = self._lockref = self._wlockref = None
85 86
86 87 def __getattr__(self, name):
87 88 if name == 'changelog':
88 89 self.changelog = changelog.changelog(self.sopener)
89 90 self.sopener.defversion = self.changelog.version
90 91 return self.changelog
91 92 if name == 'manifest':
92 93 self.changelog
93 94 self.manifest = manifest.manifest(self.sopener)
94 95 return self.manifest
95 96 if name == 'dirstate':
96 97 self.dirstate = dirstate.dirstate(self.opener, self.ui, self.root)
97 98 return self.dirstate
98 99 else:
99 100 raise AttributeError(name)
100 101
101 102 def __getitem__(self, changeid):
102 103 if changeid == None:
103 104 return context.workingctx(self)
104 105 return context.changectx(self, changeid)
105 106
106 107 def __nonzero__(self):
107 108 return True
108 109
109 110 def __len__(self):
110 111 return len(self.changelog)
111 112
112 113 def __iter__(self):
113 114 for i in xrange(len(self)):
114 115 yield i
115 116
116 117 def url(self):
117 118 return 'file:' + self.root
118 119
119 120 def hook(self, name, throw=False, **args):
120 121 return hook.hook(self.ui, self, name, throw, **args)
121 122
122 123 tag_disallowed = ':\r\n'
123 124
124 125 def _tag(self, names, node, message, local, user, date, parent=None,
125 126 extra={}):
126 127 use_dirstate = parent is None
127 128
128 129 if isinstance(names, str):
129 130 allchars = names
130 131 names = (names,)
131 132 else:
132 133 allchars = ''.join(names)
133 134 for c in self.tag_disallowed:
134 135 if c in allchars:
135 136 raise util.Abort(_('%r cannot be used in a tag name') % c)
136 137
137 138 for name in names:
138 139 self.hook('pretag', throw=True, node=hex(node), tag=name,
139 140 local=local)
140 141
141 142 def writetags(fp, names, munge, prevtags):
142 143 fp.seek(0, 2)
143 144 if prevtags and prevtags[-1] != '\n':
144 145 fp.write('\n')
145 146 for name in names:
146 147 m = munge and munge(name) or name
147 148 if self._tagstypecache and name in self._tagstypecache:
148 149 old = self.tagscache.get(name, nullid)
149 150 fp.write('%s %s\n' % (hex(old), m))
150 151 fp.write('%s %s\n' % (hex(node), m))
151 152 fp.close()
152 153
153 154 prevtags = ''
154 155 if local:
155 156 try:
156 157 fp = self.opener('localtags', 'r+')
157 158 except IOError, err:
158 159 fp = self.opener('localtags', 'a')
159 160 else:
160 161 prevtags = fp.read()
161 162
162 163 # local tags are stored in the current charset
163 164 writetags(fp, names, None, prevtags)
164 165 for name in names:
165 166 self.hook('tag', node=hex(node), tag=name, local=local)
166 167 return
167 168
168 169 if use_dirstate:
169 170 try:
170 171 fp = self.wfile('.hgtags', 'rb+')
171 172 except IOError, err:
172 173 fp = self.wfile('.hgtags', 'ab')
173 174 else:
174 175 prevtags = fp.read()
175 176 else:
176 177 try:
177 178 prevtags = self.filectx('.hgtags', parent).data()
178 179 except revlog.LookupError:
179 180 pass
180 181 fp = self.wfile('.hgtags', 'wb')
181 182 if prevtags:
182 183 fp.write(prevtags)
183 184
184 185 # committed tags are stored in UTF-8
185 186 writetags(fp, names, util.fromlocal, prevtags)
186 187
187 188 if use_dirstate and '.hgtags' not in self.dirstate:
188 189 self.add(['.hgtags'])
189 190
190 191 tagnode = self.commit(['.hgtags'], message, user, date, p1=parent,
191 192 extra=extra)
192 193
193 194 for name in names:
194 195 self.hook('tag', node=hex(node), tag=name, local=local)
195 196
196 197 return tagnode
197 198
198 199 def tag(self, names, node, message, local, user, date):
199 200 '''tag a revision with one or more symbolic names.
200 201
201 202 names is a list of strings or, when adding a single tag, names may be a
202 203 string.
203 204
204 205 if local is True, the tags are stored in a per-repository file.
205 206 otherwise, they are stored in the .hgtags file, and a new
206 207 changeset is committed with the change.
207 208
208 209 keyword arguments:
209 210
210 211 local: whether to store tags in non-version-controlled file
211 212 (default False)
212 213
213 214 message: commit message to use if committing
214 215
215 216 user: name of user to use if committing
216 217
217 218 date: date tuple to use if committing'''
218 219
219 220 for x in self.status()[:5]:
220 221 if '.hgtags' in x:
221 222 raise util.Abort(_('working copy of .hgtags is changed '
222 223 '(please commit .hgtags manually)'))
223 224
224 225 self._tag(names, node, message, local, user, date)
225 226
226 227 def tags(self):
227 228 '''return a mapping of tag to node'''
228 229 if self.tagscache:
229 230 return self.tagscache
230 231
231 232 globaltags = {}
232 233 tagtypes = {}
233 234
234 235 def readtags(lines, fn, tagtype):
235 236 filetags = {}
236 237 count = 0
237 238
238 239 def warn(msg):
239 240 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg))
240 241
241 242 for l in lines:
242 243 count += 1
243 244 if not l:
244 245 continue
245 246 s = l.split(" ", 1)
246 247 if len(s) != 2:
247 248 warn(_("cannot parse entry"))
248 249 continue
249 250 node, key = s
250 251 key = util.tolocal(key.strip()) # stored in UTF-8
251 252 try:
252 253 bin_n = bin(node)
253 254 except TypeError:
254 255 warn(_("node '%s' is not well formed") % node)
255 256 continue
256 257 if bin_n not in self.changelog.nodemap:
257 258 warn(_("tag '%s' refers to unknown node") % key)
258 259 continue
259 260
260 261 h = []
261 262 if key in filetags:
262 263 n, h = filetags[key]
263 264 h.append(n)
264 265 filetags[key] = (bin_n, h)
265 266
266 267 for k, nh in filetags.items():
267 268 if k not in globaltags:
268 269 globaltags[k] = nh
269 270 tagtypes[k] = tagtype
270 271 continue
271 272
272 273 # we prefer the global tag if:
273 274 # it supercedes us OR
274 275 # mutual supercedes and it has a higher rank
275 276 # otherwise we win because we're tip-most
276 277 an, ah = nh
277 278 bn, bh = globaltags[k]
278 279 if (bn != an and an in bh and
279 280 (bn not in ah or len(bh) > len(ah))):
280 281 an = bn
281 282 ah.extend([n for n in bh if n not in ah])
282 283 globaltags[k] = an, ah
283 284 tagtypes[k] = tagtype
284 285
285 286 # read the tags file from each head, ending with the tip
286 287 f = None
287 288 for rev, node, fnode in self._hgtagsnodes():
288 289 f = (f and f.filectx(fnode) or
289 290 self.filectx('.hgtags', fileid=fnode))
290 291 readtags(f.data().splitlines(), f, "global")
291 292
292 293 try:
293 294 data = util.fromlocal(self.opener("localtags").read())
294 295 # localtags are stored in the local character set
295 296 # while the internal tag table is stored in UTF-8
296 297 readtags(data.splitlines(), "localtags", "local")
297 298 except IOError:
298 299 pass
299 300
300 301 self.tagscache = {}
301 302 self._tagstypecache = {}
302 303 for k,nh in globaltags.items():
303 304 n = nh[0]
304 305 if n != nullid:
305 306 self.tagscache[k] = n
306 307 self._tagstypecache[k] = tagtypes[k]
307 308 self.tagscache['tip'] = self.changelog.tip()
308 309 return self.tagscache
309 310
310 311 def tagtype(self, tagname):
311 312 '''
312 313 return the type of the given tag. result can be:
313 314
314 315 'local' : a local tag
315 316 'global' : a global tag
316 317 None : tag does not exist
317 318 '''
318 319
319 320 self.tags()
320 321
321 322 return self._tagstypecache.get(tagname)
322 323
323 324 def _hgtagsnodes(self):
324 325 heads = self.heads()
325 326 heads.reverse()
326 327 last = {}
327 328 ret = []
328 329 for node in heads:
329 330 c = self[node]
330 331 rev = c.rev()
331 332 try:
332 333 fnode = c.filenode('.hgtags')
333 334 except revlog.LookupError:
334 335 continue
335 336 ret.append((rev, node, fnode))
336 337 if fnode in last:
337 338 ret[last[fnode]] = None
338 339 last[fnode] = len(ret) - 1
339 340 return [item for item in ret if item]
340 341
341 342 def tagslist(self):
342 343 '''return a list of tags ordered by revision'''
343 344 l = []
344 345 for t, n in self.tags().items():
345 346 try:
346 347 r = self.changelog.rev(n)
347 348 except:
348 349 r = -2 # sort to the beginning of the list if unknown
349 350 l.append((r, t, n))
350 351 return [(t, n) for r, t, n in util.sort(l)]
351 352
352 353 def nodetags(self, node):
353 354 '''return the tags associated with a node'''
354 355 if not self.nodetagscache:
355 356 self.nodetagscache = {}
356 357 for t, n in self.tags().items():
357 358 self.nodetagscache.setdefault(n, []).append(t)
358 359 return self.nodetagscache.get(node, [])
359 360
360 361 def _branchtags(self, partial, lrev):
361 362 tiprev = len(self) - 1
362 363 if lrev != tiprev:
363 364 self._updatebranchcache(partial, lrev+1, tiprev+1)
364 365 self._writebranchcache(partial, self.changelog.tip(), tiprev)
365 366
366 367 return partial
367 368
368 369 def branchtags(self):
369 370 tip = self.changelog.tip()
370 371 if self.branchcache is not None and self._branchcachetip == tip:
371 372 return self.branchcache
372 373
373 374 oldtip = self._branchcachetip
374 375 self._branchcachetip = tip
375 376 if self.branchcache is None:
376 377 self.branchcache = {} # avoid recursion in changectx
377 378 else:
378 379 self.branchcache.clear() # keep using the same dict
379 380 if oldtip is None or oldtip not in self.changelog.nodemap:
380 381 partial, last, lrev = self._readbranchcache()
381 382 else:
382 383 lrev = self.changelog.rev(oldtip)
383 384 partial = self._ubranchcache
384 385
385 386 self._branchtags(partial, lrev)
386 387
387 388 # the branch cache is stored on disk as UTF-8, but in the local
388 389 # charset internally
389 390 for k, v in partial.items():
390 391 self.branchcache[util.tolocal(k)] = v
391 392 self._ubranchcache = partial
392 393 return self.branchcache
393 394
394 395 def _readbranchcache(self):
395 396 partial = {}
396 397 try:
397 398 f = self.opener("branch.cache")
398 399 lines = f.read().split('\n')
399 400 f.close()
400 401 except (IOError, OSError):
401 402 return {}, nullid, nullrev
402 403
403 404 try:
404 405 last, lrev = lines.pop(0).split(" ", 1)
405 406 last, lrev = bin(last), int(lrev)
406 407 if lrev >= len(self) or self[lrev].node() != last:
407 408 # invalidate the cache
408 409 raise ValueError('invalidating branch cache (tip differs)')
409 410 for l in lines:
410 411 if not l: continue
411 412 node, label = l.split(" ", 1)
412 413 partial[label.strip()] = bin(node)
413 414 except (KeyboardInterrupt, util.SignalInterrupt):
414 415 raise
415 416 except Exception, inst:
416 417 if self.ui.debugflag:
417 418 self.ui.warn(str(inst), '\n')
418 419 partial, last, lrev = {}, nullid, nullrev
419 420 return partial, last, lrev
420 421
421 422 def _writebranchcache(self, branches, tip, tiprev):
422 423 try:
423 424 f = self.opener("branch.cache", "w", atomictemp=True)
424 425 f.write("%s %s\n" % (hex(tip), tiprev))
425 426 for label, node in branches.iteritems():
426 427 f.write("%s %s\n" % (hex(node), label))
427 428 f.rename()
428 429 except (IOError, OSError):
429 430 pass
430 431
431 432 def _updatebranchcache(self, partial, start, end):
432 433 for r in xrange(start, end):
433 434 c = self[r]
434 435 b = c.branch()
435 436 partial[b] = c.node()
436 437
437 438 def lookup(self, key):
438 439 if key == '.':
439 440 return self.dirstate.parents()[0]
440 441 elif key == 'null':
441 442 return nullid
442 443 n = self.changelog._match(key)
443 444 if n:
444 445 return n
445 446 if key in self.tags():
446 447 return self.tags()[key]
447 448 if key in self.branchtags():
448 449 return self.branchtags()[key]
449 450 n = self.changelog._partialmatch(key)
450 451 if n:
451 452 return n
452 453 try:
453 454 if len(key) == 20:
454 455 key = hex(key)
455 456 except:
456 457 pass
457 458 raise repo.RepoError(_("unknown revision '%s'") % key)
458 459
459 460 def local(self):
460 461 return True
461 462
462 463 def join(self, f):
463 464 return os.path.join(self.path, f)
464 465
465 466 def wjoin(self, f):
466 467 return os.path.join(self.root, f)
467 468
468 469 def rjoin(self, f):
469 470 return os.path.join(self.root, util.pconvert(f))
470 471
471 472 def file(self, f):
472 473 if f[0] == '/':
473 474 f = f[1:]
474 475 return filelog.filelog(self.sopener, f)
475 476
476 477 def changectx(self, changeid):
477 478 return self[changeid]
478 479
479 480 def parents(self, changeid=None):
480 481 '''get list of changectxs for parents of changeid'''
481 482 return self[changeid].parents()
482 483
483 484 def filectx(self, path, changeid=None, fileid=None):
484 485 """changeid can be a changeset revision, node, or tag.
485 486 fileid can be a file revision or node."""
486 487 return context.filectx(self, path, changeid, fileid)
487 488
488 489 def getcwd(self):
489 490 return self.dirstate.getcwd()
490 491
491 492 def pathto(self, f, cwd=None):
492 493 return self.dirstate.pathto(f, cwd)
493 494
494 495 def wfile(self, f, mode='r'):
495 496 return self.wopener(f, mode)
496 497
497 498 def _link(self, f):
498 499 return os.path.islink(self.wjoin(f))
499 500
500 501 def _filter(self, filter, filename, data):
501 502 if filter not in self.filterpats:
502 503 l = []
503 504 for pat, cmd in self.ui.configitems(filter):
504 505 if cmd == '!':
505 506 continue
506 507 mf = util.matcher(self.root, "", [pat], [], [])[1]
507 508 fn = None
508 509 params = cmd
509 510 for name, filterfn in self._datafilters.iteritems():
510 511 if cmd.startswith(name):
511 512 fn = filterfn
512 513 params = cmd[len(name):].lstrip()
513 514 break
514 515 if not fn:
515 516 fn = lambda s, c, **kwargs: util.filter(s, c)
516 517 # Wrap old filters not supporting keyword arguments
517 518 if not inspect.getargspec(fn)[2]:
518 519 oldfn = fn
519 520 fn = lambda s, c, **kwargs: oldfn(s, c)
520 521 l.append((mf, fn, params))
521 522 self.filterpats[filter] = l
522 523
523 524 for mf, fn, cmd in self.filterpats[filter]:
524 525 if mf(filename):
525 526 self.ui.debug(_("filtering %s through %s\n") % (filename, cmd))
526 527 data = fn(data, cmd, ui=self.ui, repo=self, filename=filename)
527 528 break
528 529
529 530 return data
530 531
531 532 def adddatafilter(self, name, filter):
532 533 self._datafilters[name] = filter
533 534
534 535 def wread(self, filename):
535 536 if self._link(filename):
536 537 data = os.readlink(self.wjoin(filename))
537 538 else:
538 539 data = self.wopener(filename, 'r').read()
539 540 return self._filter("encode", filename, data)
540 541
541 542 def wwrite(self, filename, data, flags):
542 543 data = self._filter("decode", filename, data)
543 544 try:
544 545 os.unlink(self.wjoin(filename))
545 546 except OSError:
546 547 pass
547 548 if 'l' in flags:
548 549 self.wopener.symlink(data, filename)
549 550 else:
550 551 self.wopener(filename, 'w').write(data)
551 552 if 'x' in flags:
552 553 util.set_flags(self.wjoin(filename), False, True)
553 554
554 555 def wwritedata(self, filename, data):
555 556 return self._filter("decode", filename, data)
556 557
557 558 def transaction(self):
558 559 if self._transref and self._transref():
559 560 return self._transref().nest()
560 561
561 562 # abort here if the journal already exists
562 563 if os.path.exists(self.sjoin("journal")):
563 564 raise repo.RepoError(_("journal already exists - run hg recover"))
564 565
565 566 # save dirstate for rollback
566 567 try:
567 568 ds = self.opener("dirstate").read()
568 569 except IOError:
569 570 ds = ""
570 571 self.opener("journal.dirstate", "w").write(ds)
571 572 self.opener("journal.branch", "w").write(self.dirstate.branch())
572 573
573 574 renames = [(self.sjoin("journal"), self.sjoin("undo")),
574 575 (self.join("journal.dirstate"), self.join("undo.dirstate")),
575 576 (self.join("journal.branch"), self.join("undo.branch"))]
576 577 tr = transaction.transaction(self.ui.warn, self.sopener,
577 578 self.sjoin("journal"),
578 579 aftertrans(renames),
579 580 self.store.createmode)
580 581 self._transref = weakref.ref(tr)
581 582 return tr
582 583
583 584 def recover(self):
584 585 l = self.lock()
585 586 try:
586 587 if os.path.exists(self.sjoin("journal")):
587 588 self.ui.status(_("rolling back interrupted transaction\n"))
588 589 transaction.rollback(self.sopener, self.sjoin("journal"))
589 590 self.invalidate()
590 591 return True
591 592 else:
592 593 self.ui.warn(_("no interrupted transaction available\n"))
593 594 return False
594 595 finally:
595 596 del l
596 597
597 598 def rollback(self):
598 599 wlock = lock = None
599 600 try:
600 601 wlock = self.wlock()
601 602 lock = self.lock()
602 603 if os.path.exists(self.sjoin("undo")):
603 604 self.ui.status(_("rolling back last transaction\n"))
604 605 transaction.rollback(self.sopener, self.sjoin("undo"))
605 606 util.rename(self.join("undo.dirstate"), self.join("dirstate"))
606 607 try:
607 608 branch = self.opener("undo.branch").read()
608 609 self.dirstate.setbranch(branch)
609 610 except IOError:
610 611 self.ui.warn(_("Named branch could not be reset, "
611 612 "current branch still is: %s\n")
612 613 % util.tolocal(self.dirstate.branch()))
613 614 self.invalidate()
614 615 self.dirstate.invalidate()
615 616 else:
616 617 self.ui.warn(_("no rollback information available\n"))
617 618 finally:
618 619 del lock, wlock
619 620
620 621 def invalidate(self):
621 622 for a in "changelog manifest".split():
622 623 if a in self.__dict__:
623 624 delattr(self, a)
624 625 self.tagscache = None
625 626 self._tagstypecache = None
626 627 self.nodetagscache = None
627 628 self.branchcache = None
628 629 self._ubranchcache = None
629 630 self._branchcachetip = None
630 631
631 632 def _lock(self, lockname, wait, releasefn, acquirefn, desc):
632 633 try:
633 634 l = lock.lock(lockname, 0, releasefn, desc=desc)
634 635 except lock.LockHeld, inst:
635 636 if not wait:
636 637 raise
637 638 self.ui.warn(_("waiting for lock on %s held by %r\n") %
638 639 (desc, inst.locker))
639 640 # default to 600 seconds timeout
640 641 l = lock.lock(lockname, int(self.ui.config("ui", "timeout", "600")),
641 642 releasefn, desc=desc)
642 643 if acquirefn:
643 644 acquirefn()
644 645 return l
645 646
646 647 def lock(self, wait=True):
647 648 if self._lockref and self._lockref():
648 649 return self._lockref()
649 650
650 651 l = self._lock(self.sjoin("lock"), wait, None, self.invalidate,
651 652 _('repository %s') % self.origroot)
652 653 self._lockref = weakref.ref(l)
653 654 return l
654 655
655 656 def wlock(self, wait=True):
656 657 if self._wlockref and self._wlockref():
657 658 return self._wlockref()
658 659
659 660 l = self._lock(self.join("wlock"), wait, self.dirstate.write,
660 661 self.dirstate.invalidate, _('working directory of %s') %
661 662 self.origroot)
662 663 self._wlockref = weakref.ref(l)
663 664 return l
664 665
665 666 def filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist):
666 667 """
667 668 commit an individual file as part of a larger transaction
668 669 """
669 670
670 671 fn = fctx.path()
671 672 t = fctx.data()
672 673 fl = self.file(fn)
673 674 fp1 = manifest1.get(fn, nullid)
674 675 fp2 = manifest2.get(fn, nullid)
675 676
676 677 meta = {}
677 678 cp = fctx.renamed()
678 679 if cp and cp[0] != fn:
679 680 # Mark the new revision of this file as a copy of another
680 681 # file. This copy data will effectively act as a parent
681 682 # of this new revision. If this is a merge, the first
682 683 # parent will be the nullid (meaning "look up the copy data")
683 684 # and the second one will be the other parent. For example:
684 685 #
685 686 # 0 --- 1 --- 3 rev1 changes file foo
686 687 # \ / rev2 renames foo to bar and changes it
687 688 # \- 2 -/ rev3 should have bar with all changes and
688 689 # should record that bar descends from
689 690 # bar in rev2 and foo in rev1
690 691 #
691 692 # this allows this merge to succeed:
692 693 #
693 694 # 0 --- 1 --- 3 rev4 reverts the content change from rev2
694 695 # \ / merging rev3 and rev4 should use bar@rev2
695 696 # \- 2 --- 4 as the merge base
696 697 #
697 698
698 699 cf = cp[0]
699 700 cr = manifest1.get(cf)
700 701 nfp = fp2
701 702
702 703 if manifest2: # branch merge
703 704 if fp2 == nullid: # copied on remote side
704 705 if fp1 != nullid or cf in manifest2:
705 706 cr = manifest2[cf]
706 707 nfp = fp1
707 708
708 709 # find source in nearest ancestor if we've lost track
709 710 if not cr:
710 711 self.ui.debug(_(" %s: searching for copy revision for %s\n") %
711 712 (fn, cf))
712 713 for a in self['.'].ancestors():
713 714 if cf in a:
714 715 cr = a[cf].filenode()
715 716 break
716 717
717 718 self.ui.debug(_(" %s: copy %s:%s\n") % (fn, cf, hex(cr)))
718 719 meta["copy"] = cf
719 720 meta["copyrev"] = hex(cr)
720 721 fp1, fp2 = nullid, nfp
721 722 elif fp2 != nullid:
722 723 # is one parent an ancestor of the other?
723 724 fpa = fl.ancestor(fp1, fp2)
724 725 if fpa == fp1:
725 726 fp1, fp2 = fp2, nullid
726 727 elif fpa == fp2:
727 728 fp2 = nullid
728 729
729 730 # is the file unmodified from the parent? report existing entry
730 731 if fp2 == nullid and not fl.cmp(fp1, t) and not meta:
731 732 return fp1
732 733
733 734 changelist.append(fn)
734 735 return fl.add(t, meta, tr, linkrev, fp1, fp2)
735 736
736 737 def rawcommit(self, files, text, user, date, p1=None, p2=None, extra={}):
737 738 if p1 is None:
738 739 p1, p2 = self.dirstate.parents()
739 740 return self.commit(files=files, text=text, user=user, date=date,
740 741 p1=p1, p2=p2, extra=extra, empty_ok=True)
741 742
742 743 def commit(self, files=None, text="", user=None, date=None,
743 744 match=None, force=False, force_editor=False,
744 745 p1=None, p2=None, extra={}, empty_ok=False):
745 746 wlock = lock = None
746 747 if files:
747 748 files = util.unique(files)
748 749 try:
749 750 wlock = self.wlock()
750 751 lock = self.lock()
751 752 use_dirstate = (p1 is None) # not rawcommit
752 753
753 754 if use_dirstate:
754 755 p1, p2 = self.dirstate.parents()
755 756 update_dirstate = True
756 757
757 758 if (not force and p2 != nullid and
758 759 (match and (match.files() or match.anypats()))):
759 760 raise util.Abort(_('cannot partially commit a merge '
760 761 '(do not specify files or patterns)'))
761 762
762 763 if files:
763 764 modified, removed = [], []
764 765 for f in files:
765 766 s = self.dirstate[f]
766 767 if s in 'nma':
767 768 modified.append(f)
768 769 elif s == 'r':
769 770 removed.append(f)
770 771 else:
771 772 self.ui.warn(_("%s not tracked!\n") % f)
772 773 changes = [modified, [], removed, [], []]
773 774 else:
774 775 changes = self.status(match=match)
775 776 else:
776 777 p1, p2 = p1, p2 or nullid
777 778 update_dirstate = (self.dirstate.parents()[0] == p1)
778 779 changes = [files, [], [], [], []]
779 780
780 781 ms = merge_.mergestate(self)
781 782 for f in changes[0]:
782 783 if f in ms and ms[f] == 'u':
783 784 raise util.Abort(_("unresolved merge conflicts "
784 785 "(see hg resolve)"))
785 786 wctx = context.workingctx(self, (p1, p2), text, user, date,
786 787 extra, changes)
787 788 return self._commitctx(wctx, force, force_editor, empty_ok,
788 789 use_dirstate, update_dirstate)
789 790 finally:
790 791 del lock, wlock
791 792
792 793 def commitctx(self, ctx):
793 794 """Add a new revision to current repository.
794 795
795 796 Revision information is passed in the context.memctx argument.
796 797 commitctx() does not touch the working directory.
797 798 """
798 799 wlock = lock = None
799 800 try:
800 801 wlock = self.wlock()
801 802 lock = self.lock()
802 803 return self._commitctx(ctx, force=True, force_editor=False,
803 804 empty_ok=True, use_dirstate=False,
804 805 update_dirstate=False)
805 806 finally:
806 807 del lock, wlock
807 808
808 809 def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
809 810 use_dirstate=True, update_dirstate=True):
810 811 tr = None
811 812 valid = 0 # don't save the dirstate if this isn't set
812 813 try:
813 814 commit = util.sort(wctx.modified() + wctx.added())
814 815 remove = wctx.removed()
815 816 extra = wctx.extra().copy()
816 817 branchname = extra['branch']
817 818 user = wctx.user()
818 819 text = wctx.description()
819 820
820 821 p1, p2 = [p.node() for p in wctx.parents()]
821 822 c1 = self.changelog.read(p1)
822 823 c2 = self.changelog.read(p2)
823 824 m1 = self.manifest.read(c1[0]).copy()
824 825 m2 = self.manifest.read(c2[0])
825 826
826 827 if use_dirstate:
827 828 oldname = c1[5].get("branch") # stored in UTF-8
828 829 if (not commit and not remove and not force and p2 == nullid
829 830 and branchname == oldname):
830 831 self.ui.status(_("nothing changed\n"))
831 832 return None
832 833
833 834 xp1 = hex(p1)
834 835 if p2 == nullid: xp2 = ''
835 836 else: xp2 = hex(p2)
836 837
837 838 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
838 839
839 840 tr = self.transaction()
840 841 trp = weakref.proxy(tr)
841 842
842 843 # check in files
843 844 new = {}
844 845 changed = []
845 846 linkrev = len(self)
846 847 for f in commit:
847 848 self.ui.note(f + "\n")
848 849 try:
849 850 fctx = wctx.filectx(f)
850 851 newflags = fctx.flags()
851 852 new[f] = self.filecommit(fctx, m1, m2, linkrev, trp, changed)
852 853 if ((not changed or changed[-1] != f) and
853 854 m2.get(f) != new[f]):
854 855 # mention the file in the changelog if some
855 856 # flag changed, even if there was no content
856 857 # change.
857 858 if m1.flags(f) != newflags:
858 859 changed.append(f)
859 860 m1.set(f, newflags)
860 861 if use_dirstate:
861 862 self.dirstate.normal(f)
862 863
863 864 except (OSError, IOError):
864 865 if use_dirstate:
865 866 self.ui.warn(_("trouble committing %s!\n") % f)
866 867 raise
867 868 else:
868 869 remove.append(f)
869 870
870 871 updated, added = [], []
871 872 for f in util.sort(changed):
872 873 if f in m1 or f in m2:
873 874 updated.append(f)
874 875 else:
875 876 added.append(f)
876 877
877 878 # update manifest
878 879 m1.update(new)
879 880 removed = []
880 881
881 882 for f in util.sort(remove):
882 883 if f in m1:
883 884 del m1[f]
884 885 removed.append(f)
885 886 elif f in m2:
886 887 removed.append(f)
887 888 mn = self.manifest.add(m1, trp, linkrev, c1[0], c2[0],
888 889 (new, removed))
889 890
890 891 # add changeset
891 892 if (not empty_ok and not text) or force_editor:
892 893 edittext = []
893 894 if text:
894 895 edittext.append(text)
895 896 edittext.append("")
896 897 edittext.append("") # Empty line between message and comments.
897 898 edittext.append(_("HG: Enter commit message."
898 899 " Lines beginning with 'HG:' are removed."))
899 900 edittext.append("HG: --")
900 901 edittext.append("HG: user: %s" % user)
901 902 if p2 != nullid:
902 903 edittext.append("HG: branch merge")
903 904 if branchname:
904 905 edittext.append("HG: branch '%s'" % util.tolocal(branchname))
905 906 edittext.extend(["HG: added %s" % f for f in added])
906 907 edittext.extend(["HG: changed %s" % f for f in updated])
907 908 edittext.extend(["HG: removed %s" % f for f in removed])
908 909 if not added and not updated and not removed:
909 910 edittext.append("HG: no files changed")
910 911 edittext.append("")
911 912 # run editor in the repository root
912 913 olddir = os.getcwd()
913 914 os.chdir(self.root)
914 915 text = self.ui.edit("\n".join(edittext), user)
915 916 os.chdir(olddir)
916 917
917 918 lines = [line.rstrip() for line in text.rstrip().splitlines()]
918 919 while lines and not lines[0]:
919 920 del lines[0]
920 921 if not lines and use_dirstate:
921 922 raise util.Abort(_("empty commit message"))
922 923 text = '\n'.join(lines)
923 924
924 925 n = self.changelog.add(mn, changed + removed, text, trp, p1, p2,
925 926 user, wctx.date(), extra)
926 927 self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
927 928 parent2=xp2)
928 929 tr.close()
929 930
930 931 if self.branchcache:
931 932 self.branchtags()
932 933
933 934 if use_dirstate or update_dirstate:
934 935 self.dirstate.setparents(n)
935 936 if use_dirstate:
936 937 for f in removed:
937 938 self.dirstate.forget(f)
938 939 valid = 1 # our dirstate updates are complete
939 940
940 941 self.hook("commit", node=hex(n), parent1=xp1, parent2=xp2)
941 942 return n
942 943 finally:
943 944 if not valid: # don't save our updated dirstate
944 945 self.dirstate.invalidate()
945 946 del tr
946 947
947 948 def walk(self, match, node=None):
948 949 '''
949 950 walk recursively through the directory tree or a given
950 951 changeset, finding all files matched by the match
951 952 function
952 953 '''
953 954 return self[node].walk(match)
954 955
955 956 def status(self, node1='.', node2=None, match=None,
956 957 ignored=False, clean=False, unknown=False):
957 958 """return status of files between two nodes or node and working directory
958 959
959 960 If node1 is None, use the first dirstate parent instead.
960 961 If node2 is None, compare node1 with working directory.
961 962 """
962 963
963 964 def mfmatches(ctx):
964 965 mf = ctx.manifest().copy()
965 966 for fn in mf.keys():
966 967 if not match(fn):
967 968 del mf[fn]
968 969 return mf
969 970
970 971 if isinstance(node1, context.changectx):
971 972 ctx1 = node1
972 973 else:
973 974 ctx1 = self[node1]
974 975 if isinstance(node2, context.changectx):
975 976 ctx2 = node2
976 977 else:
977 978 ctx2 = self[node2]
978 979
979 980 working = ctx2 == self[None]
980 981 parentworking = working and ctx1 == self['.']
981 982 match = match or match_.always(self.root, self.getcwd())
982 983 listignored, listclean, listunknown = ignored, clean, unknown
983 984
984 985 # load earliest manifest first for caching reasons
985 986 if not working and ctx2.rev() < ctx1.rev():
986 987 ctx2.manifest()
987 988
988 989 if not parentworking:
989 990 def bad(f, msg):
990 991 if f not in ctx1:
991 992 self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg))
992 993 return False
993 994 match.bad = bad
994 995
995 996 if working: # we need to scan the working dir
996 997 s = self.dirstate.status(match, listignored, listclean, listunknown)
997 998 cmp, modified, added, removed, deleted, unknown, ignored, clean = s
998 999
999 1000 # check for any possibly clean files
1000 1001 if parentworking and cmp:
1001 1002 fixup = []
1002 1003 # do a full compare of any files that might have changed
1003 1004 for f in cmp:
1004 1005 if (f not in ctx1 or ctx2.flags(f) != ctx1.flags(f)
1005 1006 or ctx1[f].cmp(ctx2[f].data())):
1006 1007 modified.append(f)
1007 1008 else:
1008 1009 fixup.append(f)
1009 1010
1010 1011 if listclean:
1011 1012 clean += fixup
1012 1013
1013 1014 # update dirstate for files that are actually clean
1014 1015 if fixup:
1015 1016 wlock = None
1016 1017 try:
1017 1018 try:
1018 1019 wlock = self.wlock(False)
1019 1020 for f in fixup:
1020 1021 self.dirstate.normal(f)
1021 1022 except lock.LockException:
1022 1023 pass
1023 1024 finally:
1024 1025 del wlock
1025 1026
1026 1027 if not parentworking:
1027 1028 mf1 = mfmatches(ctx1)
1028 1029 if working:
1029 1030 # we are comparing working dir against non-parent
1030 1031 # generate a pseudo-manifest for the working dir
1031 1032 mf2 = mfmatches(self['.'])
1032 1033 for f in cmp + modified + added:
1033 1034 mf2[f] = None
1034 1035 mf2.set(f, ctx2.flags(f))
1035 1036 for f in removed:
1036 1037 if f in mf2:
1037 1038 del mf2[f]
1038 1039 else:
1039 1040 # we are comparing two revisions
1040 1041 deleted, unknown, ignored = [], [], []
1041 1042 mf2 = mfmatches(ctx2)
1042 1043
1043 1044 modified, added, clean = [], [], []
1044 1045 for fn in mf2:
1045 1046 if fn in mf1:
1046 1047 if (mf1.flags(fn) != mf2.flags(fn) or
1047 1048 (mf1[fn] != mf2[fn] and
1048 1049 (mf2[fn] or ctx1[fn].cmp(ctx2[fn].data())))):
1049 1050 modified.append(fn)
1050 1051 elif listclean:
1051 1052 clean.append(fn)
1052 1053 del mf1[fn]
1053 1054 else:
1054 1055 added.append(fn)
1055 1056 removed = mf1.keys()
1056 1057
1057 1058 r = modified, added, removed, deleted, unknown, ignored, clean
1058 1059 [l.sort() for l in r]
1059 1060 return r
1060 1061
1061 1062 def add(self, list):
1062 1063 wlock = self.wlock()
1063 1064 try:
1064 1065 rejected = []
1065 1066 for f in list:
1066 1067 p = self.wjoin(f)
1067 1068 try:
1068 1069 st = os.lstat(p)
1069 1070 except:
1070 1071 self.ui.warn(_("%s does not exist!\n") % f)
1071 1072 rejected.append(f)
1072 1073 continue
1073 1074 if st.st_size > 10000000:
1074 1075 self.ui.warn(_("%s: files over 10MB may cause memory and"
1075 1076 " performance problems\n"
1076 1077 "(use 'hg revert %s' to unadd the file)\n")
1077 1078 % (f, f))
1078 1079 if not (stat.S_ISREG(st.st_mode) or stat.S_ISLNK(st.st_mode)):
1079 1080 self.ui.warn(_("%s not added: only files and symlinks "
1080 1081 "supported currently\n") % f)
1081 1082 rejected.append(p)
1082 1083 elif self.dirstate[f] in 'amn':
1083 1084 self.ui.warn(_("%s already tracked!\n") % f)
1084 1085 elif self.dirstate[f] == 'r':
1085 1086 self.dirstate.normallookup(f)
1086 1087 else:
1087 1088 self.dirstate.add(f)
1088 1089 return rejected
1089 1090 finally:
1090 1091 del wlock
1091 1092
1092 1093 def forget(self, list):
1093 1094 wlock = self.wlock()
1094 1095 try:
1095 1096 for f in list:
1096 1097 if self.dirstate[f] != 'a':
1097 1098 self.ui.warn(_("%s not added!\n") % f)
1098 1099 else:
1099 1100 self.dirstate.forget(f)
1100 1101 finally:
1101 1102 del wlock
1102 1103
1103 1104 def remove(self, list, unlink=False):
1104 1105 wlock = None
1105 1106 try:
1106 1107 if unlink:
1107 1108 for f in list:
1108 1109 try:
1109 1110 util.unlink(self.wjoin(f))
1110 1111 except OSError, inst:
1111 1112 if inst.errno != errno.ENOENT:
1112 1113 raise
1113 1114 wlock = self.wlock()
1114 1115 for f in list:
1115 1116 if unlink and os.path.exists(self.wjoin(f)):
1116 1117 self.ui.warn(_("%s still exists!\n") % f)
1117 1118 elif self.dirstate[f] == 'a':
1118 1119 self.dirstate.forget(f)
1119 1120 elif f not in self.dirstate:
1120 1121 self.ui.warn(_("%s not tracked!\n") % f)
1121 1122 else:
1122 1123 self.dirstate.remove(f)
1123 1124 finally:
1124 1125 del wlock
1125 1126
1126 1127 def undelete(self, list):
1127 1128 wlock = None
1128 1129 try:
1129 1130 manifests = [self.manifest.read(self.changelog.read(p)[0])
1130 1131 for p in self.dirstate.parents() if p != nullid]
1131 1132 wlock = self.wlock()
1132 1133 for f in list:
1133 1134 if self.dirstate[f] != 'r':
1134 1135 self.ui.warn(_("%s not removed!\n") % f)
1135 1136 else:
1136 1137 m = f in manifests[0] and manifests[0] or manifests[1]
1137 1138 t = self.file(f).read(m[f])
1138 1139 self.wwrite(f, t, m.flags(f))
1139 1140 self.dirstate.normal(f)
1140 1141 finally:
1141 1142 del wlock
1142 1143
1143 1144 def copy(self, source, dest):
1144 1145 wlock = None
1145 1146 try:
1146 1147 p = self.wjoin(dest)
1147 1148 if not (os.path.exists(p) or os.path.islink(p)):
1148 1149 self.ui.warn(_("%s does not exist!\n") % dest)
1149 1150 elif not (os.path.isfile(p) or os.path.islink(p)):
1150 1151 self.ui.warn(_("copy failed: %s is not a file or a "
1151 1152 "symbolic link\n") % dest)
1152 1153 else:
1153 1154 wlock = self.wlock()
1154 1155 if self.dirstate[dest] in '?r':
1155 1156 self.dirstate.add(dest)
1156 1157 self.dirstate.copy(source, dest)
1157 1158 finally:
1158 1159 del wlock
1159 1160
1160 1161 def heads(self, start=None):
1161 1162 heads = self.changelog.heads(start)
1162 1163 # sort the output in rev descending order
1163 1164 heads = [(-self.changelog.rev(h), h) for h in heads]
1164 1165 return [n for (r, n) in util.sort(heads)]
1165 1166
1166 1167 def branchheads(self, branch=None, start=None):
1167 1168 if branch is None:
1168 1169 branch = self[None].branch()
1169 1170 branches = self.branchtags()
1170 1171 if branch not in branches:
1171 1172 return []
1172 1173 # The basic algorithm is this:
1173 1174 #
1174 1175 # Start from the branch tip since there are no later revisions that can
1175 1176 # possibly be in this branch, and the tip is a guaranteed head.
1176 1177 #
1177 1178 # Remember the tip's parents as the first ancestors, since these by
1178 1179 # definition are not heads.
1179 1180 #
1180 1181 # Step backwards from the brach tip through all the revisions. We are
1181 1182 # guaranteed by the rules of Mercurial that we will now be visiting the
1182 1183 # nodes in reverse topological order (children before parents).
1183 1184 #
1184 1185 # If a revision is one of the ancestors of a head then we can toss it
1185 1186 # out of the ancestors set (we've already found it and won't be
1186 1187 # visiting it again) and put its parents in the ancestors set.
1187 1188 #
1188 1189 # Otherwise, if a revision is in the branch it's another head, since it
1189 1190 # wasn't in the ancestor list of an existing head. So add it to the
1190 1191 # head list, and add its parents to the ancestor list.
1191 1192 #
1192 1193 # If it is not in the branch ignore it.
1193 1194 #
1194 1195 # Once we have a list of heads, use nodesbetween to filter out all the
1195 1196 # heads that cannot be reached from startrev. There may be a more
1196 1197 # efficient way to do this as part of the previous algorithm.
1197 1198
1198 1199 set = util.set
1199 1200 heads = [self.changelog.rev(branches[branch])]
1200 1201 # Don't care if ancestors contains nullrev or not.
1201 1202 ancestors = set(self.changelog.parentrevs(heads[0]))
1202 1203 for rev in xrange(heads[0] - 1, nullrev, -1):
1203 1204 if rev in ancestors:
1204 1205 ancestors.update(self.changelog.parentrevs(rev))
1205 1206 ancestors.remove(rev)
1206 1207 elif self[rev].branch() == branch:
1207 1208 heads.append(rev)
1208 1209 ancestors.update(self.changelog.parentrevs(rev))
1209 1210 heads = [self.changelog.node(rev) for rev in heads]
1210 1211 if start is not None:
1211 1212 heads = self.changelog.nodesbetween([start], heads)[2]
1212 1213 return heads
1213 1214
1214 1215 def branches(self, nodes):
1215 1216 if not nodes:
1216 1217 nodes = [self.changelog.tip()]
1217 1218 b = []
1218 1219 for n in nodes:
1219 1220 t = n
1220 1221 while 1:
1221 1222 p = self.changelog.parents(n)
1222 1223 if p[1] != nullid or p[0] == nullid:
1223 1224 b.append((t, n, p[0], p[1]))
1224 1225 break
1225 1226 n = p[0]
1226 1227 return b
1227 1228
1228 1229 def between(self, pairs):
1229 1230 r = []
1230 1231
1231 1232 for top, bottom in pairs:
1232 1233 n, l, i = top, [], 0
1233 1234 f = 1
1234 1235
1235 1236 while n != bottom:
1236 1237 p = self.changelog.parents(n)[0]
1237 1238 if i == f:
1238 1239 l.append(n)
1239 1240 f = f * 2
1240 1241 n = p
1241 1242 i += 1
1242 1243
1243 1244 r.append(l)
1244 1245
1245 1246 return r
1246 1247
1247 1248 def findincoming(self, remote, base=None, heads=None, force=False):
1248 1249 """Return list of roots of the subsets of missing nodes from remote
1249 1250
1250 1251 If base dict is specified, assume that these nodes and their parents
1251 1252 exist on the remote side and that no child of a node of base exists
1252 1253 in both remote and self.
1253 1254 Furthermore base will be updated to include the nodes that exists
1254 1255 in self and remote but no children exists in self and remote.
1255 1256 If a list of heads is specified, return only nodes which are heads
1256 1257 or ancestors of these heads.
1257 1258
1258 1259 All the ancestors of base are in self and in remote.
1259 1260 All the descendants of the list returned are missing in self.
1260 1261 (and so we know that the rest of the nodes are missing in remote, see
1261 1262 outgoing)
1262 1263 """
1263 1264 m = self.changelog.nodemap
1264 1265 search = []
1265 1266 fetch = {}
1266 1267 seen = {}
1267 1268 seenbranch = {}
1268 1269 if base == None:
1269 1270 base = {}
1270 1271
1271 1272 if not heads:
1272 1273 heads = remote.heads()
1273 1274
1274 1275 if self.changelog.tip() == nullid:
1275 1276 base[nullid] = 1
1276 1277 if heads != [nullid]:
1277 1278 return [nullid]
1278 1279 return []
1279 1280
1280 1281 # assume we're closer to the tip than the root
1281 1282 # and start by examining the heads
1282 1283 self.ui.status(_("searching for changes\n"))
1283 1284
1284 1285 unknown = []
1285 1286 for h in heads:
1286 1287 if h not in m:
1287 1288 unknown.append(h)
1288 1289 else:
1289 1290 base[h] = 1
1290 1291
1291 1292 if not unknown:
1292 1293 return []
1293 1294
1294 1295 req = dict.fromkeys(unknown)
1295 1296 reqcnt = 0
1296 1297
1297 1298 # search through remote branches
1298 1299 # a 'branch' here is a linear segment of history, with four parts:
1299 1300 # head, root, first parent, second parent
1300 1301 # (a branch always has two parents (or none) by definition)
1301 1302 unknown = remote.branches(unknown)
1302 1303 while unknown:
1303 1304 r = []
1304 1305 while unknown:
1305 1306 n = unknown.pop(0)
1306 1307 if n[0] in seen:
1307 1308 continue
1308 1309
1309 1310 self.ui.debug(_("examining %s:%s\n")
1310 1311 % (short(n[0]), short(n[1])))
1311 1312 if n[0] == nullid: # found the end of the branch
1312 1313 pass
1313 1314 elif n in seenbranch:
1314 1315 self.ui.debug(_("branch already found\n"))
1315 1316 continue
1316 1317 elif n[1] and n[1] in m: # do we know the base?
1317 1318 self.ui.debug(_("found incomplete branch %s:%s\n")
1318 1319 % (short(n[0]), short(n[1])))
1319 1320 search.append(n) # schedule branch range for scanning
1320 1321 seenbranch[n] = 1
1321 1322 else:
1322 1323 if n[1] not in seen and n[1] not in fetch:
1323 1324 if n[2] in m and n[3] in m:
1324 1325 self.ui.debug(_("found new changeset %s\n") %
1325 1326 short(n[1]))
1326 1327 fetch[n[1]] = 1 # earliest unknown
1327 1328 for p in n[2:4]:
1328 1329 if p in m:
1329 1330 base[p] = 1 # latest known
1330 1331
1331 1332 for p in n[2:4]:
1332 1333 if p not in req and p not in m:
1333 1334 r.append(p)
1334 1335 req[p] = 1
1335 1336 seen[n[0]] = 1
1336 1337
1337 1338 if r:
1338 1339 reqcnt += 1
1339 1340 self.ui.debug(_("request %d: %s\n") %
1340 1341 (reqcnt, " ".join(map(short, r))))
1341 1342 for p in xrange(0, len(r), 10):
1342 1343 for b in remote.branches(r[p:p+10]):
1343 1344 self.ui.debug(_("received %s:%s\n") %
1344 1345 (short(b[0]), short(b[1])))
1345 1346 unknown.append(b)
1346 1347
1347 1348 # do binary search on the branches we found
1348 1349 search = [(t, b) for (t, b, p1, p2) in search]
1349 1350 while search:
1350 1351 newsearch = []
1351 1352 reqcnt += 1
1352 1353 for n, l in zip(search, remote.between(search)):
1353 1354 l.append(n[1])
1354 1355 p = n[0]
1355 1356 f = 1
1356 1357 for i in l:
1357 1358 self.ui.debug(_("narrowing %d:%d %s\n") % (f, len(l), short(i)))
1358 1359 if i in m:
1359 1360 if f <= 2:
1360 1361 self.ui.debug(_("found new branch changeset %s\n") %
1361 1362 short(p))
1362 1363 fetch[p] = 1
1363 1364 base[i] = 1
1364 1365 else:
1365 1366 self.ui.debug(_("narrowed branch search to %s:%s\n")
1366 1367 % (short(p), short(i)))
1367 1368 newsearch.append((p, i))
1368 1369 break
1369 1370 p, f = i, f * 2
1370 1371 search = newsearch
1371 1372
1372 1373 # sanity check our fetch list
1373 1374 for f in fetch.keys():
1374 1375 if f in m:
1375 1376 raise repo.RepoError(_("already have changeset ") + short(f[:4]))
1376 1377
1377 1378 if base.keys() == [nullid]:
1378 1379 if force:
1379 1380 self.ui.warn(_("warning: repository is unrelated\n"))
1380 1381 else:
1381 1382 raise util.Abort(_("repository is unrelated"))
1382 1383
1383 1384 self.ui.debug(_("found new changesets starting at ") +
1384 1385 " ".join([short(f) for f in fetch]) + "\n")
1385 1386
1386 1387 self.ui.debug(_("%d total queries\n") % reqcnt)
1387 1388
1388 1389 return fetch.keys()
1389 1390
1390 1391 def findoutgoing(self, remote, base=None, heads=None, force=False):
1391 1392 """Return list of nodes that are roots of subsets not in remote
1392 1393
1393 1394 If base dict is specified, assume that these nodes and their parents
1394 1395 exist on the remote side.
1395 1396 If a list of heads is specified, return only nodes which are heads
1396 1397 or ancestors of these heads, and return a second element which
1397 1398 contains all remote heads which get new children.
1398 1399 """
1399 1400 if base == None:
1400 1401 base = {}
1401 1402 self.findincoming(remote, base, heads, force=force)
1402 1403
1403 1404 self.ui.debug(_("common changesets up to ")
1404 1405 + " ".join(map(short, base.keys())) + "\n")
1405 1406
1406 1407 remain = dict.fromkeys(self.changelog.nodemap)
1407 1408
1408 1409 # prune everything remote has from the tree
1409 1410 del remain[nullid]
1410 1411 remove = base.keys()
1411 1412 while remove:
1412 1413 n = remove.pop(0)
1413 1414 if n in remain:
1414 1415 del remain[n]
1415 1416 for p in self.changelog.parents(n):
1416 1417 remove.append(p)
1417 1418
1418 1419 # find every node whose parents have been pruned
1419 1420 subset = []
1420 1421 # find every remote head that will get new children
1421 1422 updated_heads = {}
1422 1423 for n in remain:
1423 1424 p1, p2 = self.changelog.parents(n)
1424 1425 if p1 not in remain and p2 not in remain:
1425 1426 subset.append(n)
1426 1427 if heads:
1427 1428 if p1 in heads:
1428 1429 updated_heads[p1] = True
1429 1430 if p2 in heads:
1430 1431 updated_heads[p2] = True
1431 1432
1432 1433 # this is the set of all roots we have to push
1433 1434 if heads:
1434 1435 return subset, updated_heads.keys()
1435 1436 else:
1436 1437 return subset
1437 1438
1438 1439 def pull(self, remote, heads=None, force=False):
1439 1440 lock = self.lock()
1440 1441 try:
1441 1442 fetch = self.findincoming(remote, heads=heads, force=force)
1442 1443 if fetch == [nullid]:
1443 1444 self.ui.status(_("requesting all changes\n"))
1444 1445
1445 1446 if not fetch:
1446 1447 self.ui.status(_("no changes found\n"))
1447 1448 return 0
1448 1449
1449 1450 if heads is None:
1450 1451 cg = remote.changegroup(fetch, 'pull')
1451 1452 else:
1452 1453 if 'changegroupsubset' not in remote.capabilities:
1453 1454 raise util.Abort(_("Partial pull cannot be done because other repository doesn't support changegroupsubset."))
1454 1455 cg = remote.changegroupsubset(fetch, heads, 'pull')
1455 1456 return self.addchangegroup(cg, 'pull', remote.url())
1456 1457 finally:
1457 1458 del lock
1458 1459
1459 1460 def push(self, remote, force=False, revs=None):
1460 1461 # there are two ways to push to remote repo:
1461 1462 #
1462 1463 # addchangegroup assumes local user can lock remote
1463 1464 # repo (local filesystem, old ssh servers).
1464 1465 #
1465 1466 # unbundle assumes local user cannot lock remote repo (new ssh
1466 1467 # servers, http servers).
1467 1468
1468 1469 if remote.capable('unbundle'):
1469 1470 return self.push_unbundle(remote, force, revs)
1470 1471 return self.push_addchangegroup(remote, force, revs)
1471 1472
1472 1473 def prepush(self, remote, force, revs):
1473 1474 base = {}
1474 1475 remote_heads = remote.heads()
1475 1476 inc = self.findincoming(remote, base, remote_heads, force=force)
1476 1477
1477 1478 update, updated_heads = self.findoutgoing(remote, base, remote_heads)
1478 1479 if revs is not None:
1479 1480 msng_cl, bases, heads = self.changelog.nodesbetween(update, revs)
1480 1481 else:
1481 1482 bases, heads = update, self.changelog.heads()
1482 1483
1483 1484 if not bases:
1484 1485 self.ui.status(_("no changes found\n"))
1485 1486 return None, 1
1486 1487 elif not force:
1487 1488 # check if we're creating new remote heads
1488 1489 # to be a remote head after push, node must be either
1489 1490 # - unknown locally
1490 1491 # - a local outgoing head descended from update
1491 1492 # - a remote head that's known locally and not
1492 1493 # ancestral to an outgoing head
1493 1494
1494 1495 warn = 0
1495 1496
1496 1497 if remote_heads == [nullid]:
1497 1498 warn = 0
1498 1499 elif not revs and len(heads) > len(remote_heads):
1499 1500 warn = 1
1500 1501 else:
1501 1502 newheads = list(heads)
1502 1503 for r in remote_heads:
1503 1504 if r in self.changelog.nodemap:
1504 1505 desc = self.changelog.heads(r, heads)
1505 1506 l = [h for h in heads if h in desc]
1506 1507 if not l:
1507 1508 newheads.append(r)
1508 1509 else:
1509 1510 newheads.append(r)
1510 1511 if len(newheads) > len(remote_heads):
1511 1512 warn = 1
1512 1513
1513 1514 if warn:
1514 1515 self.ui.warn(_("abort: push creates new remote heads!\n"))
1515 1516 self.ui.status(_("(did you forget to merge?"
1516 1517 " use push -f to force)\n"))
1517 1518 return None, 0
1518 1519 elif inc:
1519 1520 self.ui.warn(_("note: unsynced remote changes!\n"))
1520 1521
1521 1522
1522 1523 if revs is None:
1523 1524 cg = self.changegroup(update, 'push')
1524 1525 else:
1525 1526 cg = self.changegroupsubset(update, revs, 'push')
1526 1527 return cg, remote_heads
1527 1528
1528 1529 def push_addchangegroup(self, remote, force, revs):
1529 1530 lock = remote.lock()
1530 1531 try:
1531 1532 ret = self.prepush(remote, force, revs)
1532 1533 if ret[0] is not None:
1533 1534 cg, remote_heads = ret
1534 1535 return remote.addchangegroup(cg, 'push', self.url())
1535 1536 return ret[1]
1536 1537 finally:
1537 1538 del lock
1538 1539
1539 1540 def push_unbundle(self, remote, force, revs):
1540 1541 # local repo finds heads on server, finds out what revs it
1541 1542 # must push. once revs transferred, if server finds it has
1542 1543 # different heads (someone else won commit/push race), server
1543 1544 # aborts.
1544 1545
1545 1546 ret = self.prepush(remote, force, revs)
1546 1547 if ret[0] is not None:
1547 1548 cg, remote_heads = ret
1548 1549 if force: remote_heads = ['force']
1549 1550 return remote.unbundle(cg, remote_heads, 'push')
1550 1551 return ret[1]
1551 1552
1552 1553 def changegroupinfo(self, nodes, source):
1553 1554 if self.ui.verbose or source == 'bundle':
1554 1555 self.ui.status(_("%d changesets found\n") % len(nodes))
1555 1556 if self.ui.debugflag:
1556 1557 self.ui.debug(_("List of changesets:\n"))
1557 1558 for node in nodes:
1558 1559 self.ui.debug("%s\n" % hex(node))
1559 1560
1560 1561 def changegroupsubset(self, bases, heads, source, extranodes=None):
1561 1562 """This function generates a changegroup consisting of all the nodes
1562 1563 that are descendents of any of the bases, and ancestors of any of
1563 1564 the heads.
1564 1565
1565 1566 It is fairly complex as determining which filenodes and which
1566 1567 manifest nodes need to be included for the changeset to be complete
1567 1568 is non-trivial.
1568 1569
1569 1570 Another wrinkle is doing the reverse, figuring out which changeset in
1570 1571 the changegroup a particular filenode or manifestnode belongs to.
1571 1572
1572 1573 The caller can specify some nodes that must be included in the
1573 1574 changegroup using the extranodes argument. It should be a dict
1574 1575 where the keys are the filenames (or 1 for the manifest), and the
1575 1576 values are lists of (node, linknode) tuples, where node is a wanted
1576 1577 node and linknode is the changelog node that should be transmitted as
1577 1578 the linkrev.
1578 1579 """
1579 1580
1580 1581 self.hook('preoutgoing', throw=True, source=source)
1581 1582
1582 1583 # Set up some initial variables
1583 1584 # Make it easy to refer to self.changelog
1584 1585 cl = self.changelog
1585 1586 # msng is short for missing - compute the list of changesets in this
1586 1587 # changegroup.
1587 1588 msng_cl_lst, bases, heads = cl.nodesbetween(bases, heads)
1588 1589 self.changegroupinfo(msng_cl_lst, source)
1589 1590 # Some bases may turn out to be superfluous, and some heads may be
1590 1591 # too. nodesbetween will return the minimal set of bases and heads
1591 1592 # necessary to re-create the changegroup.
1592 1593
1593 1594 # Known heads are the list of heads that it is assumed the recipient
1594 1595 # of this changegroup will know about.
1595 1596 knownheads = {}
1596 1597 # We assume that all parents of bases are known heads.
1597 1598 for n in bases:
1598 1599 for p in cl.parents(n):
1599 1600 if p != nullid:
1600 1601 knownheads[p] = 1
1601 1602 knownheads = knownheads.keys()
1602 1603 if knownheads:
1603 1604 # Now that we know what heads are known, we can compute which
1604 1605 # changesets are known. The recipient must know about all
1605 1606 # changesets required to reach the known heads from the null
1606 1607 # changeset.
1607 1608 has_cl_set, junk, junk = cl.nodesbetween(None, knownheads)
1608 1609 junk = None
1609 1610 # Transform the list into an ersatz set.
1610 1611 has_cl_set = dict.fromkeys(has_cl_set)
1611 1612 else:
1612 1613 # If there were no known heads, the recipient cannot be assumed to
1613 1614 # know about any changesets.
1614 1615 has_cl_set = {}
1615 1616
1616 1617 # Make it easy to refer to self.manifest
1617 1618 mnfst = self.manifest
1618 1619 # We don't know which manifests are missing yet
1619 1620 msng_mnfst_set = {}
1620 1621 # Nor do we know which filenodes are missing.
1621 1622 msng_filenode_set = {}
1622 1623
1623 1624 junk = mnfst.index[len(mnfst) - 1] # Get around a bug in lazyindex
1624 1625 junk = None
1625 1626
1626 1627 # A changeset always belongs to itself, so the changenode lookup
1627 1628 # function for a changenode is identity.
1628 1629 def identity(x):
1629 1630 return x
1630 1631
1631 1632 # A function generating function. Sets up an environment for the
1632 1633 # inner function.
1633 1634 def cmp_by_rev_func(revlog):
1634 1635 # Compare two nodes by their revision number in the environment's
1635 1636 # revision history. Since the revision number both represents the
1636 1637 # most efficient order to read the nodes in, and represents a
1637 1638 # topological sorting of the nodes, this function is often useful.
1638 1639 def cmp_by_rev(a, b):
1639 1640 return cmp(revlog.rev(a), revlog.rev(b))
1640 1641 return cmp_by_rev
1641 1642
1642 1643 # If we determine that a particular file or manifest node must be a
1643 1644 # node that the recipient of the changegroup will already have, we can
1644 1645 # also assume the recipient will have all the parents. This function
1645 1646 # prunes them from the set of missing nodes.
1646 1647 def prune_parents(revlog, hasset, msngset):
1647 1648 haslst = hasset.keys()
1648 1649 haslst.sort(cmp_by_rev_func(revlog))
1649 1650 for node in haslst:
1650 1651 parentlst = [p for p in revlog.parents(node) if p != nullid]
1651 1652 while parentlst:
1652 1653 n = parentlst.pop()
1653 1654 if n not in hasset:
1654 1655 hasset[n] = 1
1655 1656 p = [p for p in revlog.parents(n) if p != nullid]
1656 1657 parentlst.extend(p)
1657 1658 for n in hasset:
1658 1659 msngset.pop(n, None)
1659 1660
1660 1661 # This is a function generating function used to set up an environment
1661 1662 # for the inner function to execute in.
1662 1663 def manifest_and_file_collector(changedfileset):
1663 1664 # This is an information gathering function that gathers
1664 1665 # information from each changeset node that goes out as part of
1665 1666 # the changegroup. The information gathered is a list of which
1666 1667 # manifest nodes are potentially required (the recipient may
1667 1668 # already have them) and total list of all files which were
1668 1669 # changed in any changeset in the changegroup.
1669 1670 #
1670 1671 # We also remember the first changenode we saw any manifest
1671 1672 # referenced by so we can later determine which changenode 'owns'
1672 1673 # the manifest.
1673 1674 def collect_manifests_and_files(clnode):
1674 1675 c = cl.read(clnode)
1675 1676 for f in c[3]:
1676 1677 # This is to make sure we only have one instance of each
1677 1678 # filename string for each filename.
1678 1679 changedfileset.setdefault(f, f)
1679 1680 msng_mnfst_set.setdefault(c[0], clnode)
1680 1681 return collect_manifests_and_files
1681 1682
1682 1683 # Figure out which manifest nodes (of the ones we think might be part
1683 1684 # of the changegroup) the recipient must know about and remove them
1684 1685 # from the changegroup.
1685 1686 def prune_manifests():
1686 1687 has_mnfst_set = {}
1687 1688 for n in msng_mnfst_set:
1688 1689 # If a 'missing' manifest thinks it belongs to a changenode
1689 1690 # the recipient is assumed to have, obviously the recipient
1690 1691 # must have that manifest.
1691 1692 linknode = cl.node(mnfst.linkrev(n))
1692 1693 if linknode in has_cl_set:
1693 1694 has_mnfst_set[n] = 1
1694 1695 prune_parents(mnfst, has_mnfst_set, msng_mnfst_set)
1695 1696
1696 1697 # Use the information collected in collect_manifests_and_files to say
1697 1698 # which changenode any manifestnode belongs to.
1698 1699 def lookup_manifest_link(mnfstnode):
1699 1700 return msng_mnfst_set[mnfstnode]
1700 1701
1701 1702 # A function generating function that sets up the initial environment
1702 1703 # the inner function.
1703 1704 def filenode_collector(changedfiles):
1704 1705 next_rev = [0]
1705 1706 # This gathers information from each manifestnode included in the
1706 1707 # changegroup about which filenodes the manifest node references
1707 1708 # so we can include those in the changegroup too.
1708 1709 #
1709 1710 # It also remembers which changenode each filenode belongs to. It
1710 1711 # does this by assuming the a filenode belongs to the changenode
1711 1712 # the first manifest that references it belongs to.
1712 1713 def collect_msng_filenodes(mnfstnode):
1713 1714 r = mnfst.rev(mnfstnode)
1714 1715 if r == next_rev[0]:
1715 1716 # If the last rev we looked at was the one just previous,
1716 1717 # we only need to see a diff.
1717 1718 deltamf = mnfst.readdelta(mnfstnode)
1718 1719 # For each line in the delta
1719 1720 for f, fnode in deltamf.items():
1720 1721 f = changedfiles.get(f, None)
1721 1722 # And if the file is in the list of files we care
1722 1723 # about.
1723 1724 if f is not None:
1724 1725 # Get the changenode this manifest belongs to
1725 1726 clnode = msng_mnfst_set[mnfstnode]
1726 1727 # Create the set of filenodes for the file if
1727 1728 # there isn't one already.
1728 1729 ndset = msng_filenode_set.setdefault(f, {})
1729 1730 # And set the filenode's changelog node to the
1730 1731 # manifest's if it hasn't been set already.
1731 1732 ndset.setdefault(fnode, clnode)
1732 1733 else:
1733 1734 # Otherwise we need a full manifest.
1734 1735 m = mnfst.read(mnfstnode)
1735 1736 # For every file in we care about.
1736 1737 for f in changedfiles:
1737 1738 fnode = m.get(f, None)
1738 1739 # If it's in the manifest
1739 1740 if fnode is not None:
1740 1741 # See comments above.
1741 1742 clnode = msng_mnfst_set[mnfstnode]
1742 1743 ndset = msng_filenode_set.setdefault(f, {})
1743 1744 ndset.setdefault(fnode, clnode)
1744 1745 # Remember the revision we hope to see next.
1745 1746 next_rev[0] = r + 1
1746 1747 return collect_msng_filenodes
1747 1748
1748 1749 # We have a list of filenodes we think we need for a file, lets remove
1749 1750 # all those we now the recipient must have.
1750 1751 def prune_filenodes(f, filerevlog):
1751 1752 msngset = msng_filenode_set[f]
1752 1753 hasset = {}
1753 1754 # If a 'missing' filenode thinks it belongs to a changenode we
1754 1755 # assume the recipient must have, then the recipient must have
1755 1756 # that filenode.
1756 1757 for n in msngset:
1757 1758 clnode = cl.node(filerevlog.linkrev(n))
1758 1759 if clnode in has_cl_set:
1759 1760 hasset[n] = 1
1760 1761 prune_parents(filerevlog, hasset, msngset)
1761 1762
1762 1763 # A function generator function that sets up the a context for the
1763 1764 # inner function.
1764 1765 def lookup_filenode_link_func(fname):
1765 1766 msngset = msng_filenode_set[fname]
1766 1767 # Lookup the changenode the filenode belongs to.
1767 1768 def lookup_filenode_link(fnode):
1768 1769 return msngset[fnode]
1769 1770 return lookup_filenode_link
1770 1771
1771 1772 # Add the nodes that were explicitly requested.
1772 1773 def add_extra_nodes(name, nodes):
1773 1774 if not extranodes or name not in extranodes:
1774 1775 return
1775 1776
1776 1777 for node, linknode in extranodes[name]:
1777 1778 if node not in nodes:
1778 1779 nodes[node] = linknode
1779 1780
1780 1781 # Now that we have all theses utility functions to help out and
1781 1782 # logically divide up the task, generate the group.
1782 1783 def gengroup():
1783 1784 # The set of changed files starts empty.
1784 1785 changedfiles = {}
1785 1786 # Create a changenode group generator that will call our functions
1786 1787 # back to lookup the owning changenode and collect information.
1787 1788 group = cl.group(msng_cl_lst, identity,
1788 1789 manifest_and_file_collector(changedfiles))
1789 1790 for chnk in group:
1790 1791 yield chnk
1791 1792
1792 1793 # The list of manifests has been collected by the generator
1793 1794 # calling our functions back.
1794 1795 prune_manifests()
1795 1796 add_extra_nodes(1, msng_mnfst_set)
1796 1797 msng_mnfst_lst = msng_mnfst_set.keys()
1797 1798 # Sort the manifestnodes by revision number.
1798 1799 msng_mnfst_lst.sort(cmp_by_rev_func(mnfst))
1799 1800 # Create a generator for the manifestnodes that calls our lookup
1800 1801 # and data collection functions back.
1801 1802 group = mnfst.group(msng_mnfst_lst, lookup_manifest_link,
1802 1803 filenode_collector(changedfiles))
1803 1804 for chnk in group:
1804 1805 yield chnk
1805 1806
1806 1807 # These are no longer needed, dereference and toss the memory for
1807 1808 # them.
1808 1809 msng_mnfst_lst = None
1809 1810 msng_mnfst_set.clear()
1810 1811
1811 1812 if extranodes:
1812 1813 for fname in extranodes:
1813 1814 if isinstance(fname, int):
1814 1815 continue
1815 1816 msng_filenode_set.setdefault(fname, {})
1816 1817 changedfiles[fname] = 1
1817 1818 # Go through all our files in order sorted by name.
1818 1819 for fname in util.sort(changedfiles):
1819 1820 filerevlog = self.file(fname)
1820 1821 if not len(filerevlog):
1821 1822 raise util.Abort(_("empty or missing revlog for %s") % fname)
1822 1823 # Toss out the filenodes that the recipient isn't really
1823 1824 # missing.
1824 1825 if fname in msng_filenode_set:
1825 1826 prune_filenodes(fname, filerevlog)
1826 1827 add_extra_nodes(fname, msng_filenode_set[fname])
1827 1828 msng_filenode_lst = msng_filenode_set[fname].keys()
1828 1829 else:
1829 1830 msng_filenode_lst = []
1830 1831 # If any filenodes are left, generate the group for them,
1831 1832 # otherwise don't bother.
1832 1833 if len(msng_filenode_lst) > 0:
1833 1834 yield changegroup.chunkheader(len(fname))
1834 1835 yield fname
1835 1836 # Sort the filenodes by their revision #
1836 1837 msng_filenode_lst.sort(cmp_by_rev_func(filerevlog))
1837 1838 # Create a group generator and only pass in a changenode
1838 1839 # lookup function as we need to collect no information
1839 1840 # from filenodes.
1840 1841 group = filerevlog.group(msng_filenode_lst,
1841 1842 lookup_filenode_link_func(fname))
1842 1843 for chnk in group:
1843 1844 yield chnk
1844 1845 if fname in msng_filenode_set:
1845 1846 # Don't need this anymore, toss it to free memory.
1846 1847 del msng_filenode_set[fname]
1847 1848 # Signal that no more groups are left.
1848 1849 yield changegroup.closechunk()
1849 1850
1850 1851 if msng_cl_lst:
1851 1852 self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source)
1852 1853
1853 1854 return util.chunkbuffer(gengroup())
1854 1855
1855 1856 def changegroup(self, basenodes, source):
1856 1857 """Generate a changegroup of all nodes that we have that a recipient
1857 1858 doesn't.
1858 1859
1859 1860 This is much easier than the previous function as we can assume that
1860 1861 the recipient has any changenode we aren't sending them."""
1861 1862
1862 1863 self.hook('preoutgoing', throw=True, source=source)
1863 1864
1864 1865 cl = self.changelog
1865 1866 nodes = cl.nodesbetween(basenodes, None)[0]
1866 1867 revset = dict.fromkeys([cl.rev(n) for n in nodes])
1867 1868 self.changegroupinfo(nodes, source)
1868 1869
1869 1870 def identity(x):
1870 1871 return x
1871 1872
1872 1873 def gennodelst(log):
1873 1874 for r in log:
1874 1875 n = log.node(r)
1875 1876 if log.linkrev(n) in revset:
1876 1877 yield n
1877 1878
1878 1879 def changed_file_collector(changedfileset):
1879 1880 def collect_changed_files(clnode):
1880 1881 c = cl.read(clnode)
1881 1882 for fname in c[3]:
1882 1883 changedfileset[fname] = 1
1883 1884 return collect_changed_files
1884 1885
1885 1886 def lookuprevlink_func(revlog):
1886 1887 def lookuprevlink(n):
1887 1888 return cl.node(revlog.linkrev(n))
1888 1889 return lookuprevlink
1889 1890
1890 1891 def gengroup():
1891 1892 # construct a list of all changed files
1892 1893 changedfiles = {}
1893 1894
1894 1895 for chnk in cl.group(nodes, identity,
1895 1896 changed_file_collector(changedfiles)):
1896 1897 yield chnk
1897 1898
1898 1899 mnfst = self.manifest
1899 1900 nodeiter = gennodelst(mnfst)
1900 1901 for chnk in mnfst.group(nodeiter, lookuprevlink_func(mnfst)):
1901 1902 yield chnk
1902 1903
1903 1904 for fname in util.sort(changedfiles):
1904 1905 filerevlog = self.file(fname)
1905 1906 if not len(filerevlog):
1906 1907 raise util.Abort(_("empty or missing revlog for %s") % fname)
1907 1908 nodeiter = gennodelst(filerevlog)
1908 1909 nodeiter = list(nodeiter)
1909 1910 if nodeiter:
1910 1911 yield changegroup.chunkheader(len(fname))
1911 1912 yield fname
1912 1913 lookup = lookuprevlink_func(filerevlog)
1913 1914 for chnk in filerevlog.group(nodeiter, lookup):
1914 1915 yield chnk
1915 1916
1916 1917 yield changegroup.closechunk()
1917 1918
1918 1919 if nodes:
1919 1920 self.hook('outgoing', node=hex(nodes[0]), source=source)
1920 1921
1921 1922 return util.chunkbuffer(gengroup())
1922 1923
1923 1924 def addchangegroup(self, source, srctype, url, emptyok=False):
1924 1925 """add changegroup to repo.
1925 1926
1926 1927 return values:
1927 1928 - nothing changed or no source: 0
1928 1929 - more heads than before: 1+added heads (2..n)
1929 1930 - less heads than before: -1-removed heads (-2..-n)
1930 1931 - number of heads stays the same: 1
1931 1932 """
1932 1933 def csmap(x):
1933 1934 self.ui.debug(_("add changeset %s\n") % short(x))
1934 1935 return len(cl)
1935 1936
1936 1937 def revmap(x):
1937 1938 return cl.rev(x)
1938 1939
1939 1940 if not source:
1940 1941 return 0
1941 1942
1942 1943 self.hook('prechangegroup', throw=True, source=srctype, url=url)
1943 1944
1944 1945 changesets = files = revisions = 0
1945 1946
1946 1947 # write changelog data to temp files so concurrent readers will not see
1947 1948 # inconsistent view
1948 1949 cl = self.changelog
1949 1950 cl.delayupdate()
1950 1951 oldheads = len(cl.heads())
1951 1952
1952 1953 tr = self.transaction()
1953 1954 try:
1954 1955 trp = weakref.proxy(tr)
1955 1956 # pull off the changeset group
1956 1957 self.ui.status(_("adding changesets\n"))
1957 1958 cor = len(cl) - 1
1958 1959 chunkiter = changegroup.chunkiter(source)
1959 1960 if cl.addgroup(chunkiter, csmap, trp) is None and not emptyok:
1960 1961 raise util.Abort(_("received changelog group is empty"))
1961 1962 cnr = len(cl) - 1
1962 1963 changesets = cnr - cor
1963 1964
1964 1965 # pull off the manifest group
1965 1966 self.ui.status(_("adding manifests\n"))
1966 1967 chunkiter = changegroup.chunkiter(source)
1967 1968 # no need to check for empty manifest group here:
1968 1969 # if the result of the merge of 1 and 2 is the same in 3 and 4,
1969 1970 # no new manifest will be created and the manifest group will
1970 1971 # be empty during the pull
1971 1972 self.manifest.addgroup(chunkiter, revmap, trp)
1972 1973
1973 1974 # process the files
1974 1975 self.ui.status(_("adding file changes\n"))
1975 1976 while 1:
1976 1977 f = changegroup.getchunk(source)
1977 1978 if not f:
1978 1979 break
1979 1980 self.ui.debug(_("adding %s revisions\n") % f)
1980 1981 fl = self.file(f)
1981 1982 o = len(fl)
1982 1983 chunkiter = changegroup.chunkiter(source)
1983 1984 if fl.addgroup(chunkiter, revmap, trp) is None:
1984 1985 raise util.Abort(_("received file revlog group is empty"))
1985 1986 revisions += len(fl) - o
1986 1987 files += 1
1987 1988
1988 1989 # make changelog see real files again
1989 1990 cl.finalize(trp)
1990 1991
1991 1992 newheads = len(self.changelog.heads())
1992 1993 heads = ""
1993 1994 if oldheads and newheads != oldheads:
1994 1995 heads = _(" (%+d heads)") % (newheads - oldheads)
1995 1996
1996 1997 self.ui.status(_("added %d changesets"
1997 1998 " with %d changes to %d files%s\n")
1998 1999 % (changesets, revisions, files, heads))
1999 2000
2000 2001 if changesets > 0:
2001 2002 self.hook('pretxnchangegroup', throw=True,
2002 2003 node=hex(self.changelog.node(cor+1)), source=srctype,
2003 2004 url=url)
2004 2005
2005 2006 tr.close()
2006 2007 finally:
2007 2008 del tr
2008 2009
2009 2010 if changesets > 0:
2010 2011 # forcefully update the on-disk branch cache
2011 2012 self.ui.debug(_("updating the branch cache\n"))
2012 2013 self.branchtags()
2013 2014 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
2014 2015 source=srctype, url=url)
2015 2016
2016 2017 for i in xrange(cor + 1, cnr + 1):
2017 2018 self.hook("incoming", node=hex(self.changelog.node(i)),
2018 2019 source=srctype, url=url)
2019 2020
2020 2021 # never return 0 here:
2021 2022 if newheads < oldheads:
2022 2023 return newheads - oldheads - 1
2023 2024 else:
2024 2025 return newheads - oldheads + 1
2025 2026
2026 2027
2027 2028 def stream_in(self, remote):
2028 2029 fp = remote.stream_out()
2029 2030 l = fp.readline()
2030 2031 try:
2031 2032 resp = int(l)
2032 2033 except ValueError:
2033 2034 raise util.UnexpectedOutput(
2034 2035 _('Unexpected response from remote server:'), l)
2035 2036 if resp == 1:
2036 2037 raise util.Abort(_('operation forbidden by server'))
2037 2038 elif resp == 2:
2038 2039 raise util.Abort(_('locking the remote repository failed'))
2039 2040 elif resp != 0:
2040 2041 raise util.Abort(_('the server sent an unknown error code'))
2041 2042 self.ui.status(_('streaming all changes\n'))
2042 2043 l = fp.readline()
2043 2044 try:
2044 2045 total_files, total_bytes = map(int, l.split(' ', 1))
2045 2046 except (ValueError, TypeError):
2046 2047 raise util.UnexpectedOutput(
2047 2048 _('Unexpected response from remote server:'), l)
2048 2049 self.ui.status(_('%d files to transfer, %s of data\n') %
2049 2050 (total_files, util.bytecount(total_bytes)))
2050 2051 start = time.time()
2051 2052 for i in xrange(total_files):
2052 2053 # XXX doesn't support '\n' or '\r' in filenames
2053 2054 l = fp.readline()
2054 2055 try:
2055 2056 name, size = l.split('\0', 1)
2056 2057 size = int(size)
2057 2058 except (ValueError, TypeError):
2058 2059 raise util.UnexpectedOutput(
2059 2060 _('Unexpected response from remote server:'), l)
2060 2061 self.ui.debug(_('adding %s (%s)\n') % (name, util.bytecount(size)))
2061 2062 ofp = self.sopener(name, 'w')
2062 2063 for chunk in util.filechunkiter(fp, limit=size):
2063 2064 ofp.write(chunk)
2064 2065 ofp.close()
2065 2066 elapsed = time.time() - start
2066 2067 if elapsed <= 0:
2067 2068 elapsed = 0.001
2068 2069 self.ui.status(_('transferred %s in %.1f seconds (%s/sec)\n') %
2069 2070 (util.bytecount(total_bytes), elapsed,
2070 2071 util.bytecount(total_bytes / elapsed)))
2071 2072 self.invalidate()
2072 2073 return len(self.heads()) + 1
2073 2074
2074 2075 def clone(self, remote, heads=[], stream=False):
2075 2076 '''clone remote repository.
2076 2077
2077 2078 keyword arguments:
2078 2079 heads: list of revs to clone (forces use of pull)
2079 2080 stream: use streaming clone if possible'''
2080 2081
2081 2082 # now, all clients that can request uncompressed clones can
2082 2083 # read repo formats supported by all servers that can serve
2083 2084 # them.
2084 2085
2085 2086 # if revlog format changes, client will have to check version
2086 2087 # and format flags on "stream" capability, and use
2087 2088 # uncompressed only if compatible.
2088 2089
2089 2090 if stream and not heads and remote.capable('stream'):
2090 2091 return self.stream_in(remote)
2091 2092 return self.pull(remote, heads)
2092 2093
2093 2094 # used to avoid circular references so destructors work
2094 2095 def aftertrans(files):
2095 2096 renamefiles = [tuple(t) for t in files]
2096 2097 def a():
2097 2098 for src, dest in renamefiles:
2098 2099 util.rename(src, dest)
2099 2100 return a
2100 2101
2101 2102 def instance(ui, path, create):
2102 2103 return localrepository(ui, util.drop_scheme('file', path), create)
2103 2104
2104 2105 def islocal(path):
2105 2106 return True
@@ -1,127 +1,292 b''
1 1 # store.py - repository store handling for Mercurial
2 2 #
3 3 # Copyright 2008 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 from i18n import _
8 9 import os, stat, osutil, util
9 10
11 _sha = util.sha1
12
10 13 def _buildencodefun():
11 14 e = '_'
12 15 win_reserved = [ord(x) for x in '\\:*?"<>|']
13 16 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ])
14 17 for x in (range(32) + range(126, 256) + win_reserved):
15 18 cmap[chr(x)] = "~%02x" % x
16 19 for x in range(ord("A"), ord("Z")+1) + [ord(e)]:
17 20 cmap[chr(x)] = e + chr(x).lower()
18 21 dmap = {}
19 22 for k, v in cmap.iteritems():
20 23 dmap[v] = k
21 24 def decode(s):
22 25 i = 0
23 26 while i < len(s):
24 27 for l in xrange(1, 4):
25 28 try:
26 29 yield dmap[s[i:i+l]]
27 30 i += l
28 31 break
29 32 except KeyError:
30 33 pass
31 34 else:
32 35 raise KeyError
33 36 return (lambda s: "".join([cmap[c] for c in s]),
34 37 lambda s: "".join(list(decode(s))))
35 38
36 39 encodefilename, decodefilename = _buildencodefun()
37 40
41 def _build_lower_encodefun():
42 win_reserved = [ord(x) for x in '\\:*?"<>|']
43 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ])
44 for x in (range(32) + range(126, 256) + win_reserved):
45 cmap[chr(x)] = "~%02x" % x
46 for x in range(ord("A"), ord("Z")+1):
47 cmap[chr(x)] = chr(x).lower()
48 return lambda s: "".join([cmap[c] for c in s])
49
50 lowerencode = _build_lower_encodefun()
51
52 _windows_reserved_filenames = '''con prn aux nul
53 com1 com2 com3 com4 com5 com6 com7 com8 com9
54 lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
55 def auxencode(path):
56 res = []
57 for n in path.split('/'):
58 if n:
59 base = n.split('.')[0]
60 if base and (base in _windows_reserved_filenames):
61 # encode third letter ('aux' -> 'au~78')
62 ec = "~%02x" % ord(n[2])
63 n = n[0:2] + ec + n[3:]
64 res.append(n)
65 return '/'.join(res)
66
67 MAX_PATH_LEN_IN_HGSTORE = 120
68 DIR_PREFIX_LEN = 8
69 _MAX_SHORTENED_DIRS_LEN = 8 * (DIR_PREFIX_LEN + 1) - 4
70 def hybridencode(path):
71 '''encodes path with a length limit
72
73 Encodes all paths that begin with 'data/', according to the following.
74
75 Default encoding (reversible):
76
77 Encodes all uppercase letters 'X' as '_x'. All reserved or illegal
78 characters are encoded as '~xx', where xx is the two digit hex code
79 of the character (see encodefilename).
80 Relevant path components consisting of Windows reserved filenames are
81 masked by encoding the third character ('aux' -> 'au~78', see auxencode).
82
83 Hashed encoding (not reversible):
84
85 If the default-encoded path is longer than MAX_PATH_LEN_IN_HGSTORE, a
86 non-reversible hybrid hashing of the path is done instead.
87 This encoding uses up to DIR_PREFIX_LEN characters of all directory
88 levels of the lowerencoded path, but not more levels than can fit into
89 _MAX_SHORTENED_DIRS_LEN.
90 Then follows the filler followed by the sha digest of the full path.
91 The filler is the beginning of the basename of the lowerencoded path
92 (the basename is everything after the last path separator). The filler
93 is as long as possible, filling in characters from the basename until
94 the encoded path has MAX_PATH_LEN_IN_HGSTORE characters (or all chars
95 of the basename have been taken).
96 The extension (e.g. '.i' or '.d') is preserved.
97
98 The string 'data/' at the beginning is replaced with 'dh/', if the hashed
99 encoding was used.
100 '''
101 if not path.startswith('data/'):
102 return path
103 ndpath = path[len('data/'):]
104 res = 'data/' + auxencode(encodefilename(ndpath))
105 if len(res) > MAX_PATH_LEN_IN_HGSTORE:
106 digest = _sha(path).hexdigest()
107 aep = auxencode(lowerencode(ndpath))
108 _root, ext = os.path.splitext(aep)
109 parts = aep.split('/')
110 basename = parts[-1]
111 sdirs = []
112 for p in parts[:-1]:
113 d = p[:DIR_PREFIX_LEN]
114 t = '/'.join(sdirs) + '/' + d
115 if len(t) > _MAX_SHORTENED_DIRS_LEN:
116 break
117 sdirs.append(d)
118 dirs = '/'.join(sdirs)
119 if len(dirs) > 0:
120 dirs += '/'
121 res = 'dh/' + dirs + digest + ext
122 space_left = MAX_PATH_LEN_IN_HGSTORE - len(res)
123 if space_left > 0:
124 filler = basename[:space_left]
125 res = 'dh/' + dirs + filler + digest + ext
126 return res
127
38 128 def _calcmode(path):
39 129 try:
40 130 # files in .hg/ will be created using this mode
41 131 mode = os.stat(path).st_mode
42 132 # avoid some useless chmods
43 133 if (0777 & ~util._umask) == (0777 & mode):
44 134 mode = None
45 135 except OSError:
46 136 mode = None
47 137 return mode
48 138
49 139 _data = 'data 00manifest.d 00manifest.i 00changelog.d 00changelog.i'
50 140
51 141 class basicstore:
52 142 '''base class for local repository stores'''
53 143 def __init__(self, path, opener, pathjoiner):
54 144 self.pathjoiner = pathjoiner
55 145 self.path = path
56 146 self.createmode = _calcmode(path)
57 147 self.opener = opener(self.path)
58 148 self.opener.createmode = self.createmode
59 149
60 150 def join(self, f):
61 151 return self.pathjoiner(self.path, f)
62 152
63 153 def _walk(self, relpath, recurse):
64 154 '''yields (unencoded, encoded, size)'''
65 155 path = self.pathjoiner(self.path, relpath)
66 156 striplen = len(self.path) + len(os.sep)
67 157 prefix = path[striplen:]
68 158 l = []
69 159 if os.path.isdir(path):
70 160 visit = [path]
71 161 while visit:
72 162 p = visit.pop()
73 163 for f, kind, st in osutil.listdir(p, stat=True):
74 164 fp = self.pathjoiner(p, f)
75 165 if kind == stat.S_IFREG and f[-2:] in ('.d', '.i'):
76 166 n = util.pconvert(fp[striplen:])
77 167 l.append((n, n, st.st_size))
78 168 elif kind == stat.S_IFDIR and recurse:
79 169 visit.append(fp)
80 170 return util.sort(l)
81 171
82 172 def datafiles(self):
83 173 return self._walk('data', True)
84 174
85 175 def walk(self):
86 176 '''yields (unencoded, encoded, size)'''
87 177 # yield data files first
88 178 for x in self.datafiles():
89 179 yield x
90 180 # yield manifest before changelog
91 181 meta = self._walk('', False)
92 182 meta.reverse()
93 183 for x in meta:
94 184 yield x
95 185
96 186 def copylist(self):
97 187 return ['requires'] + _data.split()
98 188
99 189 class encodedstore(basicstore):
100 190 def __init__(self, path, opener, pathjoiner):
101 191 self.pathjoiner = pathjoiner
102 192 self.path = self.pathjoiner(path, 'store')
103 193 self.createmode = _calcmode(self.path)
104 194 op = opener(self.path)
105 195 op.createmode = self.createmode
106 196 self.opener = lambda f, *args, **kw: op(encodefilename(f), *args, **kw)
107 197
108 198 def datafiles(self):
109 199 for a, b, size in self._walk('data', True):
110 200 try:
111 201 a = decodefilename(a)
112 202 except KeyError:
113 203 a = None
114 204 yield a, b, size
115 205
116 206 def join(self, f):
117 207 return self.pathjoiner(self.path, encodefilename(f))
118 208
119 209 def copylist(self):
120 210 return (['requires', '00changelog.i'] +
121 211 [self.pathjoiner('store', f) for f in _data.split()])
122 212
213 def fncache(opener):
214 '''yields the entries in the fncache file'''
215 try:
216 fp = opener('fncache', mode='rb')
217 except IOError:
218 # skip nonexistent file
219 return
220 for n, line in enumerate(fp):
221 if (len(line) < 2) or (line[-1] != '\n'):
222 t = _('invalid entry in fncache, line %s') % (n + 1)
223 raise util.Abort(t)
224 yield line[:-1]
225 fp.close()
226
227 class fncacheopener(object):
228 def __init__(self, opener):
229 self.opener = opener
230 self.entries = None
231
232 def loadfncache(self):
233 self.entries = {}
234 for f in fncache(self.opener):
235 self.entries[f] = True
236
237 def __call__(self, path, mode='r', *args, **kw):
238 if mode not in ('r', 'rb') and path.startswith('data/'):
239 if self.entries is None:
240 self.loadfncache()
241 if path not in self.entries:
242 self.opener('fncache', 'ab').write(path + '\n')
243 # fncache may contain non-existent files after rollback / strip
244 self.entries[path] = True
245 return self.opener(hybridencode(path), mode, *args, **kw)
246
247 class fncachestore(basicstore):
248 def __init__(self, path, opener, pathjoiner):
249 self.pathjoiner = pathjoiner
250 self.path = self.pathjoiner(path, 'store')
251 self.createmode = _calcmode(self.path)
252 self._op = opener(self.path)
253 self._op.createmode = self.createmode
254 self.opener = fncacheopener(self._op)
255
256 def join(self, f):
257 return self.pathjoiner(self.path, hybridencode(f))
258
259 def datafiles(self):
260 rewrite = False
261 existing = []
262 pjoin = self.pathjoiner
263 spath = self.path
264 for f in fncache(self._op):
265 ef = hybridencode(f)
266 try:
267 st = os.stat(pjoin(spath, ef))
268 yield f, ef, st.st_size
269 existing.append(f)
270 except OSError:
271 # nonexistent entry
272 rewrite = True
273 if rewrite:
274 # rewrite fncache to remove nonexistent entries
275 # (may be caused by rollback / strip)
276 fp = self._op('fncache', mode='wb')
277 for p in existing:
278 fp.write(p + '\n')
279 fp.close()
280
281 def copylist(self):
282 d = _data + ' dh fncache'
283 return (['requires', '00changelog.i'] +
284 [self.pathjoiner('store', f) for f in d.split()])
285
123 286 def store(requirements, path, opener, pathjoiner=None):
124 287 pathjoiner = pathjoiner or os.path.join
125 288 if 'store' in requirements:
289 if 'fncache' in requirements:
290 return fncachestore(path, opener, pathjoiner)
126 291 return encodedstore(path, opener, pathjoiner)
127 292 return basicstore(path, opener, pathjoiner)
@@ -1,47 +1,61 b''
1 1 #!/bin/sh
2 2
3 3 CONTRIBDIR=$TESTDIR/../contrib
4 4
5 echo % prepare repo-a
5 6 mkdir repo-a
6 7 cd repo-a
7 8 hg init
8 9
9 10 echo this is file a > a
10 11 hg add a
11 12 hg commit -m first -d '0 0'
12 13
13 14 echo adding to file a >> a
14 15 hg commit -m second -d '0 0'
15 16
16 17 echo adding more to file a >> a
17 18 hg commit -m third -d '0 0'
18 19
19 20 hg verify
20 21
21 echo dumping revlog of file a to stdout:
22 echo
23 echo % dumping revlog of file a to stdout
22 24 python $CONTRIBDIR/dumprevlog .hg/store/data/a.i
23 echo dumprevlog done
25 echo % dumprevlog done
24 26
25 # dump all revlogs to file repo.dump
27 echo
28 echo % dump all revlogs to file repo.dump
26 29 find .hg/store -name "*.i" | sort | xargs python $CONTRIBDIR/dumprevlog > ../repo.dump
27 30
28 31 cd ..
29 32
30 33 mkdir repo-b
31 34 cd repo-b
32 35 hg init
33 36
34 echo undumping:
37 echo
38 echo % undumping into repo-b
35 39 python $CONTRIBDIR/undumprevlog < ../repo.dump
36 echo undumping done
40 echo % undumping done
41
42 cd ..
37 43
44 echo
45 echo % clone --pull repo-b repo-c to rebuild fncache
46 hg clone --pull -U repo-b repo-c
47
48 cd repo-c
49
50 echo
51 echo % verify repo-c
38 52 hg verify
39 53
40 54 cd ..
41 55
42 echo comparing repos:
43 hg -R repo-b incoming repo-a
44 hg -R repo-a incoming repo-b
45 echo comparing done
56 echo
57 echo % comparing repos
58 hg -R repo-c incoming repo-a
59 hg -R repo-a incoming repo-c
46 60
47 61 exit 0
@@ -1,53 +1,67 b''
1 % prepare repo-a
1 2 checking changesets
2 3 checking manifests
3 4 crosschecking files in changesets and manifests
4 5 checking files
5 6 1 files, 3 changesets, 3 total revisions
6 dumping revlog of file a to stdout:
7
8 % dumping revlog of file a to stdout
7 9 file: .hg/store/data/a.i
8 10 node: 183d2312b35066fb6b3b449b84efc370d50993d0
9 11 linkrev: 0
10 12 parents: 0000000000000000000000000000000000000000 0000000000000000000000000000000000000000
11 13 length: 15
12 14 -start-
13 15 this is file a
14 16
15 17 -end-
16 18 node: b1047953b6e6b633c0d8197eaa5116fbdfd3095b
17 19 linkrev: 1
18 20 parents: 183d2312b35066fb6b3b449b84efc370d50993d0 0000000000000000000000000000000000000000
19 21 length: 32
20 22 -start-
21 23 this is file a
22 24 adding to file a
23 25
24 26 -end-
25 27 node: 8c4fd1f7129b8cdec6c7f58bf48fb5237a4030c1
26 28 linkrev: 2
27 29 parents: b1047953b6e6b633c0d8197eaa5116fbdfd3095b 0000000000000000000000000000000000000000
28 30 length: 54
29 31 -start-
30 32 this is file a
31 33 adding to file a
32 34 adding more to file a
33 35
34 36 -end-
35 dumprevlog done
36 undumping:
37 % dumprevlog done
38
39 % dump all revlogs to file repo.dump
40
41 % undumping into repo-b
37 42 .hg/store/00changelog.i
38 43 .hg/store/00manifest.i
39 44 .hg/store/data/a.i
40 undumping done
45 % undumping done
46
47 % clone --pull repo-b repo-c to rebuild fncache
48 requesting all changes
49 adding changesets
50 adding manifests
51 adding file changes
52 added 3 changesets with 3 changes to 1 files
53
54 % verify repo-c
41 55 checking changesets
42 56 checking manifests
43 57 crosschecking files in changesets and manifests
44 58 checking files
45 59 1 files, 3 changesets, 3 total revisions
46 comparing repos:
60
61 % comparing repos
47 62 comparing with repo-a
48 63 searching for changes
49 64 no changes found
50 comparing with repo-b
65 comparing with repo-c
51 66 searching for changes
52 67 no changes found
53 comparing done
@@ -1,54 +1,56 b''
1 1 % before commit
2 2 % store can be written by the group, other files cannot
3 3 % store is setgid
4 4 00700 ./.hg/
5 5 00600 ./.hg/00changelog.i
6 6 00600 ./.hg/requires
7 7 00770 ./.hg/store/
8 8
9 9 % after commit
10 10 % working dir files can only be written by the owner
11 11 % files created in .hg can be written by the group
12 12 % (in particular, store/**, dirstate, branch cache file, undo files)
13 13 % new directories are setgid
14 14 00700 ./.hg/
15 15 00600 ./.hg/00changelog.i
16 16 00660 ./.hg/dirstate
17 17 00600 ./.hg/requires
18 18 00770 ./.hg/store/
19 19 00660 ./.hg/store/00changelog.i
20 20 00660 ./.hg/store/00manifest.i
21 21 00770 ./.hg/store/data/
22 22 00770 ./.hg/store/data/dir/
23 23 00660 ./.hg/store/data/dir/bar.i
24 24 00660 ./.hg/store/data/foo.i
25 00660 ./.hg/store/fncache
25 26 00660 ./.hg/store/undo
26 27 00660 ./.hg/undo.branch
27 28 00660 ./.hg/undo.dirstate
28 29 00700 ./dir/
29 30 00600 ./dir/bar
30 31 00600 ./foo
31 32
32 33 % before push
33 34 % group can write everything
34 35 00770 ../push/.hg/
35 36 00660 ../push/.hg/00changelog.i
36 37 00660 ../push/.hg/requires
37 38 00770 ../push/.hg/store/
38 39
39 40 % after push
40 41 % group can still write everything
41 42 00770 ../push/.hg/
42 43 00660 ../push/.hg/00changelog.i
43 44 00660 ../push/.hg/branch.cache
44 45 00660 ../push/.hg/requires
45 46 00770 ../push/.hg/store/
46 47 00660 ../push/.hg/store/00changelog.i
47 48 00660 ../push/.hg/store/00manifest.i
48 49 00770 ../push/.hg/store/data/
49 50 00770 ../push/.hg/store/data/dir/
50 51 00660 ../push/.hg/store/data/dir/bar.i
51 52 00660 ../push/.hg/store/data/foo.i
53 00660 ../push/.hg/store/fncache
52 54 00660 ../push/.hg/store/undo
53 55 00660 ../push/.hg/undo.branch
54 56 00660 ../push/.hg/undo.dirstate
@@ -1,69 +1,70 b''
1 1 # creating 'local'
2 2 store created
3 3 00changelog.i created
4 4 revlogv1
5 5 store
6 fncache
6 7 adding foo
7 8 # creating repo with old format
8 9 revlogv1
9 10 #test failure
10 11 abort: repository local already exists!
11 12 # init+push to remote2
12 13 comparing with local
13 14 changeset: 0:c4e059d443be
14 15 tag: tip
15 16 user: test
16 17 date: Mon Jan 12 13:46:40 1970 +0000
17 18 summary: init
18 19
19 20 pushing to ssh://user@dummy/remote2
20 21 searching for changes
21 22 remote: adding changesets
22 23 remote: adding manifests
23 24 remote: adding file changes
24 25 remote: added 1 changesets with 1 changes to 1 files
25 26 # clone to remote1
26 27 searching for changes
27 28 remote: adding changesets
28 29 remote: adding manifests
29 30 remote: adding file changes
30 31 remote: added 1 changesets with 1 changes to 1 files
31 32 # init to existing repo
32 33 abort: repository remote1 already exists!
33 34 abort: could not create remote repo!
34 35 # clone to existing repo
35 36 abort: repository remote1 already exists!
36 37 abort: could not create remote repo!
37 38 # output of dummyssh
38 39 Got arguments 1:user@dummy 2:hg init remote2
39 40 Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio
40 41 Got arguments 1:user@dummy 2:hg -R remote2 serve --stdio
41 42 Got arguments 1:user@dummy 2:hg init remote1
42 43 Got arguments 1:user@dummy 2:hg -R remote1 serve --stdio
43 44 Got arguments 1:user@dummy 2:hg init remote1
44 45 Got arguments 1:user@dummy 2:hg init remote1
45 46 # comparing repositories
46 47 0:c4e059d443be
47 48 0:c4e059d443be
48 49 0:c4e059d443be
49 50 # check names for repositories (clashes with URL schemes, special chars)
50 51 # hg init "bundle"
51 52 ok
52 53 # hg init "file"
53 54 ok
54 55 # hg init "hg"
55 56 ok
56 57 # hg init "http"
57 58 ok
58 59 # hg init "https"
59 60 ok
60 61 # hg init "old-http"
61 62 ok
62 63 # hg init "ssh"
63 64 ok
64 65 # hg init "static-http"
65 66 ok
66 67 # hg init " "
67 68 ok
68 69 # hg init "with space"
69 70 ok
@@ -1,34 +1,31 b''
1 1 % prepare repo
2 2 adding FOO.txt
3 3 adding QUICK.txt
4 4 adding bar.txt
5 5
6 6 % verify
7 7 checking changesets
8 8 checking manifests
9 9 crosschecking files in changesets and manifests
10 10 checking files
11 11 3 files, 1 changesets, 3 total revisions
12 12
13 13 % introduce some bugs in repo
14 14
15 15 % verify
16 16 checking changesets
17 17 checking manifests
18 18 crosschecking files in changesets and manifests
19 19 checking files
20 ?: cannot decode filename 'data/X_f_o_o.txt.i'
21 20 data/FOO.txt.i@0: missing revlog!
22 21 0: empty or missing FOO.txt
23 22 FOO.txt@0: f62022d3d590 in manifests not found
24 23 data/QUICK.txt.i@0: missing revlog!
25 24 0: empty or missing QUICK.txt
26 25 QUICK.txt@0: 88b857db8eba in manifests not found
27 26 data/bar.txt.i@0: missing revlog!
28 27 0: empty or missing bar.txt
29 28 bar.txt@0: 256559129457 in manifests not found
30 warning: orphan revlog 'data/xbar.txt.i'
31 29 3 files, 1 changesets, 0 total revisions
32 1 warnings encountered!
33 10 integrity errors encountered!
30 9 integrity errors encountered!
34 31 (first damaged changeset appears to be 0)
General Comments 0
You need to be logged in to leave comments. Login now