[PATCH 07 of 10 V2] branchmap: extract read logic from repo
pierre-yves.david at logilab.fr
pierre-yves.david at logilab.fr
Thu Dec 20 14:08:37 UTC 2012
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1355924817 -3600
# Node ID b4b7a64c60f390c15301e0520a8f1b93466f22d8
# Parent 0944e637aec93c80e003d477258f8914c722b9de
branchmap: extract read logic from repo
diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -3,13 +3,45 @@
# Copyright 2005-2007 Matt Mackall <mpm at selenic.com>
#
# 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)
f.write("%s %s\n" % (hex(tip), tiprev))
for label, nodes in branches.iteritems():
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2,11 +2,11 @@
#
# Copyright 2005-2007 Matt Mackall <mpm at selenic.com>
#
# 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
import changelog, dirstate, filelog, manifest, context, bookmarks, phases
import lock, transaction, store, encoding, base85
import scmutil, util, extensions, hook, error, revset
@@ -652,11 +652,11 @@ class localrepository(object):
if self._branchcache is not None and self._branchcachetip == tip:
return
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
catip = self._cacheabletip()
@@ -712,43 +712,10 @@ class localrepository(object):
for bn, heads in self.branchmap().iteritems():
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
missing heads, and a generator of nodes that are at least a superset of
heads missing, this function updates partial to be correct.
"""
More information about the Mercurial-devel
mailing list