##// END OF EJS Templates
branchmap: extract write logic from localrepo
Pierre-Yves David -
r18117:526e7ec5 default
parent child Browse files
Show More
@@ -4,3 +4,17 b''
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7
8 from node import hex
9 import encoding
10
11 def write(repo, branches, tip, tiprev):
12 try:
13 f = repo.opener("cache/branchheads", "w", atomictemp=True)
14 f.write("%s %s\n" % (hex(tip), tiprev))
15 for label, nodes in branches.iteritems():
16 for node in nodes:
17 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
18 f.close()
19 except (IOError, OSError):
20 pass
@@ -15,6 +15,7 b' import merge as mergemod'
15 15 import tags as tagsmod
16 16 from lock import release
17 17 import weakref, errno, os, time, inspect
18 import branchmap
18 19 propertycache = util.propertycache
19 20 filecache = scmutil.filecache
20 21
@@ -682,7 +683,7 b' class localrepository(object):'
682 683 if lrev < catip:
683 684 ctxgen = (self[r] for r in cl.revs(lrev + 1, catip))
684 685 self._updatebranchcache(partial, ctxgen)
685 self._writebranchcache(partial, cl.node(catip), catip)
686 branchmap.write(self, partial, cl.node(catip), catip)
686 687 lrev = catip
687 688 # If cacheable tip were lower than actual tip, we need to update the
688 689 # cache up to tip. This update (from cacheable to actual tip) is not
@@ -763,18 +764,6 b' class localrepository(object):'
763 764 return partial, last, lrev
764 765
765 766 @unfilteredmethod # Until we get a smarter cache management
766 def _writebranchcache(self, branches, tip, tiprev):
767 try:
768 f = self.opener("cache/branchheads", "w", atomictemp=True)
769 f.write("%s %s\n" % (hex(tip), tiprev))
770 for label, nodes in branches.iteritems():
771 for node in nodes:
772 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
773 f.close()
774 except (IOError, OSError):
775 pass
776
777 @unfilteredmethod # Until we get a smarter cache management
778 767 def _updatebranchcache(self, partial, ctxgen):
779 768 """Given a branchhead cache, partial, that may have extra nodes or be
780 769 missing heads, and a generator of nodes that are at least a superset of
@@ -1578,8 +1567,8 b' class localrepository(object):'
1578 1567 ctxgen = (self[node] for node in newheadnodes
1579 1568 if self.changelog.hasnode(node))
1580 1569 self._updatebranchcache(self._branchcache, ctxgen)
1581 self._writebranchcache(self._branchcache, self.changelog.tip(),
1582 tiprev)
1570 branchmap.write(self, self._branchcache, self.changelog.tip(),
1571 tiprev)
1583 1572
1584 1573 # Ensure the persistent tag cache is updated. Doing it now
1585 1574 # means that the tag cache only has to worry about destroyed
@@ -2634,7 +2623,7 b' class localrepository(object):'
2634 2623 if rbheads:
2635 2624 rtiprev = max((int(self.changelog.rev(node))
2636 2625 for node in rbheads))
2637 self._writebranchcache(self.branchcache,
2626 branchmap.write(self, self.branchcache,
2638 2627 self[rtiprev].node(), rtiprev)
2639 2628 self.invalidate()
2640 2629 return len(self.heads()) + 1
General Comments 0
You need to be logged in to leave comments. Login now