# HG changeset patch # User Alexis S. L. Carvalho # Date 2008-02-19 22:20:10 # Node ID 08e0825b8106332b67863234bd10254b21224ea2 # Parent 5b159ebb19cf9e2fddd008012e836e3d720a167f revlog.revision: avoid opening the datafile without need. If there's no inline data, revlog.revision opens the data file every time it's called. This is useful if we're going to call chunk many times, but, if we're going to call it only once, it's better to let chunk open the file - if we're lucky, all the data we're going to need is already cached and we won't need to even look at the file. diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -933,19 +933,19 @@ class revlog(object): raise RevlogError(_('incompatible revision flag %x') % (self.index[rev][0] & 0xFFFF)) - if self._inline: - # we probably have the whole chunk cached - df = None - else: - df = self.opener(self.datafile) + df = None # do we have useful data cached? if self._cache and self._cache[1] >= base and self._cache[1] < rev: base = self._cache[1] text = str(self._cache[2]) self._loadindex(base, rev + 1) + if not self._inline and rev > base + 1: + df = self.opener(self.datafile) else: self._loadindex(base, rev + 1) + if not self._inline and rev > base: + df = self.opener(self.datafile) text = self.chunk(base, df=df) bins = [self.chunk(r, df) for r in xrange(base + 1, rev + 1)]