mirror of
https://github.com/facebook/sapling.git
synced 2024-10-09 00:14:35 +03:00
branchmap: extract read logic from repo
This commit is contained in:
parent
ef0f47c598
commit
b588a59cfa
@ -5,9 +5,41 @@
|
||||
# This software may be used and distributed according to the terms of the
|
||||
# GNU General Public License version 2 or any later version.
|
||||
|
||||
from node import hex
|
||||
from node import bin, hex, nullid, nullrev
|
||||
import encoding
|
||||
|
||||
def read(repo):
|
||||
partial = {}
|
||||
try:
|
||||
f = repo.opener("cache/branchheads")
|
||||
lines = f.read().split('\n')
|
||||
f.close()
|
||||
except (IOError, OSError):
|
||||
return {}, nullid, nullrev
|
||||
|
||||
try:
|
||||
last, lrev = lines.pop(0).split(" ", 1)
|
||||
last, lrev = bin(last), int(lrev)
|
||||
if lrev >= len(repo) or repo[lrev].node() != last:
|
||||
# invalidate the cache
|
||||
raise ValueError('invalidating branch cache (tip differs)')
|
||||
for l in lines:
|
||||
if not l:
|
||||
continue
|
||||
node, label = l.split(" ", 1)
|
||||
label = encoding.tolocal(label.strip())
|
||||
if not node in repo:
|
||||
raise ValueError('invalidating branch cache because node '+
|
||||
'%s does not exist' % node)
|
||||
partial.setdefault(label, []).append(bin(node))
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except Exception, inst:
|
||||
if repo.ui.debugflag:
|
||||
repo.ui.warn(str(inst), '\n')
|
||||
partial, last, lrev = {}, nullid, nullrev
|
||||
return partial, last, lrev
|
||||
|
||||
def write(repo, branches, tip, tiprev):
|
||||
try:
|
||||
f = repo.opener("cache/branchheads", "w", atomictemp=True)
|
||||
|
@ -4,7 +4,7 @@
|
||||
#
|
||||
# This software may be used and distributed according to the terms of the
|
||||
# GNU General Public License version 2 or any later version.
|
||||
from node import bin, hex, nullid, nullrev, short
|
||||
from node import hex, nullid, short
|
||||
from i18n import _
|
||||
import peer, changegroup, subrepo, discovery, pushkey, obsolete, repoview
|
||||
import changelog, dirstate, filelog, manifest, context, bookmarks, phases
|
||||
@ -671,7 +671,7 @@ class localrepository(object):
|
||||
|
||||
oldtip = self._branchcachetip
|
||||
if oldtip is None or oldtip not in cl.nodemap:
|
||||
partial, last, lrev = self._readbranchcache()
|
||||
partial, last, lrev = branchmap.read(self)
|
||||
else:
|
||||
lrev = cl.rev(oldtip)
|
||||
partial = self._branchcache
|
||||
@ -730,39 +730,6 @@ class localrepository(object):
|
||||
bt[bn] = self._branchtip(heads)
|
||||
return bt
|
||||
|
||||
@unfilteredmethod # Until we get a smarter cache management
|
||||
def _readbranchcache(self):
|
||||
partial = {}
|
||||
try:
|
||||
f = self.opener("cache/branchheads")
|
||||
lines = f.read().split('\n')
|
||||
f.close()
|
||||
except (IOError, OSError):
|
||||
return {}, nullid, nullrev
|
||||
|
||||
try:
|
||||
last, lrev = lines.pop(0).split(" ", 1)
|
||||
last, lrev = bin(last), int(lrev)
|
||||
if lrev >= len(self) or self[lrev].node() != last:
|
||||
# invalidate the cache
|
||||
raise ValueError('invalidating branch cache (tip differs)')
|
||||
for l in lines:
|
||||
if not l:
|
||||
continue
|
||||
node, label = l.split(" ", 1)
|
||||
label = encoding.tolocal(label.strip())
|
||||
if not node in self:
|
||||
raise ValueError('invalidating branch cache because node '+
|
||||
'%s does not exist' % node)
|
||||
partial.setdefault(label, []).append(bin(node))
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except Exception, inst:
|
||||
if self.ui.debugflag:
|
||||
self.ui.warn(str(inst), '\n')
|
||||
partial, last, lrev = {}, nullid, nullrev
|
||||
return partial, last, lrev
|
||||
|
||||
@unfilteredmethod # Until we get a smarter cache management
|
||||
def _updatebranchcache(self, partial, ctxgen):
|
||||
"""Given a branchhead cache, partial, that may have extra nodes or be
|
||||
|
Loading…
Reference in New Issue
Block a user