##// END OF EJS Templates
branchmap: extract read logic from repo
Pierre-Yves David -
r18118:e70ff1e5 default
parent child Browse files
Show More
@@ -5,9 +5,41 b''
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
7
8 from node import hex
8 from node import bin, hex, nullid, nullrev
9 import encoding
9 import encoding
10
10
11 def read(repo):
12 partial = {}
13 try:
14 f = repo.opener("cache/branchheads")
15 lines = f.read().split('\n')
16 f.close()
17 except (IOError, OSError):
18 return {}, nullid, nullrev
19
20 try:
21 last, lrev = lines.pop(0).split(" ", 1)
22 last, lrev = bin(last), int(lrev)
23 if lrev >= len(repo) or repo[lrev].node() != last:
24 # invalidate the cache
25 raise ValueError('invalidating branch cache (tip differs)')
26 for l in lines:
27 if not l:
28 continue
29 node, label = l.split(" ", 1)
30 label = encoding.tolocal(label.strip())
31 if not node in repo:
32 raise ValueError('invalidating branch cache because node '+
33 '%s does not exist' % node)
34 partial.setdefault(label, []).append(bin(node))
35 except KeyboardInterrupt:
36 raise
37 except Exception, inst:
38 if repo.ui.debugflag:
39 repo.ui.warn(str(inst), '\n')
40 partial, last, lrev = {}, nullid, nullrev
41 return partial, last, lrev
42
11 def write(repo, branches, tip, tiprev):
43 def write(repo, branches, tip, tiprev):
12 try:
44 try:
13 f = repo.opener("cache/branchheads", "w", atomictemp=True)
45 f = repo.opener("cache/branchheads", "w", atomictemp=True)
@@ -4,7 +4,7 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 from node import bin, hex, nullid, nullrev, short
7 from node import hex, nullid, short
8 from i18n import _
8 from i18n import _
9 import peer, changegroup, subrepo, discovery, pushkey, obsolete, repoview
9 import peer, changegroup, subrepo, discovery, pushkey, obsolete, repoview
10 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
10 import changelog, dirstate, filelog, manifest, context, bookmarks, phases
@@ -671,7 +671,7 b' class localrepository(object):'
671
671
672 oldtip = self._branchcachetip
672 oldtip = self._branchcachetip
673 if oldtip is None or oldtip not in cl.nodemap:
673 if oldtip is None or oldtip not in cl.nodemap:
674 partial, last, lrev = self._readbranchcache()
674 partial, last, lrev = branchmap.read(self)
675 else:
675 else:
676 lrev = cl.rev(oldtip)
676 lrev = cl.rev(oldtip)
677 partial = self._branchcache
677 partial = self._branchcache
@@ -731,39 +731,6 b' class localrepository(object):'
731 return bt
731 return bt
732
732
733 @unfilteredmethod # Until we get a smarter cache management
733 @unfilteredmethod # Until we get a smarter cache management
734 def _readbranchcache(self):
735 partial = {}
736 try:
737 f = self.opener("cache/branchheads")
738 lines = f.read().split('\n')
739 f.close()
740 except (IOError, OSError):
741 return {}, nullid, nullrev
742
743 try:
744 last, lrev = lines.pop(0).split(" ", 1)
745 last, lrev = bin(last), int(lrev)
746 if lrev >= len(self) or self[lrev].node() != last:
747 # invalidate the cache
748 raise ValueError('invalidating branch cache (tip differs)')
749 for l in lines:
750 if not l:
751 continue
752 node, label = l.split(" ", 1)
753 label = encoding.tolocal(label.strip())
754 if not node in self:
755 raise ValueError('invalidating branch cache because node '+
756 '%s does not exist' % node)
757 partial.setdefault(label, []).append(bin(node))
758 except KeyboardInterrupt:
759 raise
760 except Exception, inst:
761 if self.ui.debugflag:
762 self.ui.warn(str(inst), '\n')
763 partial, last, lrev = {}, nullid, nullrev
764 return partial, last, lrev
765
766 @unfilteredmethod # Until we get a smarter cache management
767 def _updatebranchcache(self, partial, ctxgen):
734 def _updatebranchcache(self, partial, ctxgen):
768 """Given a branchhead cache, partial, that may have extra nodes or be
735 """Given a branchhead cache, partial, that may have extra nodes or be
769 missing heads, and a generator of nodes that are at least a superset of
736 missing heads, and a generator of nodes that are at least a superset of
General Comments 0
You need to be logged in to leave comments. Login now