##// 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 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
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 import tags as tagsmod
15 import tags as tagsmod
16 from lock import release
16 from lock import release
17 import weakref, errno, os, time, inspect
17 import weakref, errno, os, time, inspect
18 import branchmap
18 propertycache = util.propertycache
19 propertycache = util.propertycache
19 filecache = scmutil.filecache
20 filecache = scmutil.filecache
20
21
@@ -682,7 +683,7 b' class localrepository(object):'
682 if lrev < catip:
683 if lrev < catip:
683 ctxgen = (self[r] for r in cl.revs(lrev + 1, catip))
684 ctxgen = (self[r] for r in cl.revs(lrev + 1, catip))
684 self._updatebranchcache(partial, ctxgen)
685 self._updatebranchcache(partial, ctxgen)
685 self._writebranchcache(partial, cl.node(catip), catip)
686 branchmap.write(self, partial, cl.node(catip), catip)
686 lrev = catip
687 lrev = catip
687 # If cacheable tip were lower than actual tip, we need to update the
688 # If cacheable tip were lower than actual tip, we need to update the
688 # cache up to tip. This update (from cacheable to actual tip) is not
689 # cache up to tip. This update (from cacheable to actual tip) is not
@@ -763,18 +764,6 b' class localrepository(object):'
763 return partial, last, lrev
764 return partial, last, lrev
764
765
765 @unfilteredmethod # Until we get a smarter cache management
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 def _updatebranchcache(self, partial, ctxgen):
767 def _updatebranchcache(self, partial, ctxgen):
779 """Given a branchhead cache, partial, that may have extra nodes or be
768 """Given a branchhead cache, partial, that may have extra nodes or be
780 missing heads, and a generator of nodes that are at least a superset of
769 missing heads, and a generator of nodes that are at least a superset of
@@ -1578,7 +1567,7 b' class localrepository(object):'
1578 ctxgen = (self[node] for node in newheadnodes
1567 ctxgen = (self[node] for node in newheadnodes
1579 if self.changelog.hasnode(node))
1568 if self.changelog.hasnode(node))
1580 self._updatebranchcache(self._branchcache, ctxgen)
1569 self._updatebranchcache(self._branchcache, ctxgen)
1581 self._writebranchcache(self._branchcache, self.changelog.tip(),
1570 branchmap.write(self, self._branchcache, self.changelog.tip(),
1582 tiprev)
1571 tiprev)
1583
1572
1584 # Ensure the persistent tag cache is updated. Doing it now
1573 # Ensure the persistent tag cache is updated. Doing it now
@@ -2634,7 +2623,7 b' class localrepository(object):'
2634 if rbheads:
2623 if rbheads:
2635 rtiprev = max((int(self.changelog.rev(node))
2624 rtiprev = max((int(self.changelog.rev(node))
2636 for node in rbheads))
2625 for node in rbheads))
2637 self._writebranchcache(self.branchcache,
2626 branchmap.write(self, self.branchcache,
2638 self[rtiprev].node(), rtiprev)
2627 self[rtiprev].node(), rtiprev)
2639 self.invalidate()
2628 self.invalidate()
2640 return len(self.heads()) + 1
2629 return len(self.heads()) + 1
General Comments 0
You need to be logged in to leave comments. Login now