##// END OF EJS Templates
branchcache: backout 0311a6abd38a
Matt Mackall -
r16745:27b2e182 default
parent child Browse files
Show More
@@ -550,9 +550,6 b' class localrepository(repo.repository):'
550 continue
550 continue
551 node, label = l.split(" ", 1)
551 node, label = l.split(" ", 1)
552 label = encoding.tolocal(label.strip())
552 label = encoding.tolocal(label.strip())
553 if not node in self:
554 raise ValueError('invalidating branch cache because node '+
555 '%s does not exist' % node)
556 partial.setdefault(label, []).append(bin(node))
553 partial.setdefault(label, []).append(bin(node))
557 except KeyboardInterrupt:
554 except KeyboardInterrupt:
558 raise
555 raise
@@ -574,10 +571,6 b' class localrepository(repo.repository):'
574 pass
571 pass
575
572
576 def _updatebranchcache(self, partial, ctxgen):
573 def _updatebranchcache(self, partial, ctxgen):
577 """Given a branchhead cache, partial, that may have extra nodes or be
578 missing heads, and a generator of nodes that are at least a superset of
579 heads missing, this function updates partial to be correct.
580 """
581 # collect new branch entries
574 # collect new branch entries
582 newbranches = {}
575 newbranches = {}
583 for c in ctxgen:
576 for c in ctxgen:
@@ -588,42 +581,21 b' class localrepository(repo.repository):'
588 for branch, newnodes in newbranches.iteritems():
581 for branch, newnodes in newbranches.iteritems():
589 bheads = partial.setdefault(branch, [])
582 bheads = partial.setdefault(branch, [])
590 bheads.extend(newnodes)
583 bheads.extend(newnodes)
591 # Remove duplicates - nodes that are in newnodes and are already in
584 if len(bheads) <= 1:
592 # bheads. This can happen if you strip a node and its parent was
585 continue
593 # already a head (because they're on different branches).
586 bheads = sorted(bheads, key=lambda x: self[x].rev())
594 bheads = set(bheads)
587 # starting from tip means fewer passes over reachable
595
588 while newnodes:
596 # Remove candidate heads that no longer are in the repo (e.g., as
589 latest = newnodes.pop()
597 # the result of a strip that just happened).
590 if latest not in bheads:
598 # avoid using 'bhead in self' here because that dives down into
591 continue
599 # branchcache code somewhat recrusively.
592 minbhnode = self[bheads[0]].node()
600 bheads = [bhead for bhead in bheads \
593 reachable = self.changelog.reachable(latest, minbhnode)
601 if self.changelog.hasnode(bhead)]
594 reachable.remove(latest)
602 if len(bheads) > 1:
595 if reachable:
603 bheads = sorted(bheads, key=lambda x: self[x].rev())
596 bheads = [b for b in bheads if b not in reachable]
604 # starting from tip means fewer passes over reachable
605 while newnodes:
606 latest = newnodes.pop()
607 if latest not in bheads:
608 continue
609 minbhnode = self[bheads[0]].node()
610 reachable = self.changelog.reachable(latest, minbhnode)
611 reachable.remove(latest)
612 if reachable:
613 bheads = [b for b in bheads if b not in reachable]
614 partial[branch] = bheads
597 partial[branch] = bheads
615
598
616 # There may be branches that cease to exist when the last commit in the
617 # branch was stripped. This code filters them out. Note that the
618 # branch that ceased to exist may not be in newbranches because
619 # newbranches is the set of candidate heads, which when you strip the
620 # last commit in a branch will be the parent branch.
621 for branch in partial.keys():
622 nodes = [head for head in partial[branch] \
623 if self.changelog.hasnode(head)]
624 if len(nodes) < 1:
625 del partial[branch]
626
627 def lookup(self, key):
599 def lookup(self, key):
628 return self[key].node()
600 return self[key].node()
629
601
@@ -886,9 +858,6 b' class localrepository(repo.repository):'
886 else:
858 else:
887 ui.status(_('working directory now based on '
859 ui.status(_('working directory now based on '
888 'revision %d\n') % parents)
860 'revision %d\n') % parents)
889 # TODO: if we know which new heads may result from this rollback, pass
890 # them to destroy(), which will prevent the branchhead cache from being
891 # invalidated.
892 self.destroyed()
861 self.destroyed()
893 return 0
862 return 0
894
863
@@ -1332,27 +1301,12 b' class localrepository(repo.repository):'
1332 tr.release()
1301 tr.release()
1333 lock.release()
1302 lock.release()
1334
1303
1335 def destroyed(self, newheadrevs=None):
1304 def destroyed(self):
1336 '''Inform the repository that nodes have been destroyed.
1305 '''Inform the repository that nodes have been destroyed.
1337 Intended for use by strip and rollback, so there's a common
1306 Intended for use by strip and rollback, so there's a common
1338 place for anything that has to be done after destroying history.
1307 place for anything that has to be done after destroying history.'''
1339
1308 # XXX it might be nice if we could take the list of destroyed
1340 If you know the branchheadcache was uptodate before nodes were removed
1309 # nodes, but I don't see an easy way for rollback() to do that
1341 and you also know the set of candidate set of new heads that may have
1342 resulted from the destruction, you can set newheadrevs. This will
1343 enable the code to update the branchheads cache, rather than having
1344 future code decide it's invalid and regenrating it.
1345 '''
1346 if newheadrevs:
1347 tiprev = len(self) - 1
1348 ctxgen = (self[rev] for rev in newheadrevs)
1349 self._updatebranchcache(self._branchcache, ctxgen)
1350 self._writebranchcache(self._branchcache, self.changelog.tip(),
1351 tiprev)
1352 else:
1353 # No info to update the cache. If nodes were destroyed, the cache
1354 # is stale and this will be caught the next time it is read.
1355 pass
1356
1310
1357 # Ensure the persistent tag cache is updated. Doing it now
1311 # Ensure the persistent tag cache is updated. Doing it now
1358 # means that the tag cache only has to worry about destroyed
1312 # means that the tag cache only has to worry about destroyed
@@ -56,11 +56,6 b' def _collectbrokencsets(repo, files, str'
56 return s
56 return s
57
57
58 def strip(ui, repo, nodelist, backup="all", topic='backup'):
58 def strip(ui, repo, nodelist, backup="all", topic='backup'):
59 # It simplifies the logic around updating the branchheads cache if we only
60 # have to consider the effect of the stripped revisions and not revisions
61 # missing because the cache is out-of-date.
62 repo.updatebranchcache()
63
64 cl = repo.changelog
59 cl = repo.changelog
65 # TODO handle undo of merge sets
60 # TODO handle undo of merge sets
66 if isinstance(nodelist, str):
61 if isinstance(nodelist, str):
@@ -68,14 +63,6 b' def strip(ui, repo, nodelist, backup="al'
68 striplist = [cl.rev(node) for node in nodelist]
63 striplist = [cl.rev(node) for node in nodelist]
69 striprev = min(striplist)
64 striprev = min(striplist)
70
65
71 # Set of potential new heads resulting from the strip. The parents of any
72 # node removed could be a new head because the node to be removed could have
73 # been the only child of the parent.
74 # Do a list->set->list conversion to remove duplicates.
75 stringstriplist = [str(rev) for rev in striplist]
76 newheadrevs = set(repo.revs("parents(%lr::) - %lr::", stringstriplist,
77 stringstriplist))
78
79 keeppartialbundle = backup == 'strip'
66 keeppartialbundle = backup == 'strip'
80
67
81 # Some revisions with rev > striprev may not be descendants of striprev.
68 # Some revisions with rev > striprev may not be descendants of striprev.
@@ -182,4 +169,4 b' def strip(ui, repo, nodelist, backup="al'
182 % chgrpfile)
169 % chgrpfile)
183 raise
170 raise
184
171
185 repo.destroyed(newheadrevs)
172 repo.destroyed()
@@ -247,7 +247,6 b' Same thing, different code path:'
247
247
248 $ echo b >> b
248 $ echo b >> b
249 $ hg ci -m 'reopen branch'
249 $ hg ci -m 'reopen branch'
250 created new head
251 reopening closed branch head 4
250 reopening closed branch head 4
252 $ echo b >> b
251 $ echo b >> b
253 $ hg ci --amend --close-branch
252 $ hg ci --amend --close-branch
@@ -36,8 +36,7 b' mq patch on an empty repo'
36 $ hg qrefresh -m 'patch 1'
36 $ hg qrefresh -m 'patch 1'
37 $ show_branch_cache
37 $ show_branch_cache
38 tip: 0
38 tip: 0
39 d986d5caac23a7d44a46efc0ddaf5eb9665844cf 0
39 No branch cache
40 d986d5caac23a7d44a46efc0ddaf5eb9665844cf default
41
40
42 some regular revisions
41 some regular revisions
43
42
@@ -76,8 +75,8 b' add some mq patches'
76 $ hg qrefresh -m 'patch 2'
75 $ hg qrefresh -m 'patch 2'
77 $ show_branch_cache 1
76 $ show_branch_cache 1
78 tip: 3
77 tip: 3
79 982611f6955f9c48d3365decea203217c945ef0d 2
78 c229711f16da3d7591f89b1b8d963b79bda22714 1
80 982611f6955f9c48d3365decea203217c945ef0d bar
79 c229711f16da3d7591f89b1b8d963b79bda22714 bar
81 dc25e3827021582e979f600811852e36cbe57341 foo
80 dc25e3827021582e979f600811852e36cbe57341 foo
82 branch foo: 3
81 branch foo: 3
83 branch bar: 2
82 branch bar: 2
General Comments 0
You need to be logged in to leave comments. Login now